View Javadoc

1   /***
2    * ***************************************************************
3    * JADE - Java Agent DEvelopment Framework is a framework to develop
4    * multi-agent systems in compliance with the FIPA specifications.
5    * Copyright (C) 2000 CSELT S.p.A.
6    * 
7    * GNU Lesser General Public License
8    * 
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation,
12   * version 2.1 of the License.
13   * 
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   * 
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the
21   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22   * Boston, MA  02111-1307, USA.
23   * **************************************************************
24   */
25  package JADE_SL.schema;
26  
27  import JADE_SL.abs.*;
28  import JADE_SL.onto.*;
29  
30  /***
31   * Note that an AgentActionSchema should also be a ConceptSchema, but
32   * this inheritance relation is cut as Java does not support
33   * multiple inheritance. As a consequence in practice it will 
34   * not be possible to define e.g. a ConceptSchema with a slot 
35   * whose value must be instances of a certain type of agent-action 
36   * even if in theory this should be
37   * possible as a ConceptSchema can have slots of type term and 
38   * an agent-action is a concept and therefore a term.
39   * @author Federico Bergenti - Universita` di Parma
40   */
41  public class AgentActionSchema extends ConceptSchema {
42      public static final String         BASE_NAME = "AgentAction";
43      private static AgentActionSchema baseSchema = new AgentActionSchema();
44  
45      /***
46       * Construct a schema that vinculates an entity to be a generic
47       * agent action
48       */
49      private AgentActionSchema() {
50          super(BASE_NAME);
51      }
52  
53      /***
54       * Creates an <code>AgentActionSchema</code> with a given type-name.
55       * @param typeName The name of this <code>AgentActionSchema</code>.
56       */
57      public AgentActionSchema(String typeName) {
58          super(typeName);
59      }
60  
61      /***
62       * Retrieve the generic base schema for all agent actions.
63       * @return the generic base schema for all agent actions.
64       */
65      public static ObjectSchema getBaseSchema() {
66          return baseSchema;
67      } 
68  
69      /***
70       * Add a mandatory slot of type PredicateSchema to this schema. 
71       * @param name The name of the slot.
72       * @param slotSchema The schema of the slot.
73       */
74      public void add(String name, PredicateSchema slotSchema) {
75          super.add(name, slotSchema);
76      } 
77  
78      /***
79       * Add a slot of type PredicateSchema to this schema. 
80       * @param name The name of the slot.
81       * @param slotSchema The schema of the slot.
82       * @param optionality The optionality, i.e. <code>OPTIONAL</code> 
83       * or <code>MANDATORY</code>
84       */
85      public void add(String name, PredicateSchema slotSchema, int optionality) {
86          super.add(name, slotSchema, optionality);
87      } 
88  
89      /***
90       * Creates an Abstract descriptor to hold an agent action of
91       * the proper type.
92       */
93      public AbsObject newInstance() throws OntologyException {
94          return new AbsAgentAction(getTypeName());
95      } 
96  
97  		/***
98  	     Check whether a given abstract descriptor complies with this 
99  	     schema.
100 	     @param abs The abstract descriptor to be checked
101 	     @throws OntologyException If the abstract descriptor does not 
102 	     complies with this schema
103 	   */
104   	public void validate(AbsObject abs, Ontology onto) throws OntologyException {
105 			// Check the type of the abstract descriptor
106   		if (!(abs instanceof AbsAgentAction)) {
107 				throw new OntologyException(abs+" is not an AbsAgentAction");
108 			}
109 			
110 			// Check the slots
111 			validateSlots(abs, onto);
112   	}
113   	
114   	/***
115   	   Return true if 
116   	   - s is the base schema for the XXXSchema class this schema is
117   	     an instance of (e.g. s is ConceptSchema.getBaseSchema() and this 
118   	     schema is an instance of ConceptSchema)
119   	   - s is the base schema for a super-class of the XXXSchema class
120   	     this schema is an instance of (e.g. s is TermSchema.getBaseSchema()
121   	     and this schema is an instance of ConceptSchema.
122   	   Moreover, as AgentActionSchema extends GenericActionSchema, but should
123   	   also extend ConceptSchema (this is not possible in practice as
124   	   Java does not support multiple inheritance), this method
125   	   returns true also in the case that s is equals to, or is an
126   	   ancestor of, ConceptSchema.getBaseSchema() (i.e. TermSchema.getBaseSchema()
127   	   descends from s)
128   	 */
129   	protected boolean descendsFrom(ObjectSchema s) {
130 			if (s != null) {
131 	  	 	if (s.equals(getBaseSchema())) {
132 		  		return true;
133   			}
134   			if (super.descendsFrom(s)) {
135   				return true;
136   			}
137   			return ContentElementSchema.getBaseSchema().descendsFrom(s);
138 			}
139 			else {
140 				return false;
141 			}
142   	}
143 }