Coverage details for umich.cac.data.Field

LineHitsSource
1 package umich.cac.data;
2 import java.util.ArrayList;
3 import java.util.List;
4 import java.util.Vector;
5  
6 /**
7  * This class encapsulates a a "Field" of a PBS accounting record. A field
8  * contains a name, value, and child fields
9  *
10  * @author rmach@umich.edu
11  * @version $Header: /cvsroot/pbsaccounting/pbsaccounting/src/umich/cac/data/Field.java,v 1.5 2003/10/21 19:08:00 rodmach Exp $
12  *
13  */
14 public class Field {
15  
16     /** Encapsulates the raw name and display name of the field */
17546    protected FieldName fieldName = null;
18  
19     /** The type of field this is */
20546    protected FieldType fieldType = null;
21  
22     /** A container for child fields */
23546    protected Vector childrenFields = new Vector();
24  
25     /** The raw value of this field from accounting file */
26546    protected String rawValue = null;
27  
28     /** The new line seperator for this system */
29546    protected String nl = System.getProperty("line.separator");
30  
31     /* A list of attribute objects */
32546    private List attributeList = new ArrayList();
33  
34     /**
35      * Constructor
36      *
37      * @param fieldName
38      * FieldName describing this field
39      * @param rawValue
40      * The value of this field from accounting data
41      * @param fieldType
42      * The type of field
43      */
44546    public Field(FieldName fieldName, String rawValue, FieldType fieldType) {
45546        this.fieldName = fieldName;
46546        this.rawValue = rawValue;
47546        this.fieldType = fieldType;
48546    }
49  
50     /**
51      * Return the FieldName, for unit testing
52      *
53      * @return FieldName The FieldName object for this Field
54      */
55     public FieldName getFieldName() {
563        return fieldName;
57     }
58  
59     /**
60      * Return the type of field this is
61      *
62      * @return The fieldType value
63      */
64     public FieldType getFieldType() {
65357        return fieldType;
66     }
67  
68     /**
69      * Returns the "raw" value from PBS encoding. Used for unit tests
70      *
71      * @return The rawValue value
72      */
73     public String getRawValue() {
740        return rawValue;
75     }
76  
77     /**
78      * Returns the "raw" value from PBS encoding. Used for unit tests protected
79      * so some special fields (like neednodes) that need to munge themselves
80      * can do so
81      *
82      * @return The rawValue value
83      */
84     protected void setRawValue(String rawValue) {
850        this.rawValue = rawValue;
860    }
87  
88     /**
89      * Add children Fields to this field.
90      *
91      * @param childField
92      * a child to this field
93      */
94     public void addChild(Field childField) {
95480        childrenFields.add(childField);
96480    }
97  
98     /**
99      * Gets the children Fields of this field
100      *
101      * @return A vector of children Fields
102      */
103     public Vector getChildren() {
1040        return childrenFields;
105     }
106  
107     /**
108      * Add an attribute object to this list, in order they should appear
109      *
110      * @param Attribute
111      * attribute to add
112      */
113     public void addAttribute(Attribute attribute) {
114  
11575        if (attribute == null) {
1160            throw new IllegalArgumentException("attribute can not be null");
117         }
118  
11975        attributeList.add(attribute);
12075    }
121  
122     /**
123      * Return the attributes, in order they were added
124      *
125      * @return List of Attribute objects
126      */
127  
128     public List getAttributes() {
129504        return attributeList;
130     }
131  
132     /**
133      * Renders the XML representation of this field, and all of it's children
134      *
135      * @return The XML representation of the field
136      */
137     public String toXML() {
138  
139         //If we have children, we are just a container field
140504        StringBuffer xmlBuffer = new StringBuffer();
141  
142504        if (childrenFields.size() > 0) {
143  
144171            xmlBuffer.append(fieldName.openTag(getAttributes()));
145171            xmlBuffer.append(nl);
146  
147621            for (int i = 0; i < childrenFields.size(); i++) {
148450                Field myField = (Field) childrenFields.elementAt(i);
149  
150450                xmlBuffer.append(myField.toXML());
151             }
152  
153171            xmlBuffer.append(fieldName.closeTag());
154171            xmlBuffer.append(nl);
155         } else {
156  
157333            xmlBuffer.append(fieldName.openTag(getAttributes()));
158333            xmlBuffer.append(rawValue.trim());
159333            xmlBuffer.append(fieldName.closeTag());
160333            xmlBuffer.append(nl);
161         }
162  
163504        return xmlBuffer.toString();
164     }
165 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.