Line | Hits | Source |
---|---|---|
1 | package umich.cac.pbs; | |
2 | ||
3 | import java.util.logging.Logger; | |
4 | import java.util.logging.Level; | |
5 | import java.util.Hashtable; | |
6 | ||
7 | import umich.cac.data.*; | |
8 | import umich.cac.util.EntityEncoding; | |
9 | ||
10 | /** | |
11 | * Singleton takes a String from the PBS file, and returns the proper Field | |
12 | * object based on the name of the field, and the field value. | |
13 | * <p> | |
14 | * | |
15 | * Example: | |
16 | * | |
17 | * <pre> | |
18 | * //This would be coming from PBS String nameField = "date"; String valueField = "10/12/02 10:11:11"; //Grab the dateNode Field dateNode = FieldFactory.getInstance().getField(nameField, valueField); | |
19 | * </pre> | |
20 | * | |
21 | * @author rmach@umich.edu | |
22 | * @version $Header: /cvsroot/pbsaccounting/pbsaccounting/src/umich/cac/pbs/FieldFactory.java,v 1.6 2003/10/21 19:07:59 rodmach Exp $ | |
23 | */ | |
24 | ||
25 | public class FieldFactory { | |
26 | ||
27 | //Hashtable mapps between PBS raw name, and the FieldName object | |
28 | 3 | private Hashtable fieldHash = new Hashtable(); |
29 | ||
30 | //Logger | |
31 | 6 | private Logger logger = Logger.getLogger(FieldFactory.class.getName()); |
32 | ||
33 | //The singleton instance | |
34 | 3 | private static FieldFactory thisInstance = null; |
35 | ||
36 | /** | |
37 | * Get singleton instance | |
38 | * | |
39 | * @return The instance value | |
40 | */ | |
41 | ||
42 | public static synchronized FieldFactory getInstance() { | |
43 | ||
44 | 378 | if (thisInstance == null) { |
45 | ||
46 | 3 | thisInstance = new FieldFactory(); |
47 | ||
48 | } | |
49 | ||
50 | 378 | return thisInstance; |
51 | } | |
52 | ||
53 | /** | |
54 | * private Constructor. Creates the lookup table for mapping between the | |
55 | * raw PBS name and the Field objects | |
56 | */ | |
57 | ||
58 | 3 | private FieldFactory() { |
59 | ||
60 | //Get all the field names | |
61 | ||
62 | 3 | FieldName[] fields = FieldName.getAllFieldNames(); |
63 | ||
64 | //Create a Hash of [RAW NAME] --> FieldName for quick lookup | |
65 | ||
66 | 159 | for (int i = 0; i < fields.length; i++) { |
67 | 156 | fieldHash.put(fields[i].getRawName(), fields[i]); |
68 | } | |
69 | ||
70 | 3 | } |
71 | ||
72 | /** | |
73 | * Return the appropriate Field object based on the fieldName and | |
74 | * fieldValue, or null if no match is found | |
75 | * | |
76 | * @param pbsField | |
77 | * The name of the field, like "etime" | |
78 | * @param fieldValue | |
79 | * The corresponding value, like "12330404" | |
80 | * @return The Field object for this fieldName, fieldValue combination, or | |
81 | * null if there is no matching field found. | |
82 | */ | |
83 | ||
84 | public Field getField(String pbsField, String fieldValue) { | |
85 | ||
86 | //Encode XML reserved charachters like <, & etc | |
87 | 378 | fieldValue = EntityEncoding.encode(fieldValue); |
88 | ||
89 | 378 | FieldName fieldName = (FieldName) fieldHash.get(pbsField); |
90 | ||
91 | //Field not found in lookup table, return null | |
92 | ||
93 | 378 | if (fieldName == null) { |
94 | ||
95 | 3 | if (logger.isLoggable(Level.WARNING)) { |
96 | 3 | logger.warning( |
97 | "Field with name " | |
98 | + pbsField | |
99 | + " was not found in lookup table"); | |
100 | } | |
101 | ||
102 | 3 | return null; |
103 | } | |
104 | ||
105 | //Return the appropriate field based on the fieldName we found. | |
106 | ||
107 | //This could be a custom FieldName object, or the generic | |
108 | ||
109 | 375 | if (fieldName.rawequals(FieldName.NEED_NODES)) { |
110 | /* | |
111 | * NOTE: NodesField and NeedNodes field are the same, just the | |
112 | * value changes | |
113 | */ | |
114 | 9 | return new NodesField(FieldName.NEED_NODES, fieldValue); |
115 | 366 | } else if (fieldName.rawequals(FieldName.EXEC_HOST)) { |
116 | ||
117 | 9 | return new ExecHostField(FieldName.EXEC_HOST, fieldValue); |
118 | 357 | } else if (fieldName.rawequals(FieldName.MEM)) { |
119 | ||
120 | 6 | return new MemField(FieldName.MEM, fieldValue); |
121 | 351 | } else if (fieldName.rawequals(FieldName.VMEM)) { |
122 | ||
123 | 6 | return new MemField(FieldName.VMEM, fieldValue); |
124 | 345 | } else if (fieldName.rawequals(FieldName.NODES)) { |
125 | /* | |
126 | * Because of the problematic encoding of :ppn, this is handled | |
127 | * special. Note "value" actually has some additional decoding to | |
128 | * be done | |
129 | */ | |
130 | ||
131 | 9 | return new NodesField(FieldName.NODES, fieldValue); |
132 | 336 | } else if (fieldName.rawequals(FieldName.NODE)) { |
133 | 24 | return new NodeField(FieldName.NODE, fieldValue); |
134 | 312 | } else if (fieldName.rawequals(FieldName.DATE)) { |
135 | ||
136 | 24 | return new DateField(FieldName.DATE, fieldValue); |
137 | 288 | } else if (fieldName.rawequals(FieldName.MEMORY_R)) { |
138 | ||
139 | 0 | return new MemField(FieldName.MEMORY_R, fieldValue); |
140 | 288 | } else if (fieldName.rawequals(FieldName.BNODES)) { |
141 | ||
142 | 0 | return new BNodeField(FieldName.BNODES, fieldValue); |
143 | } else { | |
144 | 288 | return new Field(fieldName, fieldValue, fieldName.getFieldType()); |
145 | } | |
146 | ||
147 | } | |
148 | ||
149 | /** | |
150 | * Helper method to return the Field object when the FieldName and | |
151 | * FieldValue are known | |
152 | * | |
153 | * @param fieldName | |
154 | * Name of the field | |
155 | * @param fieldValue | |
156 | * Value of the field | |
157 | * @return The field value, or null if no matching field found | |
158 | */ | |
159 | ||
160 | public Field getField(FieldName fieldName, String fieldValue) { | |
161 | ||
162 | 201 | return getField(fieldName.getRawName(), fieldValue); |
163 | } | |
164 | ||
165 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |