1 /*********************************************************************
2 Copyright 2012, Ralph Ronnquist.
4 This file is part of GORITE.
6 GORITE is free software: you can redistribute it and/or modify it
7 under the terms of the Lesser GNU General Public License as published
8 by the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GORITE is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the Lesser GNU General Public
17 License along with GORITE. If not, see <http://www.gnu.org/licenses/>.
18 **********************************************************************/
20 package com.intendico.gorite;
22 import com.intendico.data.Query;
23 import com.intendico.data.Ref;
24 import com.intendico.data.Condition;
27 * The Context interface is implemented by a plan (i.e. top level
28 * goal) that has different variants for different contexts. The
29 * different contexts are defined by means of a {@link Query} that
30 * provides multiple bindings, and each binding defines a variant
31 * execution of the plan.
36 public interface Context {
39 * A constant that a {@link #context} method may return when a
40 * plan doesn't have any applicable variants. Returning this
41 * {@link Query}, which is eternally false, has the same effect as
42 * throwing a {@link None} exception in marking that the plan does
43 * not have any applicable variants. The point is that a null
44 * return from the {@link #context} method means that there is no
45 * context query, and that the goal with this context is
48 public static final Query EMPTY = new Condition() {
49 public boolean condition() {
55 * A constant that a {@link #context} method may return when a
56 * plan has a single applicable variant without bindings to {@link
57 * Ref} objects. Returning this {@link Query}, which in fact is
58 * null, has the same effect as returning null in marking that the
59 * plan has a single applicable variant. The point is that a null
60 * return from the {@link #context} method means that there is no
61 * context query, and therefore the plan with this context is
64 public static final Query TRUE = null;
67 * A constant that a {@link #context} method may return when a
68 * plan doesn't have any applicable variants. This is merely an
69 * alias for {@link #EMPTY} added for convenience.
71 public static final Query FALSE = EMPTY;
74 * An exception that a {@link #context} method may throw in
75 * order to mark that there is no applicable context.
78 public static class None extends Exception {
81 * A default constructor.
84 super( "no applicable context" );
88 * Version identity required for serialization.
90 public static final long serialVersionUID = 1L;
94 * The context method returns the {@link Query} that defines the
95 * multiple alternative contexts for the execution. The {@link
96 * #context} method is invoked for defining the {@link Query}. The
97 * method may return null, which means that the plan has a single
98 * applicable variant, or it may return {@link #EMPTY} or throw
99 * the {@link None} excpetion, which both indicate that the plan
100 * does not have any applicable variant (right now). Any other
101 * query is taken as defining the alternative applicable contexts.
102 * @see BDIGoal.BDIInstance#contextual
104 public Query context(Data d) throws Exception;