KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > xml > accessors > XMLBasicAccessor


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.accessors;
23
24 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.BasicAccessor;
25 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.objects.MetadataAccessibleObject;
26 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataColumn;
27
28 import oracle.toplink.essentials.internal.ejb.cmp3.xml.accessors.XMLClassAccessor;
29
30 import oracle.toplink.essentials.internal.ejb.cmp3.xml.columns.XMLColumn;
31
32 import oracle.toplink.essentials.internal.ejb.cmp3.xml.sequencing.XMLGeneratedValue;
33 import oracle.toplink.essentials.internal.ejb.cmp3.xml.sequencing.XMLTableGenerator;
34 import oracle.toplink.essentials.internal.ejb.cmp3.xml.sequencing.XMLSequenceGenerator;
35
36 import oracle.toplink.essentials.internal.ejb.cmp3.xml.XMLHelper;
37 import oracle.toplink.essentials.internal.ejb.cmp3.xml.XMLConstants;
38
39 import oracle.toplink.essentials.internal.helper.DatabaseField;
40
41 import org.w3c.dom.Node JavaDoc;
42
43 /**
44  * An XML extended basic accessor.
45  *
46  * @author Guy Pelletier
47  * @since TopLink EJB 3.0 Reference Implementation
48  */

49 public class XMLBasicAccessor extends BasicAccessor implements XMLAccessor {
50     private Node JavaDoc m_node;
51     private XMLHelper m_helper;
52     
53     /**
54      * INTERNAL:
55      */

56     public XMLBasicAccessor(MetadataAccessibleObject accessibleObject, Node JavaDoc node, XMLClassAccessor classAccessor) {
57         super(accessibleObject, classAccessor);
58         m_node = node;
59         m_helper = classAccessor.getHelper();
60     }
61
62     /**
63      * INTERNAL:
64      */

65     public String JavaDoc getCatalog() {
66         return m_descriptor.getCatalog();
67     }
68     
69     /**
70      * INTERNAL: (OVERRIDE)
71      * Build a metadata column. If one isn't found in XML then look for an
72      * annotation.
73      */

74     protected MetadataColumn getColumn() {
75         Node JavaDoc node = m_helper.getNode(m_node, XMLConstants.COLUMN);
76         
77         if (node != null) {
78             return new XMLColumn(node, m_helper, this);
79         } else {
80             return super.getColumn();
81         }
82     }
83     
84     /**
85      * INTERNAL:
86      */

87     public String JavaDoc getDocumentName() {
88         return m_helper.getDocumentName();
89     }
90     
91     /**
92      * INTERNAL: (Overridden in XMLBasicAccessor)
93      */

94     public String JavaDoc getEnumeratedType() {
95         if (hasEnumerated()) {
96             return m_helper.getNodeTextValue(m_node, XMLConstants.ENUMERATED);
97         } else {
98             return super.getEnumeratedType();
99         }
100     }
101     
102     /**
103      * INTERNAL:
104      */

105     public XMLHelper getHelper() {
106         return m_helper;
107     }
108     
109     /**
110      * INTERNAL:
111      */

112     public String JavaDoc getSchema() {
113         return m_descriptor.getSchema();
114     }
115     
116     /**
117      * INTERNAL:
118      * Return the temporal type for this accessor. Assumes there is a temporal
119      * node.
120      */

121     public String JavaDoc getTemporalType() {
122         if (hasTemporal()) {
123             return m_helper.getNodeTextValue(m_node, XMLConstants.TEMPORAL);
124         } else {
125             return super.getTemporalType();
126         }
127     }
128     
129     /**
130      * INTERNAL: (OVERRIDE)
131      * Method to check if m_node has an enumerated sub-element.
132      */

133     public boolean hasEnumerated() {
134         Node JavaDoc node = m_helper.getNode(m_node, XMLConstants.ENUMERATED);
135         
136         if (node == null) {
137             return super.hasEnumerated();
138         } else {
139             return true;
140         }
141     }
142     
143     /**
144      * INTERNAL: (OVERRIDE)
145      * Method to check if m_node has a temporal sub-element.
146      */

147     public boolean hasTemporal() {
148         Node JavaDoc node = m_helper.getNode(m_node, XMLConstants.TEMPORAL);
149         
150         if (node == null) {
151             return super.hasTemporal();
152         } else {
153             return true;
154         }
155     }
156     
157     /**
158      * INTERNAL:
159      * Method to check if m_node represents a primary key.
160      */

161     public boolean isId() {
162         if (m_node.getLocalName().equals(XMLConstants.ID)) {
163             return true;
164         } else {
165             return super.isId();
166         }
167     }
168     
169     /**
170      * INTERNAL: (OVERRIDE)
171      * Return true if this accessor represents an BLOB/CLOB mapping, i.e. has a
172      * lob sub-element.
173      */

174     public boolean isLob() {
175         Node JavaDoc node = m_helper.getNode(m_node, XMLConstants.LOB);
176         
177         if (node == null) {
178             return super.isLob();
179         } else {
180             return true;
181         }
182     }
183     
184     /**
185      * INTERNAL:
186      * Return true if this accessor represents an optimistic locking field.
187      */

188     public boolean isVersion() {
189         Node JavaDoc node = m_helper.getNode(m_node, XMLConstants.VERSION);
190         
191         if (node == null) {
192             return super.isVersion();
193         } else {
194             return true;
195         }
196     }
197     
198     /**
199      * INTERNAL: (OVERRIDE)
200      */

201     protected void processGeneratedValue(DatabaseField field) {
202         Node JavaDoc node = m_helper.getNode(m_node, XMLConstants.GENERATED_VALUE);
203
204         if (node == null) {
205             super.processGeneratedValue(field);
206         } else {
207             // Ask the common processor to process what we found.
208
processGeneratedValue(new XMLGeneratedValue(node, m_helper), field);
209         }
210     }
211     
212     /**
213      * INTERNAL: (OVERRIDE)
214      * Process this accessor's sequence-generator node into a common metadata
215      * sequence generator.
216      */

217     protected void processSequenceGenerator() {
218         Node JavaDoc node = m_helper.getNode(m_node, XMLConstants.SEQUENCE_GENERATOR);
219         
220         if (node != null) {
221             // Process the xml defined sequence generators first.
222
processSequenceGenerator(new XMLSequenceGenerator(node, m_helper));
223         }
224         
225         // Process the annotation defined sequence generators second.
226
super.processSequenceGenerator();
227     }
228     
229     /**
230      * INTERNAL: (OVERRIDE)
231      * Process this accessor's table-generator node into a common metadata table
232      * generator.
233      */

234     protected void processTableGenerator() {
235         Node JavaDoc node = m_helper.getNode(m_node, XMLConstants.TABLE_GENERATOR);
236         
237         if (node != null) {
238             // Process the xml defined table generators first.
239
processTableGenerator(new XMLTableGenerator(node, this));
240         }
241         
242         // Process the annotation defined sequence generators second.
243
super.processTableGenerator();
244     }
245 }
246
Popular Tags