KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > jpa > conf > MemberAnnotationProcessorFactory


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.jpa.conf;
21
22 import java.lang.reflect.AnnotatedElement JavaDoc;
23 import java.lang.reflect.Member JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Collection JavaDoc;
26
27 import javax.persistence.AssociationOverride;
28 import javax.persistence.AssociationOverrides;
29 import javax.persistence.AttributeOverride;
30 import javax.persistence.AttributeOverrides;
31 import javax.persistence.Basic;
32 import javax.persistence.Column;
33 import javax.persistence.EnumType;
34 import javax.persistence.Enumerated;
35 import javax.persistence.GeneratedValue;
36 import javax.persistence.JoinColumn;
37 import javax.persistence.JoinColumns;
38 import javax.persistence.JoinTable;
39 import javax.persistence.ManyToMany;
40 import javax.persistence.ManyToOne;
41 import javax.persistence.MapKey;
42 import javax.persistence.OneToMany;
43 import javax.persistence.OneToOne;
44 import javax.persistence.OrderBy;
45 import javax.persistence.Temporal;
46 import javax.persistence.TemporalType;
47
48 import org.apache.cayenne.jpa.map.JpaAssociationOverride;
49 import org.apache.cayenne.jpa.map.JpaAttribute;
50 import org.apache.cayenne.jpa.map.JpaAttributeOverride;
51 import org.apache.cayenne.jpa.map.JpaBasic;
52 import org.apache.cayenne.jpa.map.JpaColumn;
53 import org.apache.cayenne.jpa.map.JpaEmbedded;
54 import org.apache.cayenne.jpa.map.JpaEmbeddedId;
55 import org.apache.cayenne.jpa.map.JpaEntity;
56 import org.apache.cayenne.jpa.map.JpaGeneratedValue;
57 import org.apache.cayenne.jpa.map.JpaId;
58 import org.apache.cayenne.jpa.map.JpaJoinColumn;
59 import org.apache.cayenne.jpa.map.JpaJoinTable;
60 import org.apache.cayenne.jpa.map.JpaManagedClass;
61 import org.apache.cayenne.jpa.map.JpaManyToMany;
62 import org.apache.cayenne.jpa.map.JpaManyToOne;
63 import org.apache.cayenne.jpa.map.JpaOneToMany;
64 import org.apache.cayenne.jpa.map.JpaOneToOne;
65 import org.apache.cayenne.jpa.map.JpaTransient;
66 import org.apache.cayenne.jpa.map.JpaVersion;
67
68 /**
69  * A factory of member annotation processors.
70  *
71  * @author Andrus Adamchik
72  */

