View Javadoc

1   /******************************************************************
2   JADE - Java Agent DEvelopment Framework is a framework to develop 
3   multi-agent systems in compliance with the FIPA specifications.
4   Copyright (C) 2000 CSELT S.p.A. 
5   
6   GNU Lesser General Public License
7   
8   This library is free software; you can redistribute it and/or
9   modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation, 
11  version 2.1 of the License. 
12  
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  Lesser General Public License for more details.
17  
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the
20  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  *****************************************************************/
23  
24  
25  package sl;
26  import java.util.*;
27  
28  
29  /***
30    Descriptor class for the slots of ontological roles. Instances of this
31    class are used to describe the characteristics of the slots of a 
32    role in an ontology.
33   
34    @author Giovanni Rimassa - Universita` di Parma
35    @version $Date: 2003/10/09 13:00:37 $ $Revision: 1.1.1.1 $
36  */
37  public class SlotDescriptor {
38  
39    private CaseInsensitiveString name;
40    private int category; // indicates if the value of the slot is a primitive entity, and instance of a given role, a set or a sequence
41    private String type; // indicates the type of the elements of a set/sequence
42    private boolean optionality;
43  
44    /***
45      Build the descriptor for a named slot.  
46      @param n The name of the described slot.
47      @param c A symbolic constant identifying the category of the slot (i.e. 
48      one value between <code>
49      Ontology.FRAME_SLOT , Ontology.SET_SLOT, Ontology.SEQUENCE_SLOT,
50      Ontology.PRIMITIVE_SLOT, Ontology.ANY_SLOT</code>. )
51      @param t The name of the type of the values allowed for this slot, (i.e.
52      one value between <code> Ontology.STRING_TYPE, Ontology.XXX_TYPE </code>,
53      or, in case of a FRAME_SLOT, the name of the role in the ontology the value 
54      of this slot is an instance of
55      @param o One of <code>Ontology.M</code> (for mandatory slots) and
56      <code>Ontology.O</code> (for optional slots).
57    */
58    public SlotDescriptor(String n, int c, String t, boolean o) {
59      name = new CaseInsensitiveString(n);
60      category = c;
61      type = t;
62      optionality = o;
63    }
64  
65  
66  
67    /***
68      Build the descriptor for an unnamed slot. 
69      @see jade.onto#SlotDescriptor(String n, int t, String vt, boolean o)
70    */
71    public SlotDescriptor(int c, String t, boolean o) {
72      this("",c,t,o);
73    }
74  
75  
76  
77    /***
78      Get the name of a slot.
79      @return The name of the slot described by this object, as set by the
80      constructor, or <code>""</code> if the slot is unnamed.
81    */
82    public String getName() {
83      return name.toString();
84    }
85  
86    /***
87      Get the category of a slot.
88      @return A symbolic constant, representing the category of the slot described by
89      this object, as set by the constructor.
90    */
91    public int getCategory() {
92      return category;
93    }
94  
95    /***
96      Get the name of the type of the values of this slot.
97      @return The name of the type of the values for this slot described by this object, as set
98      by the constructor. For primitive types, the name of the type is returned
99      (e.g. <code>java.lang.Integer</code> or <code>java.lang.String</code>); for complex types, the name
100     of the specific concept is returned.
101   */
102   public String getType() {
103     return type;
104   }
105 
106   /***
107   	@return true if the values of this slot assumes primitive types (e.g. Integer, String, ...)
108   */
109 	public boolean hasPrimitiveType() {
110   	return primitiveTypes.contains(type);
111 	}
112 
113   /*** static List of primitive types */
114   static final List primitiveTypes = new ArrayList(12);
115   static { 
116     primitiveTypes.add(Ontology.BOOLEAN_TYPE);
117     primitiveTypes.add(Ontology.BYTE_TYPE);
118     primitiveTypes.add(Ontology.CHARACTER_TYPE);
119     primitiveTypes.add(Ontology.DOUBLE_TYPE);
120     primitiveTypes.add(Ontology.FLOAT_TYPE);
121     primitiveTypes.add(Ontology.INTEGER_TYPE);
122     primitiveTypes.add(Ontology.LONG_TYPE);
123     primitiveTypes.add(Ontology.SHORT_TYPE);
124     primitiveTypes.add(Ontology.STRING_TYPE);
125     primitiveTypes.add(Ontology.BINARY_TYPE);
126     primitiveTypes.add(Ontology.DATE_TYPE);
127     primitiveTypes.add(Ontology.ANY_TYPE);
128   }
129 
130 
131   /***
132     Tells whether a slot is optional.
133     @return <code>true</code> if the slot described by this object is optional
134     in its ontological role, <code>false</code> otherwise.
135   */
136   public boolean isOptional() {
137     return optionality;
138   }
139 
140   /***
141     Tells whether a slot is complex.
142     @return <code>true</code> if the category of the slot described by this 
143     object is <code>Ontology.FRAME_SLOT</code>
144     <code>false</code> otherwise.
145   */
146   public boolean isComplex() {
147     return (category == Ontology.FRAME_SLOT); 
148   }
149 
150   /***
151     Tells whether a slot is set or a sequence.
152     @return <code>true</code> if the category of the slot described by this 
153     object is <code>Ontology.SET_SLOT</code> or <code>Ontology.SEQUENCE_SLOT</code>)
154     <code>false</code> otherwise.
155   */
156   public boolean isSet() {
157     return (category == Ontology.SET_SLOT) || (category == Ontology.SEQUENCE_SLOT);
158   }
159 
160   /***
161   	Tells whethet the slot is primitive.
162     @return <code>true</code> if the category of the slot described by this 
163     object is <code>Ontology.PRIMITIVE_SLOT</code>
164     <code>false</code> otherwise.
165   */
166 	public boolean isPrimitive() {
167   	return (category == Ontology.PRIMITIVE_SLOT);
168 	}
169 
170   void setName(String n) {
171     name = new CaseInsensitiveString(n);
172   }
173 
174   /***
175   	return a String representation of the object, just for debugging purposes
176   */
177 	public String toString() {
178 		return name.toString()+" of category "+category+" and type "+type+" and optionality "+optionality;
179 	}
180 }