Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/biomage/Common/NameValueType.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:49 AM                                  *
43   *                                                                         *
44   ***************************************************************************
45   */
46  
47  /**
48   *  org.biomage.Common
49   *  
50   */
51  package org.biomage.Common;
52  
53  /**
54   *  Import list for NameValueType
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   *  A tuple designed to store data, keyed by a name and type.
66   *  
67   */
68  public
69  class NameValueType
70      implements Serializable,
71          HasPropertySets
72  {
73      /**
74       *  The name of the key.
75       *  
76       */
77       String name;
78  
79      /**
80       *  The value of the name.
81       *  
82       */
83       String value;
84  
85      /**
86       *  The type of the key.
87       *  
88       */
89       String type;
90  
91      /**
92       *  Allows nested specification of name/value pairs
93       *  
94       */
95      private PropertySets_list propertySets = new PropertySets_list();
96  
97      /**
98       *  Default constructor.
99       *  
100      */
101     public
102     NameValueType()
103     {
104     }
105 
106     /**
107      *  Attribute constructor.
108      *  
109      *  Looks up the attributes in the parameter and casts them from strings 
110      *  appropriately
111      *  @param atts: the attribute list.
112      *  
113      */
114     // TODO Work in progress (attribute constructor).
115     public
116     NameValueType(Attributes atts)
117     {
118         {
119             int nIndex = atts.getIndex("", "name");
120             if (nIndex != -1)
121             {
122                 name = atts.getValue(nIndex);
123             }
124         }
125 
126         {
127             int nIndex = atts.getIndex("", "value");
128             if (nIndex != -1)
129             {
130                 value = atts.getValue(nIndex);
131             }
132         }
133 
134         {
135             int nIndex = atts.getIndex("", "type");
136             if (nIndex != -1)
137             {
138                 type = atts.getValue(nIndex);
139             }
140         }
141 
142     }
143 
144     /**
145      *  writeMAGEML
146      *  <p>
147      *  This method is responsible for assembling the attribute and 
148      *  association data into XML. It creates the object tag and then calls 
149      *  the writeAttributes and writeAssociation methods.
150      *  <p>
151      *  
152      */
153     public
154     void
155     writeMAGEML(Writer out)
156     throws IOException
157     {
158         out.write("<NameValueType");
159         writeAttributes(out);
160         out.write(">");
161         writeAssociations(out);
162         out.write("</NameValueType>");
163     }
164 
165     /**
166      *  writeAttributes
167      *  <p>
168      *  This method is responsible for assembling the attribute data into 
169      *  XML. It calls the super method to write out all attributes of this 
170      *  class and it's ancestors.
171      *  <p>
172      *  
173      */
174     public
175     void
176     writeAttributes(Writer out)
177     throws IOException
178     {
179         if ( name != null ) {
180             out.write(" name=\"" + name + "\"");
181         }
182         if ( value != null ) {
183             out.write(" value=\"" + value + "\"");
184         }
185         if ( type != null ) {
186             out.write(" type=\"" + type + "\"");
187         }
188     }
189 
190     /**
191      *  writeAssociations
192      *  <p>
193      *  This method is responsible for assembling the association data 
194      *  into XML. It calls the super method to write out all associations of 
195      *  this class's ancestors.
196      *  <p>
197      *  
198      */
199     public
200     void
201     writeAssociations(Writer out)
202     throws IOException
203     {
204         if ( propertySets.size() > 0 ){
205             out.write("<PropertySets_assnlist>");
206             for ( int i = 0; i < propertySets.size(); i++) {
207                 ((NameValueType)propertySets.elementAt(i)).writeMAGEML(out);
208             }
209             out.write("</PropertySets_assnlist>");
210         }
211     }
212 
213     /**
214      *  Set method for name
215      *  <p>
216      *  @param value to set
217      *  <p>
218      *  
219      */
220     public
221     void
222     setName(
223         String name
224     )
225     {
226         this.name = name;
227     }
228 
229     /**
230      *  Get method for name
231      *  <p>
232      *  @return value of the attribute
233      *  <p>
234      *  
235      */
236     public
237     String
238     getName()
239     {
240         return name;
241     }
242 
243     /**
244      *  Set method for value
245      *  <p>
246      *  @param value to set
247      *  <p>
248      *  
249      */
250     public
251     void
252     setValue(
253         String value
254     )
255     {
256         this.value = value;
257     }
258 
259     /**
260      *  Get method for value
261      *  <p>
262      *  @return value of the attribute
263      *  <p>
264      *  
265      */
266     public
267     String
268     getValue()
269     {
270         return value;
271     }
272 
273     /**
274      *  Set method for type
275      *  <p>
276      *  @param value to set
277      *  <p>
278      *  
279      */
280     public
281     void
282     setType(
283         String type
284     )
285     {
286         this.type = type;
287     }
288 
289     /**
290      *  Get method for type
291      *  <p>
292      *  @return value of the attribute
293      *  <p>
294      *  
295      */
296     public
297     String
298     getType()
299     {
300         return type;
301     }
302 
303     /**
304      *  Set method for propertySets
305      *  <p>
306      *  @param value to set
307      *  <p>
308      *  
309      */
310     public
311     void
312     setPropertySets(
313         PropertySets_list propertySets
314     )
315     {
316         ((List)this.propertySets).addAll((List)propertySets);
317     }
318 
319     /**
320      *  Get method for propertySets
321      *  <p>
322      *  @return value of the attribute
323      *  <p>
324      *  
325      */
326     public
327     PropertySets_list
328     getPropertySets()
329     {
330         return propertySets;
331     }
332 
333     /**
334      *  Method to add NameValueType to PropertySets_list
335      *  
336      */
337     public
338     void
339     addToPropertySets(
340         NameValueType nameValueType
341     )
342     {
343         this.propertySets.add(nameValueType);
344     }
345 
346     /**
347      *  Method to add NameValueType at position to PropertySets_list
348      *  
349      */
350     public
351     void
352     addToPropertySets(
353         int position,
354         NameValueType nameValueType
355     )
356     {
357         this.propertySets.add(position, nameValueType);
358     }
359 
360     /**
361      *  Method to get NameValueType from PropertySets_list
362      *  
363      */
364     public
365     NameValueType
366     getFromPropertySets(
367         int position
368     )
369     {
370         return (NameValueType) this.propertySets.get(position);
371     }
372 
373     /**
374      *  Method to remove by position from PropertySets_list
375      *  
376      */
377     public
378     void
379     removeElementAtFromPropertySets(
380         int position
381     )
382     {
383         this.propertySets.removeElementAt(position);
384     }
385 
386     /**
387      *  Method to remove first NameValueType from PropertySets_list
388      *  
389      */
390     public
391     void
392     removeFromPropertySets(
393         NameValueType nameValueType
394     )
395     {
396         this.propertySets.remove(nameValueType);
397     }
398 
399 }