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 * Note that an IRESchema should also be a TermSchema, 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 IRE even if in theory
36 * this should be possible as a ConceptSchema can have slots
37 * of type term and an IRE is a term.
38 * @author Federico Bergenti - Universita` di Parma
39 */
40 public class IRESchema extends TermSchema {
41 public static final String BASE_NAME = "IRE";
42 private static IRESchema baseSchema = new IRESchema();
43
44 public static final String VARIABLE = "Variable";
45 public static final String PROPOSITION = "Proposition";
46
47 /***
48 * Construct a schema that vinculates an entity to be a generic
49 * ire
50 */
51 private IRESchema() {
52 super(BASE_NAME);
53 }
54
55 /***
56 * Creates a <code>IRESchema</code> with a given type-name.
57 * All ire-s have a variable and a proposition.
58 * @param typeName The name of this <code>IRESchema</code>
59 * (e.g. IOTA, ANY, ALL).
60 */
61 public IRESchema(String typeName) {
62 super(typeName);
63
64
65 add(VARIABLE, VariableSchema.getBaseSchema());
66 add(PROPOSITION, PredicateSchema.getBaseSchema());
67 }
68
69 /***
70 * Retrieve the generic base schema for all ire-s.
71 * @return the generic base schema for all ire-s.
72 */
73 public static ObjectSchema getBaseSchema() {
74 return baseSchema;
75 }
76
77 /***
78 * Creates an Abstract descriptor to hold a ire of
79 * the proper type.
80 */
81 public AbsObject newInstance() throws OntologyException {
82 return new AbsIRE(getTypeName());
83 }
84
85 /***
86 Check whether a given abstract descriptor complies with this
87 schema.
88 @param abs The abstract descriptor to be checked
89 @throws OntologyException If the abstract descriptor does not
90 complies with this schema
91 */
92 public void validate(AbsObject abs, Ontology onto) throws OntologyException {
93
94 if (!(abs instanceof AbsIRE)) {
95 throw new OntologyException(abs+" is not an AbsIRE");
96 }
97
98
99 validateSlots(abs, onto);
100 }
101
102 /***
103 An IRE can be put whereever a term of whatever type is
104 required --> An IRESchema is
105 compatible with s if s descends from TermSchema.getBaseSchema()
106 */
107 public boolean isCompatibleWith(ObjectSchema s) {
108 if (s != null) {
109 return s.descendsFrom(TermSchema.getBaseSchema());
110 }
111 else {
112 return false;
113 }
114 }
115
116 /***
117 Return true if
118 - s is the base schema for the XXXSchema class this schema is
119 an instance of (e.g. s is ConceptSchema.getBaseSchema() and this
120 schema is an instance of ConceptSchema)
121 - s is the base schema for a super-class of the XXXSchema class
122 this schema is an instance of (e.g. s is TermSchema.getBaseSchema()
123 and this schema is an instance of ConceptSchema.
124 Moreover, as IRESchema extends ContentElementSchema, but should
125 also extend TermSchema (this is not possible in practice as
126 Java does not support multiple inheritance), this method
127 returns true also in the case that s is equals to, or is an
128 ancestor of, TermSchema.getBaseSchema() (i.e. TermSchema.getBaseSchema()
129 descends from s)
130 */
131 protected boolean descendsFrom(ObjectSchema s) {
132 if (s != null) {
133 if (s.equals(getBaseSchema())) {
134 return true;
135 }
136 if (super.descendsFrom(s)) {
137 return true;
138 }
139
140 return ContentElementSchema.getBaseSchema().descendsFrom(s);
141 }
142 else {
143 return false;
144 }
145 }
146 }