Author: aadamchik
Date: Tue Aug  1 22:21:26 2006
New Revision: 427897

URL: http://svn.apache.org/viewvc?rev=427897&view=rev
Log:
fixing more annotation processors

Modified:
    
incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoader.java
    
incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java

Modified: 
incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoader.java
URL: 
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoader.java?rev=427897&r1=427896&r2=427897&view=diff
==============================================================================
--- 
incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoader.java
 (original)
+++ 
incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoader.java
 Tue Aug  1 22:21:26 2006
@@ -17,7 +17,6 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.jpa.conf;
 
 import java.lang.annotation.Annotation;
@@ -238,6 +237,10 @@
         // annotations...
     }
 
+    /**
+     * Returns a collection of methods that match an 'entity callback" 
pattern, i.e. "void
+     * <METHOD>()".
+     */
     protected Collection<Method> getEntityCallbacks(Class managedClass) {
 
         Collection<Method> callbacks = new ArrayList<Method>(3);

Modified: 
incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java?rev=427897&r1=427896&r2=427897&view=diff
==============================================================================
--- 
incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java
 (original)
+++ 
incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java
 Tue Aug  1 22:21:26 2006
@@ -23,19 +23,32 @@
 
 import javax.persistence.AttributeOverride;
 import javax.persistence.AttributeOverrides;
+import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
 import javax.persistence.GeneratedValue;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
 import javax.persistence.Temporal;
 
 import org.apache.cayenne.jpa.map.JpaAbstractEntity;
 import org.apache.cayenne.jpa.map.JpaAttributeOverride;
 import org.apache.cayenne.jpa.map.JpaAttributes;
+import org.apache.cayenne.jpa.map.JpaBasic;
 import org.apache.cayenne.jpa.map.JpaColumn;
 import org.apache.cayenne.jpa.map.JpaEmbeddedId;
 import org.apache.cayenne.jpa.map.JpaEntity;
 import org.apache.cayenne.jpa.map.JpaGeneratedValue;
 import org.apache.cayenne.jpa.map.JpaId;
+import org.apache.cayenne.jpa.map.JpaManagedClass;
+import org.apache.cayenne.jpa.map.JpaManyToMany;
+import org.apache.cayenne.jpa.map.JpaManyToOne;
+import org.apache.cayenne.jpa.map.JpaOneToMany;
+import org.apache.cayenne.jpa.map.JpaOneToOne;
+import org.apache.cayenne.jpa.map.JpaTransient;
+import org.apache.cayenne.jpa.map.JpaVersion;
 
 /**
  * A factory of member annotation processors.
@@ -44,6 +57,66 @@
  */
 class MemberAnnotationProcessorFactory extends AnnotationProcessorFactory {
 
+    abstract static class AbstractChildProcessor implements 
AnnotationProcessor {
+
+        public void onStartElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            Object parent = context.peek();
+
+            if (parent instanceof JpaId) {
+                onId((JpaId) parent, element, context);
+            }
+            else if (parent instanceof JpaEmbeddedId) {
+                onEmbeddedId((JpaEmbeddedId) parent, element, context);
+            }
+            else if (parent instanceof JpaManagedClass) {
+                JpaManagedClass managedClass = (JpaManagedClass) parent;
+                if (managedClass.getAttributes() == null) {
+                    managedClass.setAttributes(new JpaAttributes());
+                }
+
+                onAttributes(managedClass.getAttributes(), element, context);
+            }
+        }
+
+        /**
+         * Does nothing by default. Any elements that push themselves on stack 
in the
+         * start method, must pop the stack here.
+         */
+        public void onFinishElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+        }
+
+        void onEmbeddedId(
+                JpaEmbeddedId id,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            recordUnsupportedAnnotation(element, context);
+        }
+
+        void onId(JpaId id, AnnotatedElement element, AnnotationProcessorStack 
context) {
+            recordUnsupportedAnnotation(element, context);
+        }
+
+        void onAttributes(
+                JpaAttributes attributes,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            recordUnsupportedAnnotation(element, context);
+        }
+
+        void recordUnsupportedAnnotation(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            context.recordConflict(element, AnnotationProcessorFactory
+                    .annotationClass(getClass()), "Unsupported in this place");
+        }
+    }
+
     static final class FlushModeProcessor implements AnnotationProcessor {
 
         public void onStartElement(
@@ -121,61 +194,6 @@
         }
     }
 
