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 * @author Federico Bergenti - Universita` di Parma
32 */
33 public class ConceptSchema extends TermSchema {
34 public static final String BASE_NAME = "Concept";
35 private static ConceptSchema baseSchema = new ConceptSchema();
36
37 /***
38 * Construct a schema that vinculates an entity to be a generic
39 * concept
40 */
41 private ConceptSchema() {
42 super(BASE_NAME);
43 }
44
45 /***
46 * Creates a <code>ConceptSchema</code> with a given type-name,
47 * e.g. PERSON, ADDRESS...
48 * @param typeName The name of this <code>ConceptSchema</code>.
49 */
50 public ConceptSchema(String typeName) {
51 super(typeName);
52 }
53
54 /***
55 * Retrieve the generic base schema for all concepts.
56 * @return the generic base schema for all concepts.
57 */
58 public static ObjectSchema getBaseSchema() {
59 return baseSchema;
60 }
61
62 /***
63 * Add a mandatory slot to the schema. The schema for this slot must
64 * be a <code>TermSchema</code>.
65 * @param name The name of the slot.
66 * @param slotSchema The schema of the slot.
67 */
68 public void add(String name, TermSchema slotSchema) {
69 super.add(name, slotSchema);
70 }
71
72 /***
73 * Add a slot to the schema. The schema for this slot must
74 * be a <code>TermSchema</code>.
75 * @param name The name of the slot.
76 * @param slotSchema The schema of the slot.
77 * @param optionality The optionality, i.e., <code>OPTIONAL</code>
78 * or <code>MANDATORY</code>
79 */
80 public void add(String name, TermSchema slotSchema, int optionality) {
81 super.add(name, slotSchema, optionality);
82 }
83
84 /***
85 * Add a slot with cardinality between <code>cardMin</code>
86 * and <code>cardMax</code> to this schema.
87 * Adding such a slot is equivalent to add a slot
88 * of type Aggregate and then to add proper facets (constraints)
89 * to check that the type of the elements in the aggregate are
90 * compatible with <code>elementsSchema</code> and that the
91 * aggregate contains at least <code>cardMin</code> elements and
92 * at most <code>cardMax</code> elements.
93 * @param name The name of the slot.
94 * @param elementsSchema The schema for the elements of this slot.
95 * @param cardMin This slot must get at least <code>cardMin</code>
96 * values
97 * @param cardMax This slot can get at most <code>cardMax</code>
98 * values
99 */
100 public void add(String name, TermSchema elementsSchema, int cardMin, int cardMax) {
101 super.add(name, elementsSchema, cardMin, cardMax);
102 }
103
104 /***
105 * Adds a super-schema to this schema. This allows defining
106 * inheritance relationships between ontological concepts.
107 * It must be noted that a concept always inherits from another
108 * concept --> A super-schema of a <code>ConceptSchema</code>
109 * must be a <code>ConceptSchema</code> too.
110 *
111 * @param superClassSchema The super-schema to be added.
112 */
113 public void addSuperSchema(ConceptSchema superClassSchema) {
114 super.addSuperSchema(superClassSchema);
115 }
116
117 /***
118 Add a <code>Facet</code> on a slot of this schema
119 @param slotName the name of the slot the <code>Facet</code>
120 must be added to.
121 @param f the <code>Facet</code> to be added.
122 @throws OntologyException if slotName does not identify
123 a valid slot in this schema
124 */
125 public void addFacet(String slotName, Facet f) throws OntologyException {
126 super.addFacet(slotName, f);
127 }
128
129 /***
130 * Creates an Abstract descriptor to hold a concept of
131 * the proper type.
132 */
133 public AbsObject newInstance() throws OntologyException {
134 return new AbsConcept(getTypeName());
135 }
136
137 /***
138 Check whether a given abstract descriptor complies with this
139 schema.
140 @param abs The abstract descriptor to be checked
141 @throws OntologyException If the abstract descriptor does not
142 complies with this schema
143 */
144 public void validate(AbsObject abs, Ontology onto) throws OntologyException {
145
146 if (!(abs instanceof AbsConcept)) {
147 throw new OntologyException(abs+" is not an AbsConcept");
148 }
149
150
151 validateSlots(abs, onto);
152 }
153
154 /***
155 Return true if
156 - s is the base schema for the XXXSchema class this schema is
157 an instance of (e.g. s is ConceptSchema.getBaseSchema() and this
158 schema is an instance of ConceptSchema)
159 - s is the base schema for a super-class of the XXXSchema class
160 this schema is an instance of (e.g. s is TermSchema.getBaseSchema()
161 and this schema is an instance of ConceptSchema)
162 */
163 protected boolean descendsFrom(ObjectSchema s) {
164 if (s != null) {
165 if (s.equals(getBaseSchema())) {
166 return true;
167 }
168 return super.descendsFrom(s);
169 }
170 else {
171 return false;
172 }
173 }
174 }