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.onto.*;
28 import JADE_SL.abs.*;
29
30 /***
31 * @author Federico Bergenti - Universita` di Parma
32 */
33 public class VariableSchema extends TermSchema {
34 public static final String BASE_NAME = "Variable";
35 private static VariableSchema baseSchema = new VariableSchema();
36
37 public static final String NAME = "Name";
38 public static final String VALUE_TYPE = "ValueType";
39
40 /***
41 * Construct a schema that vinculates an entity to be a generic
42 * variable.
43 * Note that there are no different types of variable as it
44 * happens for concepts (e.g. Person, Address...), IREs (e.g. IOTA,
45 * ANY, ALL...) and the like. Therefore there is no VariableSchema
46 * constructor that takes a String parameter.
47 * Not also that the type of the values that can be assumed by
48 * the variable is another story and is defined by the
49 * VARIABLE_VALUE_TYPE slot of the VariableSchema
50 */
51 private VariableSchema() {
52 super(BASE_NAME);
53
54 try {
55 add(NAME, BasicOntology.getInstance().getSchema(BasicOntology.STRING));
56 add(VALUE_TYPE, BasicOntology.getInstance().getSchema(BasicOntology.STRING), ObjectSchema.OPTIONAL);
57 }
58 catch (OntologyException oe) {
59 oe.printStackTrace();
60 }
61 }
62
63 /***
64 * Retrieve the generic base schema for all variables.
65 *
66 * @return the generic base schema for all variables.
67 */
68 public static ObjectSchema getBaseSchema() {
69 return baseSchema;
70 }
71
72 /***
73 * Creates an Abstract descriptor to hold a variable
74 */
75 public AbsObject newInstance() throws OntologyException {
76 return new AbsVariable();
77 }
78
79 /***
80 Check whether a given abstract descriptor complies with this
81 schema.
82 @param abs The abstract descriptor to be checked
83 @throws OntologyException If the abstract descriptor does not
84 complies with this schema
85 */
86 public void validate(AbsObject abs, Ontology onto) throws OntologyException {
87
88 if (!(abs instanceof AbsVariable)) {
89 throw new OntologyException(abs+" is not an AbsVariable");
90 }
91
92
93 validateSlots(abs, onto);
94 }
95
96 /***
97 A variable can be put whereever a term of whatever type is
98 required --> A VariableSchema is
99 compatible with s if s descends from TermSchema.getBaseSchema()
100 */
101 public boolean isCompatibleWith(ObjectSchema s) {
102 if (s != null) {
103 return s.descendsFrom(TermSchema.getBaseSchema());
104 }
105 else {
106 return false;
107 }
108 }
109
110 /***
111 Return true if
112 - s is the base schema for the XXXSchema class this schema is
113 an instance of (e.g. s is ConceptSchema.getBaseSchema() and this
114 schema is an instance of ConceptSchema)
115 - s is the base schema for a super-class of the XXXSchema class
116 this schema is an instance of (e.g. s is TermSchema.getBaseSchema()
117 and this schema is an instance of ConceptSchema)
118 */
119 protected boolean descendsFrom(ObjectSchema s) {
120 if (s != null) {
121 if (s.equals(getBaseSchema())) {
122 return true;
123 }
124 return super.descendsFrom(s);
125 }
126 else {
127 return false;
128 }
129 }
130 }
131