KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > jdbc > metadata > JDBCCMPFieldPropertyMetaData


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb.plugins.cmp.jdbc.metadata;
23
24 import org.jboss.deployment.DeploymentException;
25 import org.jboss.metadata.MetaData;
26
27 import org.w3c.dom.Element JavaDoc;
28
29 /**
30  * This immutable class contains information about the an overriden field property.
31  *
32  * @author <a HREF="mailto:dain@daingroup.com">Dain Sundstrom</a>
33  * @version $Revision: 37459 $
34  */

35 public final class JDBCCMPFieldPropertyMetaData {
36    /**
37     * the cmp field on which this property is defined
38     */

39    private final JDBCCMPFieldMetaData cmpField;
40    
41    /**
42     * name of this property
43     */

44    private final String JavaDoc propertyName;
45
46    /**
47     * the column name in the table
48     */

49    private final String JavaDoc columnName;
50
51    /**
52     * the jdbc type (see java.sql.Types), used in PreparedStatement.setParameter
53     */

54    private final int jdbcType;
55
56    /**
57     * the sql type, used for table creation.
58     */

59    private final String JavaDoc sqlType;
60    
61    /**
62     * Should null values not be allowed for this property.
63     */

64    private final boolean notNull;
65
66    /**
67     * Constructs cmp field property meta data with the data contained in the
68     * property xml element from a jbosscmp-jdbc xml file.
69     *
70     * @param cmpField the JDBCCMPFieldMetaData on which this property is defined
71     * @param element the xml Element which contains the metadata about this
72     * field
73     * @throws DeploymentException if the xml element is not semantically correct
74     */

75    public JDBCCMPFieldPropertyMetaData(
76          JDBCCMPFieldMetaData cmpField,
77          Element JavaDoc element) throws DeploymentException {
78
79       this.cmpField = cmpField;
80       
81       // Property name
82
propertyName = MetaData.getUniqueChildContent(element, "property-name");
83
84       // Column name
85
String JavaDoc columnStr =
86             MetaData.getOptionalChildContent(element, "column-name");
87       if(columnStr != null) {
88          columnName = columnStr;
89       } else {
90          columnName = null;
91       }
92
93       // jdbc type
94
String JavaDoc jdbcStr = MetaData.getOptionalChildContent(element, "jdbc-type");
95       if(jdbcStr != null) {
96          jdbcType = JDBCMappingMetaData.getJdbcTypeFromName(jdbcStr);
97          sqlType = MetaData.getUniqueChildContent(element, "sql-type");
98       } else {
99          jdbcType = Integer.MIN_VALUE;
100          sqlType = null;
101       }
102
103       // notNull
104
notNull = (MetaData.getOptionalChild(element, "not-null") != null);
105    }
106
107    /**
108     * Constructs cmp field property meta data based on the data contained in
109     * the defaultValues parameter but defined on the specified cmpField. This
110     * is effectly a copy constructory, except it can change the cmpField object
111     * on which the property is defined.
112     *
113     * @param cmpField the JDBCCMPFieldMetaData on which this property is defined
114     * @param defaultValues the defaultValues of this property
115     */

116    public JDBCCMPFieldPropertyMetaData(
117          JDBCCMPFieldMetaData cmpField,
118          JDBCCMPFieldPropertyMetaData defaultValues) {
119
120       this.cmpField = cmpField;
121       
122       // Property name
123
propertyName = defaultValues.propertyName;
124
125       // Column name
126
columnName = defaultValues.columnName;
127
128       // jdbc type
129
jdbcType = defaultValues.jdbcType;
130       
131       // sql type
132
sqlType = defaultValues.sqlType;
133       
134       // not-null
135
notNull = defaultValues.notNull;
136    }
137
138    /**
139     * Gets the name of the property to be overriden.
140     */

141    public String JavaDoc getPropertyName() {
142       return propertyName;
143    }
144
145    /**
146     * Gets the column name the property should use or null if the
147     * column name is not overriden.
148     */

149    public String JavaDoc getColumnName() {
150       return columnName;
151    }
152
153    /**
154     * Gets the JDBC type the property should use or Integer.MIN_VALUE
155     * if not overriden.
156     */

157    public int getJDBCType() {
158       return jdbcType;
159    }
160
161    /**
162     * Gets the SQL type the property should use or null
163     * if not overriden.
164     */

165    public String JavaDoc getSQLType() {
166       return sqlType;
167    }
168    
169    /**
170     * Should this field allow null values?
171     * @return true if this field will not allow a null value.
172     */

173    public boolean isNotNull() {
174       return notNull;
175    }
176
177    /**
178     * Compares this JDBCCMPFieldPropertyMetaData against the specified object.
179     * Returns true if the objects are the same. Two
180     * JDBCCMPFieldPropertyMetaData are the same if they both have the same name
181     * and are defined on the same cmpField.
182     * @param o the reference object with which to compare
183     * @return true if this object is the same as the object argument; false
184     * otherwise
185     */

186    public boolean equals(Object JavaDoc o) {
187       if(o instanceof JDBCCMPFieldPropertyMetaData) {
188          JDBCCMPFieldPropertyMetaData cmpFieldProperty =
189                (JDBCCMPFieldPropertyMetaData)o;
190          return propertyName.equals(cmpFieldProperty.propertyName) &&
191                cmpField.equals(cmpFieldProperty.cmpField);
192       }
193       return false;
194    }
195    
196    /**
197     * Returns a hashcode for this JDBCCMPFieldPropertyMetaData. The hashcode is
198     * computed based on the hashCode of the declaring entity and the hashCode
199     * of the fieldName
200     * @return a hash code value for this object
201     */

202    public int hashCode() {
203       int result = 17;
204       result = 37*result + cmpField.hashCode();
205       result = 37*result + propertyName.hashCode();
206       return result;
207    }
208
209    /**
210     * Returns a string describing this JDBCCMPFieldPropertyMetaData. The exact
211     * details of the representation are unspecified and subject to change, but
212     * the following may be regarded as typical:
213     *
214     * "[JDBCCMPFieldPropertyMetaData: propertyName=line1,
215     * [JDBCCMPFieldMetaData: fieldName=address,
216     * [JDBCEntityMetaData: entityName=UserEJB]]"
217     *
218     * @return a string representation of the object
219     */

220    public String JavaDoc toString() {
221       return "[JDBCCMPFieldPropertyMetaData : propertyName=" +
222             propertyName + ", " + cmpField + "]";
223    }
224 }
225
Popular Tags