]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/java/org/opensrf/util/OSRFObject.java
added new constructor to build from class hints
[OpenSRF.git] / src / java / org / opensrf / util / OSRFObject.java
1 package org.opensrf.util;
2
3 import java.util.Map;
4 import java.util.HashMap;
5
6
7 /**
8  * Generic OpenSRF network-serializable object.  This allows
9  * access to object fields.  
10  */
11 public class OSRFObject extends HashMap<String, Object> implements OSRFSerializable {
12     
13     /** This objects registry */
14     private OSRFRegistry registry;
15
16     public OSRFObject() {
17     }
18
19
20     /**
21      * Creates a new object with the provided registry
22      */
23     public OSRFObject(OSRFRegistry reg) {
24         this();
25         registry = reg;
26     }
27
28
29     /**
30      * Creates a new OpenSRF object based on the net class string
31      * */
32     public OSRFObject(String netClass) {
33         this(OSRFRegistry.getRegistry(netClass));
34     }
35
36
37     /**
38      * @return This object's registry
39      */
40     public OSRFRegistry getRegistry() {
41         return registry;
42     }
43
44     /**
45      * Implement get() to fulfill our contract with OSRFSerializable
46      */
47     public Object get(String field) {
48         return super.get(field);
49     }
50
51     /** Returns the string value found at the given field */
52     public String getString(String field) {
53         return (String) get(field);
54     }
55
56     /** Returns the int value found at the given field */
57     public int getInt(String field) {
58         Object o = get(field);
59         if(o instanceof String)
60             return Integer.parseInt((String) o);
61         return ((Integer) get(field)).intValue();
62     }
63 }