-    abstract static class AbstractChildProcessor implements 
AnnotationProcessor {
-
-        public void onStartElement(
-                AnnotatedElement element,
-                AnnotationProcessorStack context) {
-
-            Object parent = context.peek();
-
-            if (parent instanceof JpaId) {
-                onId((JpaId) parent, element, context);
-            }
-            else if (parent instanceof JpaEmbeddedId) {
-                onEmbeddedId((JpaEmbeddedId) parent, element, context);
-            }
-            // else if (parent instanceof JpaEmbeddable) {
-            // JpaEmbeddable embeddable = (JpaEmbeddable) parent;
-            //
-            // // embeddable attribute implied...
-            // JpaAttributes attributes = new JpaAttributes();
-            // // embeddable.getEmbeddableAttributes().add(attribute);
-            // context.push(attributes);
-            //
-            //                // onEmbeddableAttribute(attributes, element, 
context);
-            //            }
-        }
-
-        public void onFinishElement(
-                AnnotatedElement element,
-                AnnotationProcessorStack context) {
-
-            Object stackTop = context.peek();
-            if (stackTop instanceof JpaAttributes) {
-                context.pop();
-            }
-        }
-
-        void onEmbeddedId(
-                JpaEmbeddedId id,
-                AnnotatedElement element,
-                AnnotationProcessorStack context) {
-            recordUnsupportedAnnotation(element, context);
-        }
-
-        void onId(JpaId id, AnnotatedElement element, AnnotationProcessorStack 
context) {
-            recordUnsupportedAnnotation(element, context);
-        }
-
-        void recordUnsupportedAnnotation(
-                AnnotatedElement element,
-                AnnotationProcessorStack context) {
-            context.recordConflict(element, AnnotationProcessorFactory
-                    .annotationClass(getClass()), "Unsupported in this place");
-        }
-    }
-
     // ====== Concrete processor classes ========
 
     static final class AttributeOverrideProcessor extends 
