Line | Hits | Source |
---|---|---|
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 */ | |
17 | 546 | protected FieldName fieldName = null; |
18 | ||
19 | /** The type of field this is */ | |
20 | 546 | protected FieldType fieldType = null; |
21 | ||
22 | /** A container for child fields */ | |
23 | 546 | protected Vector childrenFields = new Vector(); |
24 | ||
25 | /** The raw value of this field from accounting file */ | |
26 | 546 | protected String rawValue = null; |
27 | ||
28 | /** The new line seperator for this system */ | |
29 | 546 | protected String nl = System.getProperty("line.separator"); |
30 | ||
31 | /* A list of attribute objects */ | |
32 | 546 | 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 | */ | |
44 | 546 | public Field(FieldName fieldName, String rawValue, FieldType fieldType) { |
45 | 546 | this.fieldName = fieldName; |
46 | 546 | this.rawValue = rawValue; |
47 | 546 | this.fieldType = fieldType; |
48 | 546 | } |
49 | ||
50 | /** | |
51 | * Return the FieldName, for unit testing | |
52 | * | |
53 | * @return FieldName The FieldName object for this Field | |
54 | */ | |
55 | public FieldName getFieldName() { | |
56 | 3 | return fieldName; |
57 | } | |
58 | ||
59 | /** | |
60 | * Return the type of field this is | |
61 | * | |
62 | * @return The fieldType value | |
63 | */ | |
64 | public FieldType getFieldType() { | |
65 | 357 | 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() { | |
74 | 0 | 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) { | |
85 | 0 | this.rawValue = rawValue; |
86 | 0 | } |
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) { | |
95 | 480 | childrenFields.add(childField); |
96 | 480 | } |
97 | ||
98 | /** | |
99 | * Gets the children Fields of this field | |
100 | * | |
101 | * @return A vector of children Fields | |
102 | */ | |
103 | public Vector getChildren() { | |
104 | 0 | 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 | ||
115 | 75 | if (attribute == null) { |
116 | 0 | throw new IllegalArgumentException("attribute can not be null"); |
117 | } | |
118 | ||
119 | 75 | attributeList.add(attribute); |
120 | 75 | } |
121 | ||
122 | /** | |
123 | * Return the attributes, in order they were added | |
124 | * | |
125 | * @return List of Attribute objects | |
126 | */ | |
127 | ||
128 | public List getAttributes() { | |
129 | 504 | 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 | |
140 | 504 | StringBuffer xmlBuffer = new StringBuffer(); |
141 | ||
142 | 504 | if (childrenFields.size() > 0) { |
143 | ||
144 | 171 | xmlBuffer.append(fieldName.openTag(getAttributes())); |
145 | 171 | xmlBuffer.append(nl); |
146 | ||
147 | 621 | for (int i = 0; i < childrenFields.size(); i++) { |
148 | 450 | Field myField = (Field) childrenFields.elementAt(i); |
149 | ||
150 | 450 | xmlBuffer.append(myField.toXML()); |
151 | } | |
152 | ||
153 | 171 | xmlBuffer.append(fieldName.closeTag()); |
154 | 171 | xmlBuffer.append(nl); |
155 | } else { | |
156 | ||
157 | 333 | xmlBuffer.append(fieldName.openTag(getAttributes())); |
158 | 333 | xmlBuffer.append(rawValue.trim()); |
159 | 333 | xmlBuffer.append(fieldName.closeTag()); |
160 | 333 | xmlBuffer.append(nl); |
161 | } | |
162 | ||
163 | 504 | return xmlBuffer.toString(); |
164 | } | |
165 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |