Source code: org/biomage/BioMaterial/Compound.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:08 AM *
43 * *
44 ***************************************************************************
45 */
46
47 /**
48 * org.biomage.BioMaterial
49 *
50 */
51 package org.biomage.BioMaterial;
52
53 /**
54 * Import list for Compound
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.HasComponentCompounds;
63 import org.biomage.Interface.HasMerckIndex;
64 import org.biomage.Common.Identifiable;
65 import org.biomage.Description.OntologyEntry;
66
67 /**
68 * A Compound can be a simple compound such as SDS (sodium dodecyl
69 * sulfate). It may also be made of other Compounds in proportions using
70 * CompoundMeasurements to enumerate the Compounds and their amounts such
71 * as LB (Luria Broth) Media.
72 *
73 */
74 public
75 class Compound
76 extends Identifiable
77 implements Serializable,
78 HasComponentCompounds,
79 HasMerckIndex
80 {
81 /**
82 * A Compound may be a special case Solvent.
83 *
84 */
85 boolean isSolvent;
86
87 /**
88 * The Compounds and their amounts used to create this Compound.
89 *
90 */
91 private ComponentCompounds_list componentCompounds = new ComponentCompounds_list();
92
93 /**
94 * The Merck Index of this Compound.
95 *
96 */
97 private OntologyEntry merckIndex;
98
99
100 /**
101 * Default constructor.
102 *
103 */
104 public
105 Compound()
106 {
107 super();
108 }
109
110 /**
111 * Attribute constructor.
112 *
113 * Looks up the attributes in the parameter and casts them from strings
114 * appropriately
115 * @param atts: the attribute list.
116 *
117 */
118 // TODO Work in progress (attribute constructor).
119 public
120 Compound(Attributes atts)
121 {
122 super(atts);
123
124 {
125 int nIndex = atts.getIndex("", "isSolvent");
126 if (nIndex != -1)
127 {
128 isSolvent = (new Boolean(atts.getValue(nIndex))).booleanValue();
129 }
130 }
131
132 }
133
134 /**
135 * writeMAGEML
136 * <p>
137 * This method is responsible for assembling the attribute and
138 * association data into XML. It creates the object tag and then calls
139 * the writeAttributes and writeAssociation methods.
140 * <p>
141 *
142 */
143 public
144 void
145 writeMAGEML(Writer out)
146 throws IOException
147 {
148 out.write("<Compound");
149 writeAttributes(out);
150 out.write(">");
151 writeAssociations(out);
152 out.write("</Compound>");
153 }
154
155 /**
156 * writeAttributes
157 * <p>
158 * This method is responsible for assembling the attribute data into
159 * XML. It calls the super method to write out all attributes of this
160 * class and it's ancestors.
161 * <p>
162 *
163 */
164 public
165 void
166 writeAttributes(Writer out)
167 throws IOException
168 {
169 super.writeAttributes(out);
170 out.write(" isSolvent=\"" + isSolvent + "\"");
171 }
172
173 /**
174 * writeAssociations
175 * <p>
176 * This method is responsible for assembling the association data
177 * into XML. It calls the super method to write out all associations of
178 * this class's ancestors.
179 * <p>
180 *
181 */
182 public
183 void
184 writeAssociations(Writer out)
185 throws IOException
186 {
187 super.writeAssociations(out);
188 if ( merckIndex != null ){
189 out.write("<MerckIndex_assn>");
190 merckIndex.writeMAGEML(out);
191 out.write("</MerckIndex_assn>");
192 }
193 if ( componentCompounds.size() > 0 ){
194 out.write("<ComponentCompounds_assnlist>");
195 for ( int i = 0; i < componentCompounds.size(); i++) {
196 ((CompoundMeasurement)componentCompounds.elementAt(i)).writeMAGEML(out);
197 }
198 out.write("</ComponentCompounds_assnlist>");
199 }
200 }
201
202 /**
203 * Set method for isSolvent
204 * <p>
205 * @param value to set
206 * <p>
207 *
208 */
209 public
210 void
211 setIsSolvent(
212 boolean isSolvent
213 )
214 {
215 this.isSolvent = isSolvent;
216 }
217
218 /**
219 * Get method for isSolvent
220 * <p>
221 * @return value of the attribute
222 * <p>
223 *
224 */
225 public
226 boolean
227 getIsSolvent()
228 {
229 return isSolvent;
230 }
231
232 /**
233 * Set method for componentCompounds
234 * <p>
235 * @param value to set
236 * <p>
237 *
238 */
239 public
240 void
241 setComponentCompounds(
242 ComponentCompounds_list componentCompounds
243 )
244 {
245 ((List)this.componentCompounds).addAll((List)componentCompounds);
246 }
247
248 /**
249 * Get method for componentCompounds
250 * <p>
251 * @return value of the attribute
252 * <p>
253 *
254 */
255 public
256 ComponentCompounds_list
257 getComponentCompounds()
258 {
259 return componentCompounds;
260 }
261
262 /**
263 * Method to add CompoundMeasurement to ComponentCompounds_list
264 *
265 */
266 public
267 void
268 addToComponentCompounds(
269 CompoundMeasurement compoundMeasurement
270 )
271 {
272 this.componentCompounds.add(compoundMeasurement);
273 }
274
275 /**
276 * Method to add CompoundMeasurement at position to
277 * ComponentCompounds_list
278 *
279 */
280 public
281 void
282 addToComponentCompounds(
283 int position,
284 CompoundMeasurement compoundMeasurement
285 )
286 {
287 this.componentCompounds.add(position, compoundMeasurement);
288 }
289
290 /**
291 * Method to get CompoundMeasurement from ComponentCompounds_list
292 *
293 */
294 public
295 CompoundMeasurement
296 getFromComponentCompounds(
297 int position
298 )
299 {
300 return (CompoundMeasurement) this.componentCompounds.get(position);
301 }
302
303 /**
304 * Method to remove by position from ComponentCompounds_list
305 *
306 */
307 public
308 void
309 removeElementAtFromComponentCompounds(
310 int position
311 )
312 {
313 this.componentCompounds.removeElementAt(position);
314 }
315
316 /**
317 * Method to remove first CompoundMeasurement from
318 * ComponentCompounds_list
319 *
320 */
321 public
322 void
323 removeFromComponentCompounds(
324 CompoundMeasurement compoundMeasurement
325 )
326 {
327 this.componentCompounds.remove(compoundMeasurement);
328 }
329
330 /**
331 * Set method for merckIndex
332 * <p>
333 * @param value to set
334 * <p>
335 *
336 */
337 public
338 void
339 setMerckIndex(
340 OntologyEntry merckIndex
341 )
342 {
343 this.merckIndex = merckIndex;
344 }
345
346 /**
347 * Get method for merckIndex
348 * <p>
349 * @return value of the attribute
350 * <p>
351 *
352 */
353 public
354 OntologyEntry
355 getMerckIndex()
356 {
357 return merckIndex;
358 }
359
360 }