AbstractChildProcessor {
@@ -232,21 +250,23 @@
 
     static final class BasicProcessor extends AbstractChildProcessor {
 
-        // @Override
-        // void onAttribute(
-        // JpaAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // attribute.setBasic(new 
JpaBasic(element.getAnnotation(Basic.class)));
-        // }
+        @Override
+        void onAttributes(
+                JpaAttributes attributes,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            JpaBasic attribute = new 
JpaBasic(element.getAnnotation(Basic.class));
+            attributes.getBasicAttributes().add(attribute);
+            context.push(attribute);
+        }
 
-//        @Override
-//        void onEmbeddableAttribute(
-//                JpaEmbeddableAttribute attribute,
-//                AnnotatedElement element,
-//                AnnotationProcessorStack context) {
-//            attribute.setBasic(new 
JpaBasic(element.getAnnotation(Basic.class)));
-//        }
+        @Override
+        public void onFinishElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            context.pop();
+        }
     }
 
     static final class ColumnProcessor extends AbstractChildProcessor {
@@ -260,14 +280,14 @@
         // attribute.setColumn(new JpaColumn(annotation));
         // }
 
-//        @Override
-//        void onEmbeddableAttribute(
-//                JpaEmbeddableAttribute attribute,
-//                AnnotatedElement element,
-//                AnnotationProcessorStack context) {
-//            Column annotation = element.getAnnotation(Column.class);
-//            attribute.setColumn(new JpaColumn(annotation));
-//        }
+        // @Override
+        // void onEmbeddableAttribute(
+        // JpaEmbeddableAttribute attribute,
+        // AnnotatedElement element,
+        // AnnotationProcessorStack context) {
+        // Column annotation = element.getAnnotation(Column.class);
+        // attribute.setColumn(new JpaColumn(annotation));
+        // }
 
         @Override
         void onId(JpaId id, AnnotatedElement element, AnnotationProcessorStack 
context) {
@@ -298,14 +318,14 @@
         // attribute.setEnumerated(annotation.value());
         // }
 
-//        @Override
-//        void onEmbeddableAttribute(
-//                JpaEmbeddableAttribute attribute,
-//                AnnotatedElement element,
-//                AnnotationProcessorStack context) {
-//            Enumerated annotation = element.getAnnotation(Enumerated.class);
-//            attribute.setEnumerated(annotation.value());
-//        }
+        // @Override
+        // void onEmbeddableAttribute(
+        // JpaEmbeddableAttribute attribute,
+        // AnnotatedElement element,
+        // AnnotationProcessorStack context) {
+        // Enumerated annotation = element.getAnnotation(Enumerated.class);
+        // attribute.setEnumerated(annotation.value());
+        // }
     }
 
     static final class GeneratedValueProcessor extends AbstractChildProcessor {
@@ -358,45 +378,51 @@
 
     static final class LobProcessor extends AbstractChildProcessor {
 
-        // @Override
-        // void onAttribute(
-        // JpaAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // attribute.setLob(true);
-        // }
-
-//        @Override
-//        void onEmbeddableAttribute(
-//                JpaEmbeddableAttribute attribute,
-//                AnnotatedElement element,
-//                AnnotationProcessorStack context) {
-//            attribute.setLob(true);
-//        }
+     
     }
 
     static final class ManyToManyProcessor extends AbstractChildProcessor {
 
-        // @Override
-        // void onAttribute(
-        // JpaAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // ManyToMany annotation = element.getAnnotation(ManyToMany.class);
-        // attribute.setManyToMany(new JpaManyToMany(annotation));
-        // }
+        @Override
+        void onAttributes(
+                JpaAttributes attributes,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            JpaManyToMany attribute = new JpaManyToMany(element
+                    .getAnnotation(ManyToMany.class));
+            attributes.getManyToManyRelationships().add(attribute);
+            context.push(attribute);
+        }
+
+        @Override
+        public void onFinishElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            context.pop();
+        }
     }
 
     static final class ManyToOneProcessor extends AbstractChildProcessor {
 
-        // @Override
-        // void onAttribute(
-        // JpaAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // attribute.setManyToOne(new JpaManyToOne(element
-        // .getAnnotation(ManyToOne.class)));
-        // }
+        @Override
+        void onAttributes(
+                JpaAttributes attributes,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            JpaManyToOne attribute = new JpaManyToOne(element
+                    .getAnnotation(ManyToOne.class));
+            attributes.getManyToOneRelationships().add(attribute);
+            context.push(attribute);
+        }
+
+        @Override
+        public void onFinishElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            context.pop();
+        }
     }
 
     static final class MapKeyProcessor extends AbstractChildProcessor {
@@ -413,25 +439,45 @@
 
     static final class OneToManyProcessor extends AbstractChildProcessor {
 
-        // @Override
-        // void onAttribute(
-        // JpaAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // attribute.setOneToMany(new JpaOneToMany(element
-        // .getAnnotation(OneToMany.class)));
-        // }
+        @Override
+        void onAttributes(
+                JpaAttributes attributes,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            JpaOneToMany attribute = new JpaOneToMany(element
+                    .getAnnotation(OneToMany.class));
+            attributes.getOneToManyRelationships().add(attribute);
+            context.push(attribute);
+        }
+
+        @Override
+        public void onFinishElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            context.pop();
+        }
     }
 
     static final class OneToOneProcessor extends AbstractChildProcessor {
 
-        // @Override
-        // void onAttribute(
-        // JpaAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // attribute.setOneToOne(new 
JpaOneToOne(element.getAnnotation(OneToOne.class)));
-        // }
+        @Override
+        void onAttributes(
+                JpaAttributes attributes,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            JpaOneToOne attribute = new 
JpaOneToOne(element.getAnnotation(OneToOne.class));
+            attributes.getOneToOneRelationships().add(attribute);
+            context.push(attribute);
+        }
+
+        @Override
+        public void onFinishElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            context.pop();
+        }
     }
 
     static final class OrderByProcessor extends AbstractChildProcessor {
@@ -464,7 +510,7 @@
         // AnnotationProcessorStack context) {
         // Temporal annotation = element.getAnnotation(Temporal.class);
         // attribute.setTemporal(annotation.value());
-        //        }
+        // }
 
         @Override
         void onId(JpaId id, AnnotatedElement element, AnnotationProcessorStack 
context) {
@@ -475,23 +521,41 @@
 
     static final class TransientProcessor extends AbstractChildProcessor {
 
-        // @Override
-        // void onAttribute(
-        // JpaAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // attribute.setTransient(true);
-        // }
+        @Override
+        void onAttributes(
+                JpaAttributes attributes,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            JpaTransient attribute = new JpaTransient();
+            attributes.getTransientAttributes().add(attribute);
+            context.push(attribute);
+        }
+
+        @Override
+        public void onFinishElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            context.pop();
+        }
     }
 
     static final class VersionProcessor extends AbstractChildProcessor {
 
-        // @Override
-        // void onAttribute(
-        // JpaAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // attribute.setVersion(true);
-        // }
+        @Override
+        void onAttributes(
+                JpaAttributes attributes,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            JpaVersion attribute = new JpaVersion();
+            attributes.getVersionAttributes().add(attribute);
+            context.push(attribute);
+        }
+
+        @Override
+        public void onFinishElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            context.pop();
+        }
     }
 }


Reply via email to