KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > Record


1 package dinamica;
2
3 import java.io.Serializable JavaDoc;
4 import java.text.MessageFormat JavaDoc;
5 import java.util.HashMap JavaDoc;
6
7 /**
8  * Utility class for Recordset: represents a record inside a recordset
9  * <br>
10  * Creation date: 10/09/2003<br>
11  * Last Update: 29/april/2004<br>
12  * (c) 2004 Martin Cordova<br>
13  * This code is released under the LGPL license<br>
14  * @author Martin Cordova (dinamica@martincordova.com)
15  */

16 public class Record implements Serializable JavaDoc
17 {
18
19     /**
20      *
21      */

22     private static final long serialVersionUID = 1L;
23
24     /** container for field|value pairs */
25     HashMap JavaDoc _record = new HashMap JavaDoc();
26
27     /** every record in a recordset can contain a children recordset */
28     Recordset _children = null;
29
30     /**
31      * Quick constructor to build a record given a HashMap with field|value pairs
32      * @param values Record values
33      */

34     public Record(HashMap JavaDoc values)
35     {
36         _record = values;
37     }
38
39     /**
40      * Returns the field value (may be null). Throws exception if
41      * the field is not defined in the record
42      * @param fieldName Field name to retrieve value
43      * @return
44      * @throws Throwable
45      */

46     public Object JavaDoc getFieldValue(String JavaDoc fieldName) throws RecordsetException
47     {
48
49         if (!_record.containsKey(fieldName))
50         {
51             String JavaDoc args[] = {fieldName};
52             String JavaDoc msg = Errors.FIELD_NOT_FOUND;
53             msg = MessageFormat.format(msg, args);
54             throw new RecordsetException(msg);
55         }
56         return _record.get(fieldName);
57             
58     }
59
60     /**
61      * Set a field's value - throws exception if field does not exist
62      * @param fieldName Field Name
63      * @param value Value (Date, String, double, int, null)
64      * @throws Throwable
65      */

66     public void setValue(String JavaDoc fieldName, Object JavaDoc value) throws RecordsetException
67     {
68         if (!_record.containsKey(fieldName))
69         {
70             String JavaDoc args[] = {fieldName};
71             String JavaDoc msg = Errors.FIELD_NOT_FOUND;
72             msg = MessageFormat.format(msg, args);
73             throw new RecordsetException(msg);
74         }
75         
76         _record.put(fieldName, value );
77         
78     }
79     
80     /**
81      * Set the children recordset of this record
82      * @param rs Children recordset
83      */

84     public void setChildren(Recordset rs)
85     {
86         _children = rs;
87     }
88     
89     /**
90      * Retrieve this record's children recordset
91      * @return A reference to the recordset or null if no children recordset exists
92      */

93     public Recordset getChildren()
94     {
95         return _children;
96     }
97     
98     /**
99      * This constructor was added to support Glue SOAP toolkit
100      * 2005-05-14
101      */

102     public Record()
103     {
104     }
105
106 }
107
Popular Tags