73 class MemberAnnotationProcessorFactory extends AnnotationProcessorFactory {
74
75     // superclass of the top-level member annotations
76
abstract static class L1Processor implements AnnotationProcessor {
77
78         public void onStartElement(
79                 AnnotatedElement JavaDoc element,
80                 AnnotationProcessorStack context) {
81
82             Object JavaDoc parent = context.peek();
83
84             if (parent instanceof JpaManagedClass) {
85                 onManagedClass((JpaManagedClass) parent, element, context);
86             }
87             else if (parent instanceof JpaAttribute) {
88                 onAttribute((JpaAttribute) parent, element, context);
89             }
90             else {
91                 recordUnsupportedAnnotation(element, context);
92             }
93         }
94
95         /**
96          * Does nothing by default. Any elements that push themselves on stack in the
97          * start method, must pop the stack here.
98          */

99         public void onFinishElement(
100                 AnnotatedElement JavaDoc element,
101                 AnnotationProcessorStack context) {
102         }
103
104         void onManagedClass(
105                 JpaManagedClass managedClass,
106                 AnnotatedElement JavaDoc element,
107                 AnnotationProcessorStack context) {
108             recordUnsupportedAnnotation(element, context);
109         }
110
111         void onAttribute(
112                 JpaAttribute attribute,
113                 AnnotatedElement JavaDoc element,
114                 AnnotationProcessorStack context) {
115             recordUnsupportedAnnotation(element, context);
116         }
117
118         void recordUnsupportedAnnotation(
119                 AnnotatedElement JavaDoc element,
120                 AnnotationProcessorStack context) {
121             context.recordConflict(element, AnnotationProcessorFactory
122                     .annotationClass(getClass()), "Unsupported in this context");
123         }
124     }
125
126     // superclass of the second-level member annotations
127
abstract static class L2Processor implements AnnotationProcessor {
128
129         public void onStartElement(
130                 AnnotatedElement JavaDoc element,
131                 AnnotationProcessorStack context) {
132
133             JpaAttribute attribute = null;
134
135             Object JavaDoc parent = context.peek();
136             if (parent instanceof JpaAttribute) {
137                 attribute = (JpaAttribute) parent;
138             }
139             else {
140                 attribute = findOrCreateAttribute(element, parent, context);
141             }
142
143             if (parent != null) {
144                 onAttribute(attribute, element, context);
145             }
146             else {
147                 recordUnsupportedAnnotation(element, context);
148             }
149         }
150
151         JpaAttribute findOrCreateAttribute(
152                 AnnotatedElement JavaDoc element,
153                 Object JavaDoc parent,
154                 AnnotationProcessorStack context) {
155
156             JpaBasic basic = null;
157
158             if (parent instanceof JpaManagedClass) {
159                 JpaManagedClass managedClass = (JpaManagedClass) parent;
160                 String JavaDoc name = ((Member JavaDoc) element).getName();
161                 basic = managedClass.getAttributes().getBasicAttribute(name);
162                 if (basic == null) {
163                     basic = new JpaBasic();
164
165                     // do push/pop as the context does some required injection
166
context.push(basic);
167                     context.pop();
168
169                     managedClass.getAttributes().getBasicAttributes().add(basic);
170                 }
171             }
172
173             return basic;
174         }
175
176         /**
177          * Does nothing by default. Any elements that push themselves on stack in the
178          * start method, must pop the stack here.
179          */

180         public void onFinishElement(
181                 AnnotatedElement JavaDoc element,
182                 AnnotationProcessorStack context) {
183         }
184
185         void onAttribute(
186                 JpaAttribute attribute,
187                 AnnotatedElement JavaDoc element,
188                 AnnotationProcessorStack context) {
189             recordUnsupportedAnnotation(element, context);
190         }
191
192         void recordUnsupportedAnnotation(
193                 AnnotatedElement JavaDoc element,
194                 AnnotationProcessorStack context) {
195             context.recordConflict(element, AnnotationProcessorFactory
196                     .annotationClass(getClass()), "Unsupported in this context");
197         }
198     }
199
200     static final class AssociationOverrideProcessor extends L1Processor {
201
202         @Override JavaDoc
203         void onManagedClass(
204                 JpaManagedClass managedClass,
205                 AnnotatedElement JavaDoc element,
206                 AnnotationProcessorStack context) {
207
208             if (managedClass instanceof JpaEntity) {
209                 JpaAssociationOverride override = new JpaAssociationOverride(element
210                         .getAnnotation(AssociationOverride.class));
211                 ((JpaEntity) managedClass).getAssociationOverrides().add(override);
212             }
213             else {
214                 super.onManagedClass(managedClass, element, context);
215             }
216         }
217     }
218
219     static final class AssociationOverridesProcessor extends L1Processor {
220
221         @Override JavaDoc
222         void onManagedClass(
223                 JpaManagedClass managedClass,
224                 AnnotatedElement JavaDoc element,
225                 AnnotationProcessorStack context) {
226
227             if (managedClass instanceof JpaEntity) {
228                 AssociationOverrides overrides = element
229                         .getAnnotation(AssociationOverrides.class);
230                 for (AssociationOverride overrideAnnotation : overrides.value()) {
231                     JpaAssociationOverride override = new JpaAssociationOverride(
232                             overrideAnnotation);
233                     ((JpaEntity) managedClass).getAssociationOverrides().add(override);
234                 }
235             }
236             else {
237                 super.onManagedClass(managedClass, element, context);
238             }
239         }
240     }
241
242     static final class AttributeOverrideProcessor extends L1Processor {
243
244         @Override JavaDoc
245         void onAttribute(
246                 JpaAttribute attribute,
247                 AnnotatedElement JavaDoc element,
248                 AnnotationProcessorStack context) {
249
250             if (attribute instanceof JpaEmbeddedId) {
251                 JpaAttributeOverride override = new JpaAttributeOverride(element
252                         .getAnnotation(AttributeOverride.class));
253                 ((JpaEmbeddedId) attribute).getAttributeOverrides().add(override);
254             }
255             else {
256                 super.onAttribute(attribute, element, context);
257             }
258         }
259     }
260
261     static final class AttributeOverridesProcessor extends L1Processor {
262
263         @Override JavaDoc
264         void onAttribute(
265                 JpaAttribute attribute,
266                 AnnotatedElement JavaDoc element,
267                 AnnotationProcessorStack context) {
268
269             if (attribute instanceof JpaEmbeddedId) {
270                 AttributeOverrides overrides = element
271                         .getAnnotation(AttributeOverrides.class);
272
273                 for (AttributeOverride overrideAnnotation : overrides.value()) {
274                     JpaAttributeOverride override = new JpaAttributeOverride(
275                             overrideAnnotation);
276                     ((JpaEmbeddedId) attribute).getAttributeOverrides().add(override);
277                 }
278             }
279             else {
280                 super.onAttribute(attribute, element, context);
281             }
282         }
283     }
284
285     static final class BasicProcessor extends L1Processor {
286
287         @Override JavaDoc
288         void onManagedClass(
289                 JpaManagedClass managedClass,
290                 AnnotatedElement JavaDoc element,
291                 AnnotationProcessorStack context) {
292             JpaBasic attribute = new JpaBasic(element.getAnnotation(Basic.class));
293             managedClass.getAttributes().getBasicAttributes().add(attribute);
294             context.push(attribute);
295         }
296
297         @Override JavaDoc
298         void onAttribute(
299                 JpaAttribute attribute,
300                 AnnotatedElement JavaDoc element,
301                 AnnotationProcessorStack context) {
302             if (!(attribute instanceof JpaBasic)) {
303                 super.onAttribute(attribute, element, context);
304             }
305         }
306
307         @Override JavaDoc
308         public void onFinishElement(
309                 AnnotatedElement JavaDoc element,
310                 AnnotationProcessorStack context) {
311
312             Object JavaDoc pop = context.pop();
313             if (!(pop instanceof JpaBasic)) {
314                 context.push(pop);
315             }
316         }
317     }
318
319     static final class ColumnProcessor extends L2Processor {
320
321         @Override JavaDoc
322         void onAttribute(
323                 JpaAttribute attribute,
324                 AnnotatedElement JavaDoc element,
325                 AnnotationProcessorStack context) {
326
327             JpaColumn column = new JpaColumn(element.getAnnotation(Column.class));
328
329             if (attribute instanceof JpaBasic) {
330                 ((JpaBasic) attribute).setColumn(column);
331             }
332             else if (attribute instanceof JpaVersion) {
333                 ((JpaVersion) attribute).setColumn(column);
334             }
335             else if (attribute instanceof JpaId) {
336                 ((JpaId) attribute).setColumn(column);
337             }
338             else {
339                 super.onAttribute(attribute, element, context);
340             }
341         }
342     }
343
344     static final class EmbeddedProcessor extends L1Processor {
345
346         @Override JavaDoc
347         void onManagedClass(
348                 JpaManagedClass managedClass,
349                 AnnotatedElement JavaDoc element,
350                 AnnotationProcessorStack context) {
351             JpaEmbedded attribute = new JpaEmbedded();
352             managedClass.getAttributes().getEmbeddedAttributes().add(attribute);
353             context.push(attribute);
354         }
355
356         @Override JavaDoc
357         void onAttribute(
358                 JpaAttribute attribute,
359                 AnnotatedElement JavaDoc element,
360                 AnnotationProcessorStack context) {
361
362             if (!(attribute instanceof JpaEmbedded)) {
363                 super.onAttribute(attribute, element, context);
364             }
365         }
366
367         @Override JavaDoc
368         public void onFinishElement(
369                 AnnotatedElement JavaDoc element,
370                 AnnotationProcessorStack context) {
371
372             Object JavaDoc pop = context.pop();
373             if (!(pop instanceof JpaEmbedded)) {
374                 context.push(pop);
375             }
376         }
377     }
378
379     static final class EmbeddedIdProcessor extends L1Processor {
380
381         @Override JavaDoc
382         void onManagedClass(
383                 JpaManagedClass managedClass,
384                 AnnotatedElement JavaDoc element,
385                 AnnotationProcessorStack context) {
386             JpaEmbeddedId id = new JpaEmbeddedId();
387             managedClass.getAttributes().setEmbeddedId(id);
388             context.push(id);
389         }
390
391         @Override JavaDoc
392         void onAttribute(
393                 JpaAttribute attribute,
394                 AnnotatedElement JavaDoc element,
395                 AnnotationProcessorStack context) {
396             if (attribute instanceof JpaEmbeddedId) {
397                 // was created implictly by another annotation
398
}
399             else {
400                 super.onAttribute(attribute, element, context);
401             }
402         }
403
404         @Override JavaDoc
405         public void onFinishElement(
406                 AnnotatedElement JavaDoc element,
407                 AnnotationProcessorStack context) {
408
409             Object JavaDoc pop = context.pop();
410             if (!(pop instanceof JpaEmbeddedId)) {
411                 context.push(pop);
412             }
413         }
414     }
415
416     static final class EnumeratedProcessor extends L2Processor {
417
418         @Override JavaDoc
419         void onAttribute(
420                 JpaAttribute attribute,
421                 AnnotatedElement JavaDoc element,
422                 AnnotationProcessorStack context) {
423
424             if (attribute instanceof JpaBasic) {
425                 EnumType enumType = element.getAnnotation(Enumerated.class).value();
426                 ((JpaBasic) attribute).setEnumerated(enumType);
427             }
428             else {
429                 super.onAttribute(attribute, element, context);
430             }
431         }
432     }
433
434     static final class GeneratedValueProcessor extends L2Processor {
435
436         @Override JavaDoc
437         void onAttribute(
438                 JpaAttribute attribute,
439                 AnnotatedElement JavaDoc element,
440                 AnnotationProcessorStack context) {
441
442             // can only attach to id
443
if (attribute instanceof JpaId) {
444                 JpaGeneratedValue generated = new JpaGeneratedValue(element
445                         .getAnnotation(GeneratedValue.class));
446                 ((JpaId) attribute).setGeneratedValue(generated);
447             }
448             else {
449                 super.onAttribute(attribute, element, context);
450             }
451         }
452     }
453
454     static final class IdProcessor extends L1Processor {
455
456         @Override JavaDoc
457         void onManagedClass(
458                 JpaManagedClass managedClass,
459                 AnnotatedElement JavaDoc element,
460                 AnnotationProcessorStack context) {
461             JpaId attribute = new JpaId();
462             managedClass.getAttributes().getIds().add(attribute);
463             context.push(attribute);
464         }
465
466         @Override JavaDoc
467         void onAttribute(
468                 JpaAttribute attribute,
469                 AnnotatedElement JavaDoc element,
470                 AnnotationProcessorStack context) {
471             if (attribute instanceof JpaId) {
472                 // id was created implictly by another annotation
473
}
474             else {
475                 super.onAttribute(attribute, element, context);
476             }
477         }
478
479         @Override JavaDoc
480         public void onFinishElement(
481                 AnnotatedElement JavaDoc element,
482                 AnnotationProcessorStack context) {
483
484             Object JavaDoc pop = context.pop();
485             if (!(pop instanceof JpaId)) {
486                 context.push(pop);
487             }
488         }
489     }
490
491     static final class JoinColumnProcessor extends L2Processor {
492
493         @Override JavaDoc
494         void onAttribute(
495                 JpaAttribute attribute,
496                 AnnotatedElement JavaDoc element,
497                 AnnotationProcessorStack context) {
498
499             JpaJoinColumn joinColumn = new JpaJoinColumn(element
500                     .getAnnotation(JoinColumn.class));
501
502             if (attribute instanceof JpaOneToMany) {
503                 ((JpaOneToMany) attribute).getJoinColumns().add(joinColumn);
504             }
505             else if (attribute instanceof JpaOneToOne) {
506                 ((JpaOneToOne) attribute).getJoinColumns().add(joinColumn);
507             }
508             else if (attribute instanceof JpaManyToOne) {
509                 ((JpaManyToOne) attribute).getJoinColumns().add(joinColumn);
510             }
511             else {
512                 super.onAttribute(attribute, element, context);
513             }
514         }
515     }
516
517     static final class JoinColumnsProcessor extends L2Processor {
518
519         @Override JavaDoc
520         void onAttribute(
521                 JpaAttribute attribute,
522                 AnnotatedElement JavaDoc element,
523                 AnnotationProcessorStack context) {
524
525             JoinColumn[] annotations = element.getAnnotation(JoinColumns.class).value();
526             Collection JavaDoc<JpaJoinColumn> joinColumns = new ArrayList JavaDoc<JpaJoinColumn>(
527                     annotations.length);
528             for (int i = 0; i < annotations.length; i++) {
529                 joinColumns.add(new JpaJoinColumn(annotations[i]));
530             }
531
532             if (attribute instanceof JpaOneToMany) {
533                 ((JpaOneToMany) attribute).getJoinColumns().addAll(joinColumns);
534             }
535             else if (attribute instanceof JpaOneToOne) {
536                 ((JpaOneToOne) attribute).getJoinColumns().addAll(joinColumns);
537             }
538             else if (attribute instanceof JpaManyToOne) {
539                 ((JpaManyToOne) attribute).getJoinColumns().addAll(joinColumns);
540             }
541             else {
542                 super.onAttribute(attribute, element, context);
543             }
544         }
545     }
546
547     static final class JoinTableProcessor extends L2Processor {
548
549         @Override JavaDoc
550         void onAttribute(
551                 JpaAttribute attribute,
552                 AnnotatedElement JavaDoc element,
553                 AnnotationProcessorStack context) {
554
555             JpaJoinTable joinTable = new JpaJoinTable(element
556                     .getAnnotation(JoinTable.class));
557
558             if (attribute instanceof JpaOneToMany) {
559                 ((JpaOneToMany) attribute).setJoinTable(joinTable);
560             }
561             else if (attribute instanceof JpaOneToOne) {
562                 ((JpaOneToOne) attribute).setJoinTable(joinTable);
563             }
564             else if (attribute instanceof JpaManyToOne) {
565                 ((JpaManyToOne) attribute).setJoinTable(joinTable);
566             }
567             else if (attribute instanceof JpaManyToMany) {
568                 ((JpaManyToOne) attribute).setJoinTable(joinTable);
569             }
570             else {
571                 super.onAttribute(attribute, element, context);
572             }
573         }
574     }
575
576     static final class LobProcessor extends L2Processor {
577
578         @Override JavaDoc
579         void onAttribute(
580                 JpaAttribute attribute,
581                 AnnotatedElement JavaDoc element,
582                 AnnotationProcessorStack context) {
583
584             if (attribute instanceof JpaBasic) {
585                 ((JpaBasic) attribute).setLob(true);
586             }
587             else {
588                 super.onAttribute(attribute, element, context);
589             }
590         }
591     }
592
593     static final class ManyToManyProcessor extends L1Processor {
594
595         @Override JavaDoc
596         void onManagedClass(
597                 JpaManagedClass managedClass,
598                 AnnotatedElement JavaDoc element,
599                 AnnotationProcessorStack context) {
600             JpaManyToMany attribute = new JpaManyToMany(element
601                     .getAnnotation(ManyToMany.class));
602             managedClass.getAttributes().getManyToManyRelationships().add(attribute);
603             context.push(attribute);
604         }
605
606         @Override JavaDoc
607         void onAttribute(
608                 JpaAttribute attribute,
609                 AnnotatedElement JavaDoc element,
610                 AnnotationProcessorStack context) {
611             if (!(attribute instanceof JpaManyToMany)) {
612                 super.onAttribute(attribute, element, context);
613             }
614         }
615
616         @Override JavaDoc
617         public void onFinishElement(
618                 AnnotatedElement JavaDoc element,
619                 AnnotationProcessorStack context) {
620
621             Object JavaDoc pop = context.pop();
622             if (!(pop instanceof JpaManyToMany)) {
623                 context.push(pop);
624             }
625         }
626     }
627
628     static final class ManyToOneProcessor extends L1Processor {
629
630         @Override JavaDoc
631         void onManagedClass(
632                 JpaManagedClass managedClass,
633                 AnnotatedElement JavaDoc element,
634                 AnnotationProcessorStack context) {
635             JpaManyToOne attribute = new JpaManyToOne(element
636                     .getAnnotation(ManyToOne.class));
637             managedClass.getAttributes().getManyToOneRelationships().add(attribute);
638             context.push(attribute);
639         }
640
641         @Override JavaDoc
642         void onAttribute(
643                 JpaAttribute attribute,
644                 AnnotatedElement JavaDoc element,
645                 AnnotationProcessorStack context) {
646             if (!(attribute instanceof JpaManyToMany)) {
647                 super.onAttribute(attribute, element, context);
648             }
649         }
650
651         @Override JavaDoc
652         public void onFinishElement(
653                 AnnotatedElement JavaDoc element,
654                 AnnotationProcessorStack context) {
655
656             Object JavaDoc pop = context.pop();
657             if (!(pop instanceof JpaManyToOne)) {
658                 context.push(pop);
659             }
660         }
661     }
662
663     static final class MapKeyProcessor extends L2Processor {
664
665         @Override JavaDoc
666         void onAttribute(
667                 JpaAttribute attribute,
668                 AnnotatedElement JavaDoc element,
669                 AnnotationProcessorStack context) {
670
671             String JavaDoc key = element.getAnnotation(MapKey.class).name();
672             if (attribute instanceof JpaOneToMany) {
673                 ((JpaOneToMany) attribute).setMapKey(key);
674             }
675             else if (attribute instanceof JpaManyToMany) {
676                 ((JpaManyToMany) attribute).setMapKey(key);
677             }
678             else {
679                 super.onAttribute(attribute, element, context);
680             }
681         }
682     }
683
684     static final class OneToManyProcessor extends L1Processor {
685
686         @Override JavaDoc
687         void onManagedClass(
688                 JpaManagedClass managedClass,
689                 AnnotatedElement JavaDoc element,
690                 AnnotationProcessorStack context) {
691             JpaOneToMany attribute = new JpaOneToMany(element
692                     .getAnnotation(OneToMany.class));
693             managedClass.getAttributes().getOneToManyRelationships().add(attribute);
694             context.push(attribute);
695         }
696
697         @Override JavaDoc
698         void onAttribute(
699                 JpaAttribute attribute,
700                 AnnotatedElement JavaDoc element,
701                 AnnotationProcessorStack context) {
702             if (!(attribute instanceof JpaOneToMany)) {
703                 super.onAttribute(attribute, element, context);
704             }
705         }
706
707         @Override JavaDoc
708         public void onFinishElement(
709                 AnnotatedElement JavaDoc element,
710                 AnnotationProcessorStack context) {
711
712             Object JavaDoc pop = context.pop();
713             if (!(pop instanceof JpaOneToMany)) {
714                 context.push(pop);
715             }
716         }
717     }
718
719     static final class OneToOneProcessor extends L1Processor {
720
721         @Override JavaDoc
722         void onManagedClass(
723                 JpaManagedClass managedClass,
724                 AnnotatedElement JavaDoc element,
725                 AnnotationProcessorStack context) {
726             JpaOneToOne attribute = new JpaOneToOne(element.getAnnotation(OneToOne.class));
727             managedClass.getAttributes().getOneToOneRelationships().add(attribute);
728             context.push(attribute);
729         }
730
731         @Override JavaDoc
732         void onAttribute(
733                 JpaAttribute attribute,
734                 AnnotatedElement JavaDoc element,
735                 AnnotationProcessorStack context) {
736             if (!(attribute instanceof JpaOneToOne)) {
737                 super.onAttribute(attribute, element, context);
738             }
739         }
740
741         @Override JavaDoc
742         public void onFinishElement(
743                 AnnotatedElement JavaDoc element,
744                 AnnotationProcessorStack context) {
745
746             Object JavaDoc pop = context.pop();
747             if (!(pop instanceof JpaOneToOne)) {
748                 context.push(pop);
749             }
750         }
751     }
752
753     static final class OrderByProcessor extends L2Processor {
754
755         @Override JavaDoc
756         void onAttribute(
757                 JpaAttribute attribute,
758                 AnnotatedElement JavaDoc element,
759                 AnnotationProcessorStack context) {
760
761             String JavaDoc order = element.getAnnotation(OrderBy.class).value();
762             if (attribute instanceof JpaOneToMany) {
763                 ((JpaOneToMany) attribute).setOrderBy(order);
764             }
765             else if (attribute instanceof JpaManyToMany) {
766                 ((JpaManyToMany) attribute).setOrderBy(order);
767             }
768             else {
769                 super.onAttribute(attribute, element, context);
770             }
771         }
772     }
773
774     static final class TemporalProcessor extends L2Processor {
775
776         @Override JavaDoc
777         void onAttribute(
778                 JpaAttribute attribute,
779                 AnnotatedElement JavaDoc element,
780                 AnnotationProcessorStack context) {
781
782             TemporalType value = element.getAnnotation(Temporal.class).value();
783
784             if (attribute instanceof JpaBasic) {
785                 ((JpaBasic) attribute).setTemporal(value);
786             }
787             // according to the spec, only @Basic is compatibel with @Temporal, however
788
// @Id and @Version also support it in the schema
789
else if (attribute instanceof JpaId) {
790                 ((JpaId) attribute).setTemporal(value);
791             }
792             else if (attribute instanceof JpaVersion) {
793                 ((JpaVersion) attribute).setTemporal(value);
794             }
795             else {
796                 super.onAttribute(attribute, element, context);
797             }
798         }
799     }
800
801     static final class TransientProcessor extends L1Processor {
802
803         @Override JavaDoc
804         void onManagedClass(
805                 JpaManagedClass managedClass,
806                 AnnotatedElement JavaDoc element,
807                 AnnotationProcessorStack context) {
808             JpaTransient attribute = new JpaTransient();
809             managedClass.getAttributes().getTransientAttributes().add(attribute);
810             context.push(attribute);
811         }
812
813         @Override JavaDoc
814         void onAttribute(
815                 JpaAttribute attribute,
816                 AnnotatedElement JavaDoc element,
817                 AnnotationProcessorStack context) {
818
819             if (!(attribute instanceof JpaTransient)) {
820                 super.onAttribute(attribute, element, context);
821             }
822         }
823
824         @Override JavaDoc
825         public void onFinishElement(
826                 AnnotatedElement JavaDoc element,
827                 AnnotationProcessorStack context) {
828
829             Object JavaDoc pop = context.pop();
830             if (!(pop instanceof JpaTransient)) {
831                 context.push(pop);
832             }
833         }
834     }
835
836     static final class VersionProcessor extends L1Processor {
837
838         @Override JavaDoc
839         void onManagedClass(
840                 JpaManagedClass managedClass,
841                 AnnotatedElement JavaDoc element,
842                 AnnotationProcessorStack context) {
843             JpaVersion attribute = new JpaVersion();
844             managedClass.getAttributes().getVersionAttributes().add(attribute);
845             context.push(attribute);
846         }
847
848         @Override JavaDoc
849         void onAttribute(
850                 JpaAttribute attribute,
851                 AnnotatedElement JavaDoc element,
852                 AnnotationProcessorStack context) {
853
854             if (!(attribute instanceof JpaVersion)) {
855                 super.onAttribute(attribute, element, context);
856             }
857         }
858
859         @Override JavaDoc
860         public void onFinishElement(
861                 AnnotatedElement JavaDoc element,
862                 AnnotationProcessorStack context) {
863
864             Object JavaDoc pop = context.pop();
865             if (!(pop instanceof JpaVersion)) {
866                 context.push(pop);
867             }
868         }
869     }
870 }
871
Popular Tags