Source code: org/biomage/Protocol/Parameterizable.java
1 /***************************************************************************
2 * *
3 * C O P Y R I G H T N O T I C E *
4 * Copyright (c) 2001 by: *
5 * * The MicroArray Gene Expression Database group (MGED) *
6 * * Rosetta Inpharmatics *
7 * *
8 * All Rights Reserved. *
9 * *
10 * Permission is hereby granted, free of charge, to any person *
11 * obtaining a copy of this software and associated documentation files *
12 * (the "Software"), to deal in the Software without restriction, *
13 * including without limitation the rights to use, copy, modify, merge, *
14 * publish, distribute, sublicense, and/or sell copies of the Software, *
15 * and to permit persons to whom the Software is furnished to do so, *
16 * subject to the following conditions: *
17 * *
18 * The above copyright notice and this permission notice shall be *
19 * included in all copies or substantial portions of the Software. *
20 * *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS *
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN *
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN *
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
28 * SOFTWARE. *
29 ***************************************************************************
30 * *
31 * Created by the create_mage_java_classes java program based on the *
32 * information in the xmi file created from the MAGE-OM UML model, *
33 * copyright European Bioinformatics Institute (EBI) for MGED and Rosetta *
34 * Informatics. *
35 * *
36 * The ideas and work are built on the previous work in perl of Jason *
37 * Stewart, Open Informatics, and Robert M. Hubley, Institute for Systems *
38 * Biology *
39 * *
40 * @author Michael Miller, Rosetta Inpharmatics *
41 * @version Revision: 1.0 *
42 * @date Thu, Feb 21, 2002 10:46:27 AM *
43 * *
44 ***************************************************************************
45 */
46
47 /**
48 * org.biomage.Protocol
49 *
50 */
51 package org.biomage.Protocol;
52
53 /**
54 * Import list for Parameterizable
55 *
56 */
57 import java.io.Serializable;
58 import java.util.*;
59 import org.xml.sax.Attributes;
60 import java.io.Writer;
61 import java.io.IOException;
62 import org.biomage.Interface.HasParameterTypes;
63 import org.biomage.Common.Identifiable;
64
65 /**
66 * The Parameterizable interface encapsulates the association of
67 * Parameters with ParameterValues.
68 *
69 */
70 public
71 abstract
72 class Parameterizable
73 extends Identifiable
74 implements Serializable,
75 HasParameterTypes
76 {
77 /**
78 * Where an instantiated Parameterizable is located.
79 *
80 */
81 String URI;
82
83 /**
84 * The description of the parameters for the Parameterizable class
85 * instance.
86 *
87 */
88 private ParameterTypes_list parameterTypes = new ParameterTypes_list();
89
90 /**
91 * Default constructor.
92 *
93 */
94 public
95 Parameterizable()
96 {
97 super();
98 }
99
100 /**
101 * Attribute constructor.
102 *
103 * Looks up the attributes in the parameter and casts them from strings
104 * appropriately
105 * @param atts: the attribute list.
106 *
107 */
108 // TODO Work in progress (attribute constructor).
109 public
110 Parameterizable(Attributes atts)
111 {
112 super(atts);
113
114 {
115 int nIndex = atts.getIndex("", "URI");
116 if (nIndex != -1)
117 {
118 URI = atts.getValue(nIndex);
119 }
120 }
121
122 }
123
124 /**
125 * writeMAGEML
126 * <p>
127 * This method is responsible for assembling the attribute and
128 * association data into XML. It creates the object tag and then calls
129 * the writeAttributes and writeAssociation methods.
130 * <p>
131 *
132 */
133 public
134 void
135 writeMAGEML(Writer out)
136 throws IOException
137 {
138 }
139
140 /**
141 * writeAttributes
142 * <p>
143 * This method is responsible for assembling the attribute data into
144 * XML. It calls the super method to write out all attributes of this
145 * class and it's ancestors.
146 * <p>
147 *
148 */
149 public
150 void
151 writeAttributes(Writer out)
152 throws IOException
153 {
154 super.writeAttributes(out);
155 if ( URI != null ) {
156 out.write(" URI=\"" + URI + "\"");
157 }
158 }
159
160 /**
161 * writeAssociations
162 * <p>
163 * This method is responsible for assembling the association data
164 * into XML. It calls the super method to write out all associations of
165 * this class's ancestors.
166 * <p>
167 *
168 */
169 public
170 void
171 writeAssociations(Writer out)
172 throws IOException
173 {
174 super.writeAssociations(out);
175 if ( parameterTypes.size() > 0 ){
176 out.write("<ParameterTypes_assnlist>");
177 for ( int i = 0; i < parameterTypes.size(); i++) {
178 ((Parameter)parameterTypes.elementAt(i)).writeMAGEML(out);
179 }
180 out.write("</ParameterTypes_assnlist>");
181 }
182 }
183
184 /**
185 * Set method for URI
186 * <p>
187 * @param value to set
188 * <p>
189 *
190 */
191 public
192 void
193 setURI(
194 String URI
195 )
196 {
197 this.URI = URI;
198 }
199
200 /**
201 * Get method for URI
202 * <p>
203 * @return value of the attribute
204 * <p>
205 *
206 */
207 public
208 String
209 getURI()
210 {
211 return URI;
212 }
213
214 /**
215 * Set method for parameterTypes
216 * <p>
217 * @param value to set
218 * <p>
219 *
220 */
221 public
222 void
223 setParameterTypes(
224 ParameterTypes_list parameterTypes
225 )
226 {
227 ((List)this.parameterTypes).addAll((List)parameterTypes);
228 }
229
230 /**
231 * Get method for parameterTypes
232 * <p>
233 * @return value of the attribute
234 * <p>
235 *
236 */
237 public
238 ParameterTypes_list
239 getParameterTypes()
240 {
241 return parameterTypes;
242 }
243
244 /**
245 * Method to add Parameter to ParameterTypes_list
246 *
247 */
248 public
249 void
250 addToParameterTypes(
251 Parameter parameter
252 )
253 {
254 this.parameterTypes.add(parameter);
255 }
256
257 /**
258 * Method to add Parameter at position to ParameterTypes_list
259 *
260 */
261 public
262 void
263 addToParameterTypes(
264 int position,
265 Parameter parameter
266 )
267 {
268 this.parameterTypes.add(position, parameter);
269 }
270
271 /**
272 * Method to get Parameter from ParameterTypes_list
273 *
274 */
275 public
276 Parameter
277 getFromParameterTypes(
278 int position
279 )
280 {
281 return (Parameter) this.parameterTypes.get(position);
282 }
283
284 /**
285 * Method to remove by position from ParameterTypes_list
286 *
287 */
288 public
289 void
290 removeElementAtFromParameterTypes(
291 int position
292 )
293 {
294 this.parameterTypes.removeElementAt(position);
295 }
296
297 /**
298 * Method to remove first Parameter from ParameterTypes_list
299 *
300 */
301 public
302 void
303 removeFromParameterTypes(
304 Parameter parameter
305 )
306 {
307 this.parameterTypes.remove(parameter);
308 }
309
310 }