Source code: org/biomage/Description/OntologyEntry.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:30 AM *
43 * *
44 ***************************************************************************
45 */
46
47 /**
48 * org.biomage.Description
49 *
50 */
51 package org.biomage.Description;
52
53 /**
54 * Import list for OntologyEntry
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.HasOntologyReference;
63 import org.biomage.Common.Extendable;
64
65 /**
66 * A single entry from an ontology or a controlled vocabulary. For
67 * instance, category could be 'species name', value could be 'homo
68 * sapiens' and ontology would be taxonomy database, NCBI.
69 *
70 */
71 public
72 class OntologyEntry
73 extends Extendable
74 implements Serializable,
75 HasOntologyReference
76 {
77 /**
78 * The category to which this entry belongs.
79 *
80 */
81 String category;
82
83 /**
84 * The value for this entry in this category.
85 *
86 */
87 String value;
88
89 /**
90 * The description of the meaning for this entry.
91 *
92 */
93 String description;
94
95 /**
96 * Many ontology entries will not yet have formalized ontologies.
97 * In those cases, they will not have a database reference to the
98 * ontology.
99 *
100 * In the future it is highly encouraged that these ontologies be
101 * developed and ontologyEntry be subclassed from DatabaseReference.
102 *
103 */
104 private DatabaseEntry ontologyReference;
105
106
107 /**
108 * Default constructor.
109 *
110 */
111 public
112 OntologyEntry()
113 {
114 super();
115 }
116
117 /**
118 * Attribute constructor.
119 *
120 * Looks up the attributes in the parameter and casts them from strings
121 * appropriately
122 * @param atts: the attribute list.
123 *
124 */
125 // TODO Work in progress (attribute constructor).
126 public
127 OntologyEntry(Attributes atts)
128 {
129 super(atts);
130
131 {
132 int nIndex = atts.getIndex("", "category");
133 if (nIndex != -1)
134 {
135 category = atts.getValue(nIndex);
136 }
137 }
138
139 {
140 int nIndex = atts.getIndex("", "value");
141 if (nIndex != -1)
142 {
143 value = atts.getValue(nIndex);
144 }
145 }
146
147 {
148 int nIndex = atts.getIndex("", "description");
149 if (nIndex != -1)
150 {
151 description = atts.getValue(nIndex);
152 }
153 }
154
155 }
156
157 /**
158 * writeMAGEML
159 * <p>
160 * This method is responsible for assembling the attribute and
161 * association data into XML. It creates the object tag and then calls
162 * the writeAttributes and writeAssociation methods.
163 * <p>
164 *
165 */
166 public
167 void
168 writeMAGEML(Writer out)
169 throws IOException
170 {
171 out.write("<OntologyEntry");
172 writeAttributes(out);
173 out.write(">");
174 writeAssociations(out);
175 out.write("</OntologyEntry>");
176 }
177
178 /**
179 * writeAttributes
180 * <p>
181 * This method is responsible for assembling the attribute data into
182 * XML. It calls the super method to write out all attributes of this
183 * class and it's ancestors.
184 * <p>
185 *
186 */
187 public
188 void
189 writeAttributes(Writer out)
190 throws IOException
191 {
192 super.writeAttributes(out);
193 if ( category != null ) {
194 out.write(" category=\"" + category + "\"");
195 }
196 if ( value != null ) {
197 out.write(" value=\"" + value + "\"");
198 }
199 if ( description != null ) {
200 out.write(" description=\"" + description + "\"");
201 }
202 }
203
204 /**
205 * writeAssociations
206 * <p>
207 * This method is responsible for assembling the association data
208 * into XML. It calls the super method to write out all associations of
209 * this class's ancestors.
210 * <p>
211 *
212 */
213 public
214 void
215 writeAssociations(Writer out)
216 throws IOException
217 {
218 super.writeAssociations(out);
219 if ( ontologyReference != null ){
220 out.write("<OntologyReference_assn>");
221 ontologyReference.writeMAGEML(out);
222 out.write("</OntologyReference_assn>");
223 }
224 }
225
226 /**
227 * Set method for category
228 * <p>
229 * @param value to set
230 * <p>
231 *
232 */
233 public
234 void
235 setCategory(
236 String category
237 )
238 {
239 this.category = category;
240 }
241
242 /**
243 * Get method for category
244 * <p>
245 * @return value of the attribute
246 * <p>
247 *
248 */
249 public
250 String
251 getCategory()
252 {
253 return category;
254 }
255
256 /**
257 * Set method for value
258 * <p>
259 * @param value to set
260 * <p>
261 *
262 */
263 public
264 void
265 setValue(
266 String value
267 )
268 {
269 this.value = value;
270 }
271
272 /**
273 * Get method for value
274 * <p>
275 * @return value of the attribute
276 * <p>
277 *
278 */
279 public
280 String
281 getValue()
282 {
283 return value;
284 }
285
286 /**
287 * Set method for description
288 * <p>
289 * @param value to set
290 * <p>
291 *
292 */
293 public
294 void
295 setDescription(
296 String description
297 )
298 {
299 this.description = description;
300 }
301
302 /**
303 * Get method for description
304 * <p>
305 * @return value of the attribute
306 * <p>
307 *
308 */
309 public
310 String
311 getDescription()
312 {
313 return description;
314 }
315
316 /**
317 * Set method for ontologyReference
318 * <p>
319 * @param value to set
320 * <p>
321 *
322 */
323 public
324 void
325 setOntologyReference(
326 DatabaseEntry ontologyReference
327 )
328 {
329 this.ontologyReference = ontologyReference;
330 }
331
332 /**
333 * Get method for ontologyReference
334 * <p>
335 * @return value of the attribute
336 * <p>
337 *
338 */
339 public
340 DatabaseEntry
341 getOntologyReference()
342 {
343 return ontologyReference;
344 }
345
346 }