KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > metadata > accessors > NonRelationshipAccessor


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.metadata.accessors;
23
24 import javax.persistence.SequenceGenerator;
25 import javax.persistence.TableGenerator;
26
27 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.objects.MetadataAccessibleObject;
28
29 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataConstants;
30 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptor;
31 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor;
32
33 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.sequencing.MetadataTableGenerator;
34 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.sequencing.MetadataSequenceGenerator;
35
36 /**
37  * An relational accessor.
38  *
39  * @author Guy Pelletier
40  * @since TopLink EJB 3.0 Reference Implementation
41  */

42 public abstract class NonRelationshipAccessor extends MetadataAccessor {
43     /**
44      * INTERNAL:
45      */

46     public NonRelationshipAccessor(MetadataAccessibleObject accessibleObject, MetadataProcessor processor, MetadataDescriptor descriptor) {
47         super(accessibleObject, processor, descriptor);
48     }
49     
50     /**
51      * INTERNAL:
52      */

53     public NonRelationshipAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor) {
54         super(accessibleObject, classAccessor);
55     }
56     
57     /**
58      * INTERNAL: (Overridden in XMLClassAccessor and XMLBasicAccessor)
59      * Process a @SequenceGenerator into a common metadata sequence generator.
60      */

61     protected void processSequenceGenerator() {
62         SequenceGenerator sequenceGenerator = getAnnotation(SequenceGenerator.class);
63         
64         if (sequenceGenerator != null) {
65             // Ask the common processor to process what we found.
66
processSequenceGenerator(new MetadataSequenceGenerator(sequenceGenerator, getJavaClassName()));
67         }
68     }
69     
70     /**
71      * INTERNAL:
72      * Process a MetadataSequenceGenerator and add it to the project.
73      */

74     protected void processSequenceGenerator(MetadataSequenceGenerator sequenceGenerator) {
75         // Check if the sequence generator name uses a reserved name.
76
String JavaDoc name = sequenceGenerator.getName();
77         
78          if (name.equals(MetadataConstants.DEFAULT_TABLE_GENERATOR)) {
79             m_validator.throwSequenceGeneratorUsingAReservedName(MetadataConstants.DEFAULT_TABLE_GENERATOR, sequenceGenerator.getLocation());
80         }
81             
82         // Conflicting means that they do not have all the same values.
83
if (m_project.hasConflictingSequenceGenerator(sequenceGenerator)) {
84             MetadataSequenceGenerator otherSequenceGenerator = m_project.getSequenceGenerator(name);
85             if (sequenceGenerator.loadedFromAnnotations() && otherSequenceGenerator.loadedFromXML()) {
86                 // WIP - should log a warning that we are ignoring this table generator.
87
return;
88             } else {
89                 m_validator.throwConflictingSequenceGeneratorsSpecified(name, sequenceGenerator.getLocation(), otherSequenceGenerator.getLocation());
90             }
91         }
92             
93         if (m_project.hasTableGenerator(name)) {
94             MetadataTableGenerator otherTableGenerator = m_project.getTableGenerator(name);
95             m_validator.throwConflictingSequenceAndTableGeneratorsSpecified(name, sequenceGenerator.getLocation(), otherTableGenerator.getLocation());
96         }
97             
98         for (MetadataTableGenerator otherTableGenerator : m_project.getTableGenerators()) {
99             if (otherTableGenerator.getPkColumnValue().equals(sequenceGenerator.getSequenceName())) {
100                 m_validator.throwConflictingSequenceNameAndTablePkColumnValueSpecified(sequenceGenerator.getSequenceName(), sequenceGenerator.getLocation(), otherTableGenerator.getLocation());
101             }
102         }
103         
104         m_project.addSequenceGenerator(sequenceGenerator);
105     }
106     
107     /**
108      * INTERNAL: (Overridden in XMLClassAccessor and XMLBasicAccessor)
109      * Process a @TableGenerator into a common metadata table generator.
110      */

111     protected void processTableGenerator() {
112         TableGenerator tableGenerator = getAnnotation(TableGenerator.class);
113         
114         if (tableGenerator != null) {
115             // Ask the common processor to process what we found.
116
processTableGenerator(new MetadataTableGenerator(tableGenerator, getJavaClassName()));
117         }
118     }
119     
120     /**
121      * INTERNAL:
122      * Process a MetadataTableGenerator and add it to the project.
123      */

124     protected void processTableGenerator(MetadataTableGenerator tableGenerator) {
125         // Check if the table generator name uses a reserved name.
126
String JavaDoc name = tableGenerator.getName();
127         
128         if (name.equals(MetadataConstants.DEFAULT_SEQUENCE_GENERATOR)) {
129             m_validator.throwTableGeneratorUsingAReservedName(MetadataConstants.DEFAULT_SEQUENCE_GENERATOR, tableGenerator.getLocation());
130         }
131
132         // Conflicting means that they do not have all the same values.
133
if (m_project.hasConflictingTableGenerator(tableGenerator)) {
134             MetadataTableGenerator otherTableGenerator = m_project.getTableGenerator(name);
135             if (tableGenerator.loadedFromAnnotations() && otherTableGenerator.loadedFromXML()) {
136                 // WIP - should log a warning that we are ignoring this table generator.
137
return;
138             } else {
139                 m_validator.throwConflictingTableGeneratorsSpecified(name, tableGenerator.getLocation(), otherTableGenerator.getLocation());
140             }
141         }
142         
143         if (m_project.hasSequenceGenerator(tableGenerator.getName())) {
144             MetadataSequenceGenerator otherSequenceGenerator = m_project.getSequenceGenerator(name);
145             m_validator.throwConflictingSequenceAndTableGeneratorsSpecified(name, otherSequenceGenerator.getLocation(), tableGenerator.getLocation());
146         }
147             
148         for (MetadataSequenceGenerator otherSequenceGenerator : m_project.getSequenceGenerators()) {
149             if (otherSequenceGenerator.getSequenceName().equals(tableGenerator.getPkColumnValue())) {
150                 m_validator.throwConflictingSequenceNameAndTablePkColumnValueSpecified(otherSequenceGenerator.getSequenceName(), otherSequenceGenerator.getLocation(), tableGenerator.getLocation());
151             }
152         }
153             
154         // Add the table generator to the descriptor metadata.
155
m_project.addTableGenerator(tableGenerator);
156     }
157 }
158
Popular Tags