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.abs;
26
27 import java.util.Date;
28
29 /***
30 * @author Federico Bergenti - Universita` di Parma
31 */
32 class AbsPrimitiveSlotsHolder extends AbsObjectImpl {
33
34 /***
35 * Construct an Abstract descriptor to hold an object of
36 * the proper type.
37 * @param typeName The name of the type of the object held by
38 * this abstract descriptor.
39 */
40 protected AbsPrimitiveSlotsHolder(String typeName) {
41 super(typeName);
42 }
43
44 /***
45 * Utility method that allows setting attributes of type
46 * <code>String</code> without the need of wrapping the new value
47 * into an <code>AbsPrimitive</code>.
48 * @param name The name of the attribute to be set.
49 * @param value The new value of the attribute.
50 */
51 public void set(String name, String value) {
52 set(name, AbsPrimitive.wrap(value));
53 }
54
55 /***
56 * Utility method that allows setting attributes of type
57 * <code>boolean</code> without the need of wrapping the new value
58 * into an <code>AbsPrimitive</code>.
59 * @param name The name of the attribute to be set.
60 * @param value The new value of the attribute.
61 */
62 public void set(String name, boolean value) {
63 set(name, AbsPrimitive.wrap(value));
64 }
65
66 /***
67 * Utility method that allows setting attributes of type
68 * <code>int</code> without the need of wrapping the new value
69 * into an <code>AbsPrimitive</code>.
70 * @param name The name of the attribute to be set.
71 * @param value The new value of the attribute.
72 */
73 public void set(String name, int value) {
74 set(name, AbsPrimitive.wrap(value));
75 }
76
77 /***
78 * Utility method that allows setting attributes of type
79 * <code>long</code> without the need of wrapping the new value
80 * into an <code>AbsPrimitive</code>.
81 * @param name The name of the attribute to be set.
82 * @param value The new value of the attribute.
83 */
84 public void set(String name, long value) {
85 set(name, AbsPrimitive.wrap(value));
86 }
87
88
89 /***
90 * Utility method that allows setting attributes of type
91 * <code>float</code> without the need of wrapping the new value
92 * into an <code>AbsPrimitive</code>.
93 * @param name The name of the attribute to be set.
94 * @param value The new value of the attribute.
95 */
96 public void set(String name, float value) {
97 set(name, AbsPrimitive.wrap(value));
98 }
99
100 /***
101 * Utility method that allows setting attributes of type
102 * <code>double</code> without the need of wrapping the new value
103 * into an <code>AbsPrimitive</code>.
104 * @param name The name of the attribute to be set.
105 * @param value The new value of the attribute.
106 */
107 public void set(String name, double value) {
108 set(name, AbsPrimitive.wrap(value));
109 }
110
111
112 /***
113 * Utility method that allows setting attributes of type
114 * <code>Date</code> without the need of wrapping the new value
115 * into an <code>AbsPrimitive</code>.
116 * @param name The name of the attribute to be set.
117 * @param value The new value of the attribute.
118 */
119 public void set(String name, Date value) {
120 set(name, AbsPrimitive.wrap(value));
121 }
122
123 /***
124 * Utility method that allows setting attributes of type
125 * <code>byte[]</code> without the need of wrapping the new value
126 * into an <code>AbsPrimitive</code>.
127 * @param name The name of the attribute to be set.
128 * @param value The new value of the attribute.
129 */
130 public void set(String name, byte[] value) {
131 set(name, AbsPrimitive.wrap(value));
132 }
133
134 /***
135 * Utility method that allows getting the value of attributes
136 * of type <code>String</code> directly as a <code>String</code>
137 * i.e. not wrapped into an <code>AbsPrimitive/code>.
138 * @param name The name of the attribute to be retrieved.
139 * @param value The value of the attribute.
140 */
141 public String getString(String name) {
142 AbsPrimitive p = (AbsPrimitive) getAbsObject(name);
143 if (p != null) {
144 return p.getString();
145 }
146 else {
147 return null;
148 }
149 }
150
151 /***
152 * Utility method that allows getting the value of attributes
153 * of type <code>boolean</code> directly as a <code>boolean</code>
154 * i.e. not wrapped into an <code>AbsPrimitive/code>.
155 * @param name The name of the attribute to be retrieved.
156 * @param value The value of the attribute.
157 */
158 public boolean getBoolean(String name) {
159 return ((AbsPrimitive) getAbsObject(name)).getBoolean();
160 }
161
162 /***
163 * Utility method that allows getting the value of attributes
164 * of type <code>int</code> directly as an <code>int</code>
165 * i.e. not wrapped into an <code>AbsPrimitive/code>.
166 * @param name The name of the attribute to be retrieved.
167 * @param value The value of the attribute.
168 */
169 public int getInteger(String name) {
170 return ((AbsPrimitive) getAbsObject(name)).getInteger();
171 }
172
173 /***
174 * Utility method that allows getting the value of attributes
175 * of type <code>long</code> directly as a <code>long</code>
176 * i.e. not wrapped into an <code>AbsPrimitive/code>.
177 * @param name The name of the attribute to be retrieved.
178 * @param value The value of the attribute.
179 */
180 public long getLong(String name) {
181 return ((AbsPrimitive) getAbsObject(name)).getLong();
182 }
183
184
185 /***
186 * Utility method that allows getting the value of attributes
187 * of type <code>float</code> directly as a <code>float</code>
188 * i.e. not wrapped into an <code>AbsPrimitive/code>.
189 * @param name The name of the attribute to be retrieved.
190 * @param value The value of the attribute.
191 */
192 public float getFloat(String name) {
193 return ((AbsPrimitive) getAbsObject(name)).getFloat();
194 }
195
196 /***
197 * Utility method that allows getting the value of attributes
198 * of type <code>double</code> directly as a <code>double</code>
199 * i.e. not wrapped into an <code>AbsPrimitive/code>.
200 * @param name The name of the attribute to be retrieved.
201 * @param value The value of the attribute.
202 */
203 public double getDouble(String name) {
204 return ((AbsPrimitive) getAbsObject(name)).getDouble();
205 }
206
207
208 /***
209 * Utility method that allows getting the value of attributes
210 * of type <code>Date</code> directly as a <code>Date</code>
211 * i.e. not wrapped into an <code>AbsPrimitive/code>.
212 * @param name The name of the attribute to be retrieved.
213 * @param value The value of the attribute.
214 */
215 public Date getDate(String name) {
216 AbsPrimitive p = (AbsPrimitive) getAbsObject(name);
217 if (p != null) {
218 return p.getDate();
219 }
220 else {
221 return null;
222 }
223 }
224
225 /***
226 * Utility method that allows getting the value of attributes
227 * of type <code>byte[]</code> directly as a <code>byte[]</code>
228 * i.e. not wrapped into an <code>AbsPrimitive/code>.
229 * @param name The name of the attribute to be retrieved.
230 * @param value The value of the attribute.
231 */
232 public byte[] getByteSequence(String name) {
233 AbsPrimitive p = (AbsPrimitive) getAbsObject(name);
234 if (p != null) {
235 return p.getByteSequence();
236 }
237 else {
238 return null;
239 }
240 }
241 }
242