KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > xml > columns > XMLColumn


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.ejb.cmp3.xml.columns;
23
24 import java.lang.reflect.AnnotatedElement JavaDoc;
25
26 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataColumn;
27
28 import oracle.toplink.essentials.internal.ejb.cmp3.xml.accessors.XMLBasicAccessor;
29
30 import oracle.toplink.essentials.internal.ejb.cmp3.xml.XMLConstants;
31 import oracle.toplink.essentials.internal.ejb.cmp3.xml.XMLHelper;
32
33 import org.w3c.dom.Node JavaDoc;
34
35 /**
36  * Object to hold onto an xml column metadata in a TopLink database field.
37  *
38  * @author Guy Pelletier
39  * @since TopLink EJB 3.0 Reference Implementation
40  */

41 public class XMLColumn extends MetadataColumn {
42     /**
43      * INTERNAL:
44      * Called for attribute overrides from a class accessor or embedded
45      * accessor. If there is no column node, the database field values will
46      * default.
47      */

48     public XMLColumn(Node JavaDoc node, XMLHelper helper, AnnotatedElement JavaDoc annotatedElement) {
49         super(helper.getNodeValue(node, XMLConstants.ATT_NAME), annotatedElement);
50         
51         processColumnNode(helper.getNode(node, XMLConstants.COLUMN), helper);
52     }
53     
54     /**
55      * INTERNAL:
56      * Called for basic accessors. If there is no column node, the database
57      * field values will default.
58      */

59     public XMLColumn(Node JavaDoc node, XMLHelper helper, XMLBasicAccessor accessor) {
60         super(accessor.getAttributeName(), accessor.getAnnotatedElement());
61         
62         processColumnNode(node, helper);
63     }
64     
65     /**
66      * INTERNAL:
67      */

68     public boolean loadedFromXML() {
69         return true;
70     }
71     
72     /**
73      * INTERNAL:
74      */

75     protected void processColumnNode(Node JavaDoc node, XMLHelper helper) {
76         if (node != null) {
77             // Process the name attribute node.
78
m_databaseField.setName(helper.getNodeValue(node, XMLConstants.ATT_NAME, DEFAULT_NAME));
79         
80             // Process the table attribute node.
81
m_databaseField.setTableName(helper.getNodeValue(node, XMLConstants.ATT_TABLE, DEFAULT_TABLE));
82         
83             // Process the insertable attribute node.
84
m_databaseField.setInsertable(helper.getNodeValue(node, XMLConstants.ATT_INSERTABLE, DEFAULT_INSERTABLE));
85         
86             // Process the updatable attribute node.
87
m_databaseField.setUpdatable(helper.getNodeValue(node, XMLConstants.ATT_UPDATABLE, DEFAULT_UPDATABLE));
88         
89             // Process the unique attribute node.
90
m_databaseField.setUnique(helper.getNodeValue(node, XMLConstants.ATT_UNIQUE, DEFAULT_UNIQUE));
91         
92             // Process the nullable attribute node.
93
m_databaseField.setNullable(helper.getNodeValue(node, XMLConstants.ATT_NULLABLE, DEFAULT_NULLABLE));
94         
95             // Process the column-definition attribute node.
96
m_databaseField.setColumnDefinition(helper.getNodeValue(node, XMLConstants.ATT_COLUMN_DEFINITION, DEFAULT_COLUMN_DEFINITION));
97         
98             // Process the length attribute node.
99
m_databaseField.setLength(helper.getNodeValue(node, XMLConstants.ATT_LENGTH, DEFAULT_LENGTH));
100         
101             // Process the precision attribute node.
102
m_databaseField.setPrecision(helper.getNodeValue(node, XMLConstants.ATT_PRECISION, DEFAULT_PRECISION));
103         
104             // Process the scale attribute node.
105
m_databaseField.setScale(helper.getNodeValue(node, XMLConstants.ATT_SCALE, DEFAULT_SCALE));
106         }
107     }
108 }
109
Popular Tags