Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: nectar/record/datatypes/RecordDataElement.java


1   /*
2       Copyright (C) 2003  Kai Schutte
3   
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8   
9       This program is distributed in the hope that it will be useful,
10      but WITHOUT ANY WARRANTY; without even the implied warranty of
11      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12      GNU General Public License for more details.
13  
14      You should have received a copy of the GNU General Public License
15      along with this program; if not, write to the Free Software
16      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
17   
18   * RecordDataElement.java
19   *
20   * Created on March 19, 2003, 10:02 PM
21   */
22  
23  package nectar.record.datatypes;
24  
25  import java.io.Serializable;
26  import nectar.record.RecordInvalidInputException;
27  /** The top-level class for all record data elements. Record Classes store their property values in the classes that inherit from this abstract class. The <CODE>RecordDataElement</CODE> classes offer an input validation method, convert the <CODE>Object</CODE> received from the <CODE>DataAdapter</CODE> into their base type and convert this type back into a DataAdapter readable <CODE>String</CODE> value.
28   * Each implementing class must also implement a <CODE>public * getDataValue();</CODE> method, which returns a <B>copy</B> of the value in an approriate object type. RecordInteger has, for example:<br>
29   * <PRE>
30   *    public Integer getDataValue() {
31   *        if (value == null) {
32   *            return null;
33   *        } else {
34   *            return new Integer(value.intValue());
35   *        }
36   *    }
37   * </PRE>
38   * <p>
39   *
40   * Take, for example, the <CODE>RecordDate</CODE> class: The <CODE>assignDataValue()</CODE> method, receives an <CODE>Object</CODE> that originates from the <CODE>DataAdapterService</CODE>, usually the SQL datasource. If the database field is a <PRE>DATE</PRE> or <PRE>DATETIME</PRE> field, that Object will be of type <CODE>java.util.Date</CODE> or <CODE>null</CODE>.
41   * The <CODE>getDataValue()</CODE> method returns a <CODE>Date</CODE> object or null, the <CODE>getStringValue()</CODE> returns a <CODE>String</CODE> in the format: "YYYY-MM-DD HH:MM:SS", so that the database server can parse it.<p>
42   * The classes inherited from this class <b>must</b> be final and cannot have child classes, because the <code>Record.getFields()</code> method filters Record class member fields by their first level ancestry to this class (RecordDataElement).
43   *
44   * @author Kai Schutte skander@skander.com
45   */
46  public abstract class RecordDataElement implements Serializable,IRecordDataElement {
47      private String fieldName = null;
48      protected boolean nullAllowed = false;
49      /** Creates a new instance of a RecordDataElement which doesn't allow null values.
50       * @param fieldName The database field name String for this RecordDataElement within the Record that instantiates it.
51       */    
52      public RecordDataElement(String fieldName) {
53          this.setFieldName(fieldName);
54      }
55      
56      /** Creates a new instance of a RecordDataElement
57       * @param fieldName The database field name String for this RecordDataElement within the Record that instantiates it.
58       * @param nullAllowed true if this data Element may be null, false to force this data element to be non-null.
59       */    
60      public RecordDataElement(String fieldName, boolean nullAllowed) {
61          this.setFieldName(fieldName);
62          this.nullAllowed = nullAllowed;
63      }
64      
65      
66      /** Returns the database field name String for this RecordDataElement within the Record that has instantiated it.
67       * @return The database field name.
68       */    
69      public String getFieldName() {
70          return fieldName;
71      }
72  
73      /** Sets the database field name String for this RecordDataElement within the Record that instantiates it.
74       * @param fieldName The database field name.
75       */    
76      protected void setFieldName(String fieldName) {
77          this.fieldName = fieldName;
78      }
79  
80  }