Source code: org/biomage/Common/Extendable.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:48 AM *
43 * *
44 ***************************************************************************
45 */
46
47 /**
48 * org.biomage.Common
49 *
50 */
51 package org.biomage.Common;
52
53 /**
54 * Import list for Extendable
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.HasPropertySets;
63
64 /**
65 * Abstract class that specifies for subclasses an association to
66 * NameValueTypes. These can be used, for instance, to specify proprietary
67 * properties and in-house processing hints.
68 *
69 */
70 public
71 abstract
72 class Extendable
73 implements Serializable,
74 HasPropertySets
75 {
76 /**
77 * Allows specification of name/value pairs. Meant to primarily
78 * help in-house, pipeline processing of instances by providing a place
79 * for values that aren't part of the specification proper.
80 *
81 */
82 private PropertySets_list propertySets = new PropertySets_list();
83
84 /**
85 * Default constructor.
86 *
87 */
88 public
89 Extendable()
90 {
91 }
92
93 /**
94 * Attribute constructor.
95 *
96 * Looks up the attributes in the parameter and casts them from strings
97 * appropriately
98 * @param atts: the attribute list.
99 *
100 */
101 // TODO Work in progress (attribute constructor).
102 public
103 Extendable(Attributes atts)
104 {
105 }
106
107 /**
108 * writeMAGEML
109 * <p>
110 * This method is responsible for assembling the attribute and
111 * association data into XML. It creates the object tag and then calls
112 * the writeAttributes and writeAssociation methods.
113 * <p>
114 *
115 */
116 public
117 void
118 writeMAGEML(Writer out)
119 throws IOException
120 {
121 }
122
123 /**
124 * writeAttributes
125 * <p>
126 * This method is responsible for assembling the attribute data into
127 * XML. It calls the super method to write out all attributes of this
128 * class and it's ancestors.
129 * <p>
130 *
131 */
132 public
133 void
134 writeAttributes(Writer out)
135 throws IOException
136 {
137 }
138
139 /**
140 * writeAssociations
141 * <p>
142 * This method is responsible for assembling the association data
143 * into XML. It calls the super method to write out all associations of
144 * this class's ancestors.
145 * <p>
146 *
147 */
148 public
149 void
150 writeAssociations(Writer out)
151 throws IOException
152 {
153 if ( propertySets.size() > 0 ){
154 out.write("<PropertySets_assnlist>");
155 for ( int i = 0; i < propertySets.size(); i++) {
156 ((NameValueType)propertySets.elementAt(i)).writeMAGEML(out);
157 }
158 out.write("</PropertySets_assnlist>");
159 }
160 }
161
162 /**
163 * Set method for propertySets
164 * <p>
165 * @param value to set
166 * <p>
167 *
168 */
169 public
170 void
171 setPropertySets(
172 PropertySets_list propertySets
173 )
174 {
175 ((List)this.propertySets).addAll((List)propertySets);
176 }
177
178 /**
179 * Get method for propertySets
180 * <p>
181 * @return value of the attribute
182 * <p>
183 *
184 */
185 public
186 PropertySets_list
187 getPropertySets()
188 {
189 return propertySets;
190 }
191
192 /**
193 * Method to add NameValueType to PropertySets_list
194 *
195 */
196 public
197 void
198 addToPropertySets(
199 NameValueType nameValueType
200 )
201 {
202 this.propertySets.add(nameValueType);
203 }
204
205 /**
206 * Method to add NameValueType at position to PropertySets_list
207 *
208 */
209 public
210 void
211 addToPropertySets(
212 int position,
213 NameValueType nameValueType
214 )
215 {
216 this.propertySets.add(position, nameValueType);
217 }
218
219 /**
220 * Method to get NameValueType from PropertySets_list
221 *
222 */
223 public
224 NameValueType
225 getFromPropertySets(
226 int position
227 )
228 {
229 return (NameValueType) this.propertySets.get(position);
230 }
231
232 /**
233 * Method to remove by position from PropertySets_list
234 *
235 */
236 public
237 void
238 removeElementAtFromPropertySets(
239 int position
240 )
241 {
242 this.propertySets.removeElementAt(position);
243 }
244
245 /**
246 * Method to remove first NameValueType from PropertySets_list
247 *
248 */
249 public
250 void
251 removeFromPropertySets(
252 NameValueType nameValueType
253 )
254 {
255 this.propertySets.remove(nameValueType);
256 }
257
258 }