Coverage details for umich.cac.pbs.FieldFactory

LineHitsSource
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
283    private Hashtable fieldHash = new Hashtable();
29  
30     //Logger
316    private Logger logger = Logger.getLogger(FieldFactory.class.getName());
32  
33     //The singleton instance
343    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  
44378        if (thisInstance == null) {
45  
463            thisInstance = new FieldFactory();
47  
48         }
49  
50378        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  
583    private FieldFactory() {
59  
60         //Get all the field names
61  
623        FieldName[] fields = FieldName.getAllFieldNames();
63  
64         //Create a Hash of [RAW NAME] --> FieldName for quick lookup
65  
66159        for (int i = 0; i < fields.length; i++) {
67156            fieldHash.put(fields[i].getRawName(), fields[i]);
68         }
69  
703    }
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
87378        fieldValue = EntityEncoding.encode(fieldValue);
88  
89378        FieldName fieldName = (FieldName) fieldHash.get(pbsField);
90  
91         //Field not found in lookup table, return null
92  
93378        if (fieldName == null) {
94  
953            if (logger.isLoggable(Level.WARNING)) {
963                logger.warning(
97                     "Field with name "
98                         + pbsField
99                         + " was not found in lookup table");
100             }
101  
1023            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  
109375        if (fieldName.rawequals(FieldName.NEED_NODES)) {
110             /*
111              * NOTE: NodesField and NeedNodes field are the same, just the
112              * value changes
113              */
1149            return new NodesField(FieldName.NEED_NODES, fieldValue);
115366        } else if (fieldName.rawequals(FieldName.EXEC_HOST)) {
116  
1179            return new ExecHostField(FieldName.EXEC_HOST, fieldValue);
118357        } else if (fieldName.rawequals(FieldName.MEM)) {
119  
1206            return new MemField(FieldName.MEM, fieldValue);
121351        } else if (fieldName.rawequals(FieldName.VMEM)) {
122  
1236            return new MemField(FieldName.VMEM, fieldValue);
124345        } 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  
1319            return new NodesField(FieldName.NODES, fieldValue);
132336        } else if (fieldName.rawequals(FieldName.NODE)) {
13324            return new NodeField(FieldName.NODE, fieldValue);
134312        } else if (fieldName.rawequals(FieldName.DATE)) {
135  
13624            return new DateField(FieldName.DATE, fieldValue);
137288        } else if (fieldName.rawequals(FieldName.MEMORY_R)) {
138  
1390            return new MemField(FieldName.MEMORY_R, fieldValue);
140288        } else if (fieldName.rawequals(FieldName.BNODES)) {
141  
1420            return new BNodeField(FieldName.BNODES, fieldValue);
143         } else {
144288            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  
162201        return getField(fieldName.getRawName(), fieldValue);
163     }
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.