aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alien11...@apache.org
Subject svn commit: r1758293 - in /aries/trunk/blueprint/blueprint-maven-plugin/src: main/java/org/apache/aries/blueprint/plugin/ main/java/org/apache/aries/blueprint/plugin/javax/ main/java/org/apache/aries/blueprint/plugin/model/ main/java/org/apache/aries/b...
Date Mon, 29 Aug 2016 19:19:21 GMT
Author: alien11689
Date: Mon Aug 29 19:19:20 2016
New Revision: 1758293

URL: http://svn.apache.org/viewvc?rev=1758293&view=rev
Log:
[ARIES-1602] Use @PersistenceContext and @PersistenceUnit annotations via spi handlers

Added:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/PersistenceContextHandler.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/PersistenceUnitHandler.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spi/FieldAnnotationHandler.java
      - copied, changed from r1758278, aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spi/MethodAnnotationHandler.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler
      - copied, changed from r1758278, aries/trunk/blueprint/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler
Modified:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/BlueprintConfigurationImpl.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Extensions.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/JavaxTransactionFactory.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spring/SpringTransactionalFactory.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/BlueprintConfigurationImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/BlueprintConfigurationImpl.java?rev=1758293&r1=1758292&r2=1758293&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/BlueprintConfigurationImpl.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/BlueprintConfigurationImpl.java
Mon Aug 29 19:19:20 2016
@@ -7,10 +7,9 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
-import static org.apache.aries.blueprint.plugin.Generator.NS_JPA2;
-
 public class BlueprintConfigurationImpl implements BlueprintConfiguration {
     public static final String NS_TX2 = "http://aries.apache.org/xmlns/transactions/v2.0.0";
+    public static final String NS_JPA2 = "http://aries.apache.org/xmlns/jpa/v2.0.0";
 
     private final Set<String> namespaces;
     private final Activation defaultActivation;

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Extensions.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Extensions.java?rev=1758293&r1=1758292&r2=1758293&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Extensions.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Extensions.java
Mon Aug 29 19:19:20 2016
@@ -22,6 +22,7 @@ import org.apache.aries.blueprint.plugin
 import org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler;
 import org.apache.aries.blueprint.plugin.spi.CustomDependencyAnnotationHandler;
 import org.apache.aries.blueprint.plugin.spi.CustomFactoryMethodAnnotationHandler;
+import org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler;
 import org.apache.aries.blueprint.plugin.spi.InjectLikeHandler;
 import org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler;
 import org.apache.aries.blueprint.plugin.spi.NamedLikeHandler;
@@ -42,6 +43,7 @@ public class Extensions {
     public static final List<CustomFactoryMethodAnnotationHandler<? extends Annotation>>
customFactoryMethodAnnotationHandlers = new ArrayList<>();
     public static final List<CustomDependencyAnnotationHandler<? extends Annotation>>
customDependencyAnnotationHandlers = new ArrayList<>();
     public static final List<MethodAnnotationHandler<? extends Annotation>> methodAnnotationHandlers
= new ArrayList<>();
+    public static final List<FieldAnnotationHandler<? extends Annotation>> fieldAnnotationHandlers
= new ArrayList<>();
 
     static {
         for (BeanFinder beanFinder : ServiceLoader.load(BeanFinder.class)) {
@@ -78,5 +80,9 @@ public class Extensions {
         for (MethodAnnotationHandler<? extends Annotation> methodAnnotationHandler
: ServiceLoader.load(MethodAnnotationHandler.class)) {
             methodAnnotationHandlers.add(methodAnnotationHandler);
         }
+
+        for (FieldAnnotationHandler<? extends Annotation> fieldAnnotationHandler :
ServiceLoader.load(FieldAnnotationHandler.class)) {
+            fieldAnnotationHandlers.add(fieldAnnotationHandler);
+        }
     }
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java?rev=1758293&r1=1758292&r2=1758293&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
Mon Aug 29 19:19:20 2016
@@ -28,21 +28,15 @@ import org.apache.aries.blueprint.plugin
 import org.apache.aries.blueprint.plugin.spi.BlueprintConfiguration;
 import org.apache.aries.blueprint.plugin.spi.XmlWriter;
 
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceUnit;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import java.io.OutputStream;
-import java.lang.reflect.Field;
-import java.util.List;
 import java.util.Map;
 
 public class Generator implements PropertyWriter, ArgumentWriter {
     private static final String NS_BLUEPRINT = "http://www.osgi.org/xmlns/blueprint/v1.0.0";
     private static final String NS_EXT = "http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0";
-    public static final String NS_JPA = "http://aries.apache.org/xmlns/jpa/v1.1.0";
-    public static final String NS_JPA2 = "http://aries.apache.org/xmlns/jpa/v2.0.0";
 
     private final Context context;
     private final BlueprintConfiguration blueprintConfiguration;
@@ -62,10 +56,6 @@ public class Generator implements Proper
             writeBlueprint();
             writer.writeCharacters("\n");
 
-            if (blueprintConfiguration.getNamespaces().contains(NS_JPA2) && isJpaUsed())
{
-                writer.writeEmptyElement(NS_JPA2, "enable");
-                writer.writeCharacters("\n");
-            }
             for (Bean bean : context.getBeans()) {
                 writeBeanStart(bean);
                 bean.writeArguments(this);
@@ -88,39 +78,15 @@ public class Generator implements Proper
         }
     }
 
-    private boolean isJpaUsed() {
-        boolean jpaUsed = false;
-        for (Bean bean : context.getBeans()) {
-            if (bean.persistenceFields.size() > 0) {
-                jpaUsed = true;
-            }
-        }
-        return jpaUsed;
-    }
-
     private void writeBlueprint() throws XMLStreamException {
         writer.writeStartElement("blueprint");
         writer.writeDefaultNamespace(NS_BLUEPRINT);
         writer.writeNamespace("ext", NS_EXT);
-        for (String namespace : blueprintConfiguration.getNamespaces()) {
-            String prefix = getPrefixForNamesapace(namespace);
-            writer.writeNamespace(prefix, namespace);
-        }
         if (blueprintConfiguration.getDefaultActivation() != null) {
             writer.writeAttribute("default-activation", blueprintConfiguration.getDefaultActivation().name().toLowerCase());
         }
     }
 
-    private String getPrefixForNamesapace(String namespace) {
-        if (namespace.contains("jpa")) {
-            return "jpa";
-        }
-        if (namespace.contains("transactions")) {
-            return "tx";
-        }
-        return "other";
-    }
-
     public void writeBeanStart(Bean bean) throws XMLStreamException {
         writer.writeStartElement("bean");
         writer.writeAttribute("id", bean.id);
@@ -144,9 +110,6 @@ public class Generator implements Proper
         for (XmlWriter xmlWriter : bean.beanContentWriters.values()) {
             xmlWriter.write(writer);
         }
-        if (blueprintConfiguration.getNamespaces().contains(NS_JPA)) {
-            writePersistenceFields(bean.persistenceFields);
-        }
     }
 
     private void writeFactory(ProducedBean bean) throws XMLStreamException {
@@ -154,31 +117,6 @@ public class Generator implements Proper
         writer.writeAttribute("factory-method", bean.factoryMethod);
     }
 
-    private void writePersistenceFields(List<Field> fields) throws XMLStreamException
{
-        for (Field field : fields) {
-            writePersistenceField(field);
-        }
-    }
-
-    private void writePersistenceField(Field field) throws XMLStreamException {
-        PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
-        if (persistenceContext != null) {
-            writer.writeCharacters("    ");
-            writer.writeEmptyElement("jpa", "context", NS_JPA);
-            writer.writeAttribute("unitname", persistenceContext.unitName());
-            writer.writeAttribute("property", field.getName());
-            writer.writeCharacters("\n");
-        }
-        PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
-        if (persistenceUnit != null) {
-            writer.writeCharacters("    ");
-            writer.writeEmptyElement("jpa", "unit", NS_JPA);
-            writer.writeAttribute("unitname", persistenceUnit.unitName());
-            writer.writeAttribute("property", field.getName());
-            writer.writeCharacters("\n");
-        }
-    }
-
     @Override
     public void writeProperty(Property property) {
         try {

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/JavaxTransactionFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/JavaxTransactionFactory.java?rev=1758293&r1=1758292&r2=1758293&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/JavaxTransactionFactory.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/JavaxTransactionFactory.java
Mon Aug 29 19:19:20 2016
@@ -35,6 +35,7 @@ import java.util.List;
 public class JavaxTransactionFactory implements BeanAnnotationHandler<Transactional>,
MethodAnnotationHandler<Transactional> {
     public static final String NS_TX = "http://aries.apache.org/xmlns/transactions/v1.2.0";
     public static final String NS_TX2 = "http://aries.apache.org/xmlns/transactions/v2.0.0";
+
     private String getTransactionTypeName(Transactional transactional) {
         return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, transactional.value().name());
     }
@@ -56,7 +57,7 @@ public class JavaxTransactionFactory imp
                 beanEnricher.addBeanContentWriter("javax.transactional.method/" + clazz.getName()
+ "/" + name + "/" + transactionTypeName, new XmlWriter() {
                     @Override
                     public void write(XMLStreamWriter writer) throws XMLStreamException {
-                        writer.writeEmptyElement(NS_TX, "transaction");
+                        writer.writeEmptyElement("tx", "transaction", NS_TX);
                         writer.writeAttribute("method", name);
                         writer.writeAttribute("value", transactionTypeName);
                         writer.writeCharacters("\n");
@@ -87,7 +88,7 @@ public class JavaxTransactionFactory imp
             beanEnricher.addBeanContentWriter("javax.transactional.method/" + annotatedElement
+ "/*/" + transactionTypeName, new XmlWriter() {
                 @Override
                 public void write(XMLStreamWriter writer) throws XMLStreamException {
-                    writer.writeEmptyElement(NS_TX, "transaction");
+                    writer.writeEmptyElement("tx", "transaction", NS_TX);
                     writer.writeAttribute("method", "*");
                     writer.writeAttribute("value", transactionTypeName);
                     writer.writeCharacters("\n");
@@ -103,7 +104,7 @@ public class JavaxTransactionFactory imp
         contextEnricher.addBlueprintContentWriter("transaction/ennable-annotation", new XmlWriter()
{
             @Override
             public void write(XMLStreamWriter writer) throws XMLStreamException {
-                writer.writeEmptyElement(NS_TX2, "enable");
+                writer.writeEmptyElement("tx", "enable", NS_TX2);
             }
         });
     }

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/PersistenceContextHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/PersistenceContextHandler.java?rev=1758293&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/PersistenceContextHandler.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/PersistenceContextHandler.java
Mon Aug 29 19:19:20 2016
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.plugin.javax;
+
+import org.apache.aries.blueprint.plugin.spi.BeanEnricher;
+import org.apache.aries.blueprint.plugin.spi.ContextEnricher;
+import org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler;
+import org.apache.aries.blueprint.plugin.spi.XmlWriter;
+
+import javax.persistence.PersistenceContext;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.lang.reflect.Field;
+import java.util.List;
+
+public class PersistenceContextHandler implements FieldAnnotationHandler<PersistenceContext>
{
+    public static final String NS_JPA = "http://aries.apache.org/xmlns/jpa/v1.1.0";
+    public static final String NS_JPA2 = "http://aries.apache.org/xmlns/jpa/v2.0.0";
+
+    @Override
+    public Class<PersistenceContext> getAnnotation() {
+        return PersistenceContext.class;
+    }
+
+    @Override
+    public void handleMethodAnnotation(Class<?> clazz, List<Field> fields, ContextEnricher
contextEnricher, BeanEnricher beanEnricher) {
+        if (contextEnricher.getBlueprintConfiguration().getNamespaces().contains(NS_JPA))
{
+            for (final Field field : fields) {
+                final String name = field.getName();
+                final PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
+                beanEnricher.addBeanContentWriter("javax.persistence.field.context/" + name,
new XmlWriter() {
+                    @Override
+                    public void write(XMLStreamWriter writer) throws XMLStreamException {
+                        writer.writeEmptyElement("jpa", "context", NS_JPA);
+                        writer.writeAttribute("unitname", persistenceContext.unitName());
+                        writer.writeAttribute("property", name);
+                    }
+                });
+            }
+        }
+        if (contextEnricher.getBlueprintConfiguration().getNamespaces().contains(NS_JPA2))
{
+            contextEnricher.addBlueprintContentWriter("javax.persistence.enableJpa2", new
XmlWriter() {
+                @Override
+                public void write(XMLStreamWriter writer) throws XMLStreamException {
+                    writer.writeEmptyElement("jpa", "enable", NS_JPA2);
+                }
+            });
+        }
+    }
+}

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/PersistenceUnitHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/PersistenceUnitHandler.java?rev=1758293&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/PersistenceUnitHandler.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/javax/PersistenceUnitHandler.java
Mon Aug 29 19:19:20 2016
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.plugin.javax;
+
+import org.apache.aries.blueprint.plugin.spi.BeanEnricher;
+import org.apache.aries.blueprint.plugin.spi.ContextEnricher;
+import org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler;
+import org.apache.aries.blueprint.plugin.spi.XmlWriter;
+
+import javax.persistence.PersistenceUnit;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.lang.reflect.Field;
+import java.util.List;
+
+public class PersistenceUnitHandler implements FieldAnnotationHandler<PersistenceUnit>
{
+    public static final String NS_JPA = "http://aries.apache.org/xmlns/jpa/v1.1.0";
+    public static final String NS_JPA2 = "http://aries.apache.org/xmlns/jpa/v2.0.0";
+
+    @Override
+    public Class<PersistenceUnit> getAnnotation() {
+        return PersistenceUnit.class;
+    }
+
+    @Override
+    public void handleMethodAnnotation(Class<?> clazz, List<Field> fields, ContextEnricher
contextEnricher, BeanEnricher beanEnricher) {
+        if (contextEnricher.getBlueprintConfiguration().getNamespaces().contains(NS_JPA))
{
+            for (final Field field : fields) {
+                final String name = field.getName();
+                final PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
+                beanEnricher.addBeanContentWriter("javax.persistence.field.unit/" + name,
new XmlWriter() {
+                    @Override
+                    public void write(XMLStreamWriter writer) throws XMLStreamException {
+                        writer.writeEmptyElement("jpa", "unit", NS_JPA);
+                        writer.writeAttribute("unitname", persistenceUnit.unitName());
+                        writer.writeAttribute("property", name);
+                    }
+                });
+            }
+        }
+        if (contextEnricher.getBlueprintConfiguration().getNamespaces().contains(NS_JPA2))
{
+            contextEnricher.addBlueprintContentWriter("javax.persistence.enableJpa2", new
XmlWriter() {
+                @Override
+                public void write(XMLStreamWriter writer) throws XMLStreamException {
+                    writer.writeEmptyElement("jpa", "enable", NS_JPA2);
+                }
+            });
+        }
+    }
+}

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java?rev=1758293&r1=1758292&r2=1758293&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
Mon Aug 29 19:19:20 2016
@@ -23,13 +23,12 @@ import org.apache.aries.blueprint.plugin
 import org.apache.aries.blueprint.plugin.spi.BeanEnricher;
 import org.apache.aries.blueprint.plugin.spi.ContextEnricher;
 import org.apache.aries.blueprint.plugin.spi.CustomDependencyAnnotationHandler;
+import org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler;
 import org.apache.aries.blueprint.plugin.spi.InjectLikeHandler;
 import org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler;
 import org.apache.aries.blueprint.plugin.spi.NamedLikeHandler;
 import org.apache.aries.blueprint.plugin.spi.XmlWriter;
 
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceUnit;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Constructor;
@@ -49,7 +48,6 @@ import static org.apache.aries.blueprint
 public class Bean extends BeanRef implements BeanEnricher {
     public SortedSet<Property> properties = new TreeSet<>();
     public List<Argument> constructorArguments = new ArrayList<>();
-    public List<Field> persistenceFields;
     public boolean isPrototype;
     public final Map<String, String> attributes = new HashMap<>();
     public final Set<BeanRef> refs = new HashSet<>();
@@ -62,12 +60,13 @@ public class Bean extends BeanRef implem
         Introspector introspector = new Introspector(clazz);
 
         this.isPrototype = isPrototype(clazz);
-        this.persistenceFields = findPersistenceFields(introspector);
 
         setQualifiersFromAnnotations(clazz.getAnnotations());
 
         handleCustomBeanAnnotations();
 
+        handleFieldsAnnotation(introspector);
+
         handleMethodsAnnotation(introspector);
     }
 
@@ -86,6 +85,15 @@ public class Bean extends BeanRef implem
         }
     }
 
+    private void handleFieldsAnnotation(Introspector introspector) {
+        for (FieldAnnotationHandler fieldAnnotationHandler : Extensions.fieldAnnotationHandlers)
{
+            List<Field> fields = introspector.fieldsWith(fieldAnnotationHandler.getAnnotation());
+            if (fields.size() > 0) {
+                fieldAnnotationHandler.handleMethodAnnotation(clazz, fields, contextEnricher,
this);
+            }
+        }
+    }
+
     private void handleCustomBeanAnnotations() {
         for (BeanAnnotationHandler beanAnnotationHandler : Extensions.BEAN_ANNOTATION_HANDLERs)
{
             Object annotation = AnnotationHelper.findAnnotation(clazz.getAnnotations(), beanAnnotationHandler.getAnnotation());
@@ -95,10 +103,6 @@ public class Bean extends BeanRef implem
         }
     }
 
-    private List<Field> findPersistenceFields(Introspector introspector) {
-        return introspector.fieldsWith(PersistenceContext.class, PersistenceUnit.class);
-    }
-
     private boolean isPrototype(Class<?> clazz) {
         return !findSingleton(clazz);
     }

Copied: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spi/FieldAnnotationHandler.java
(from r1758278, aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spi/MethodAnnotationHandler.java)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spi/FieldAnnotationHandler.java?p2=aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spi/FieldAnnotationHandler.java&p1=aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spi/MethodAnnotationHandler.java&r1=1758278&r2=1758293&rev=1758293&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spi/MethodAnnotationHandler.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spi/FieldAnnotationHandler.java
Mon Aug 29 19:19:20 2016
@@ -19,11 +19,11 @@
 package org.apache.aries.blueprint.plugin.spi;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
+import java.lang.reflect.Field;
 import java.util.List;
 
-public interface MethodAnnotationHandler<A extends Annotation> {
+public interface FieldAnnotationHandler<A extends Annotation> {
     Class<A> getAnnotation();
 
-    void handleMethodAnnotation(Class<?> clazz, List<Method> methods, ContextEnricher
contextEnricher, BeanEnricher beanEnricher);
+    void handleMethodAnnotation(Class<?> clazz, List<Field> fields, ContextEnricher
contextEnricher, BeanEnricher beanEnricher);
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spring/SpringTransactionalFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spring/SpringTransactionalFactory.java?rev=1758293&r1=1758292&r2=1758293&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spring/SpringTransactionalFactory.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/spring/SpringTransactionalFactory.java
Mon Aug 29 19:19:20 2016
@@ -61,7 +61,7 @@ public class SpringTransactionalFactory
                 beanEnricher.addBeanContentWriter("javax.transactional.method/" + clazz.getName()
+ "/" + name + "/" + transactionTypeName, new XmlWriter() {
                     @Override
                     public void write(XMLStreamWriter writer) throws XMLStreamException {
-                        writer.writeEmptyElement(NS_TX, "transaction");
+                        writer.writeEmptyElement("tx", "transaction", NS_TX);
                         writer.writeAttribute("method", name);
                         writer.writeAttribute("value", transactionTypeName);
                         writer.writeCharacters("\n");
@@ -78,7 +78,7 @@ public class SpringTransactionalFactory
         contextEnricher.addBlueprintContentWriter("transaction/ennable-annotation", new XmlWriter()
{
             @Override
             public void write(XMLStreamWriter writer) throws XMLStreamException {
-                writer.writeEmptyElement(NS_TX, "enable-annotations");
+                writer.writeEmptyElement("tx", "enable-annotations", NS_TX);
             }
         });
     }
@@ -92,7 +92,7 @@ public class SpringTransactionalFactory
             beanEnricher.addBeanContentWriter("javax.transactional.method/" + annotatedElement
+ "/*/" + transactionTypeName, new XmlWriter() {
                 @Override
                 public void write(XMLStreamWriter writer) throws XMLStreamException {
-                    writer.writeEmptyElement(NS_TX, "transaction");
+                    writer.writeEmptyElement("tx", "transaction", NS_TX);
                     writer.writeAttribute("method", "*");
                     writer.writeAttribute("value", transactionTypeName);
                     writer.writeCharacters("\n");
@@ -108,7 +108,7 @@ public class SpringTransactionalFactory
         contextEnricher.addBlueprintContentWriter("transaction/ennable-annotation", new XmlWriter()
{
             @Override
             public void write(XMLStreamWriter writer) throws XMLStreamException {
-                writer.writeEmptyElement(NS_TX2, "enable");
+                writer.writeEmptyElement("tx", "enable", NS_TX2);
             }
         });
     }

Copied: aries/trunk/blueprint/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler
(from r1758278, aries/trunk/blueprint/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler?p2=aries/trunk/blueprint/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler&p1=aries/trunk/blueprint/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler&r1=1758278&r2=1758293&rev=1758293&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler
Mon Aug 29 19:19:20 2016
@@ -15,8 +15,5 @@
 # limitations under the License.
 #
 
-org.apache.aries.blueprint.plugin.pax.OsgiServiceProviderHandler
-org.apache.aries.blueprint.plugin.spring.LazyAttributeResolver
-org.apache.aries.blueprint.plugin.spring.DependsOnAttributeResolver
-org.apache.aries.blueprint.plugin.spring.SpringTransactionalFactory
-org.apache.aries.blueprint.plugin.javax.JavaxTransactionFactory
\ No newline at end of file
+org.apache.aries.blueprint.plugin.javax.PersistenceContextHandler
+org.apache.aries.blueprint.plugin.javax.PersistenceUnitHandler
\ No newline at end of file

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java?rev=1758293&r1=1758292&r2=1758293&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
Mon Aug 29 19:19:20 2016
@@ -19,6 +19,7 @@
 package org.apache.aries.blueprint.plugin;
 
 import com.google.common.collect.Sets;
+import org.apache.aries.blueprint.plugin.javax.PersistenceContextHandler;
 import org.apache.aries.blueprint.plugin.model.Context;
 import org.apache.aries.blueprint.plugin.model.TransactionalDef;
 import org.apache.aries.blueprint.plugin.spring.SpringTransactionalFactory;
@@ -63,7 +64,7 @@ public class GeneratorTest {
         ClassFinder classFinder = new ClassFinder(GeneratorTest.class.getClassLoader());
         String packageName = MyBean1.class.getPackage().getName();
         Set<Class<?>> beanClasses = findClasses(classFinder, Collections.singletonList(packageName));
-        Set<String> namespaces = new HashSet<String>(Arrays.asList(Generator.NS_JPA,
SpringTransactionalFactory.NS_TX));
+        Set<String> namespaces = new HashSet<String>(Arrays.asList(PersistenceContextHandler.NS_JPA,
SpringTransactionalFactory.NS_TX));
         BlueprintConfigurationImpl blueprintConfiguration = new BlueprintConfigurationImpl(namespaces,
null);
         Context context = new Context(blueprintConfiguration, beanClasses);
         context.resolve();

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java?rev=1758293&r1=1758292&r2=1758293&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
Mon Aug 29 19:19:20 2016
@@ -20,7 +20,6 @@ package org.apache.aries.blueprint.plugi
 
 import com.google.common.collect.Sets;
 import org.apache.aries.blueprint.plugin.BlueprintConfigurationImpl;
-import org.apache.aries.blueprint.plugin.Generator;
 import org.apache.aries.blueprint.plugin.bad.BadBean1;
 import org.apache.aries.blueprint.plugin.bad.BadBean2;
 import org.apache.aries.blueprint.plugin.bad.BadBean3;
@@ -29,6 +28,7 @@ import org.apache.aries.blueprint.plugin
 import org.apache.aries.blueprint.plugin.bad.BadFieldBean3;
 import org.apache.aries.blueprint.plugin.bad.FieldBean4;
 import org.apache.aries.blueprint.plugin.javax.JavaxTransactionFactory;
+import org.apache.aries.blueprint.plugin.javax.PersistenceUnitHandler;
 import org.apache.aries.blueprint.plugin.test.MyBean1;
 import org.apache.aries.blueprint.plugin.test.MyBean3;
 import org.apache.aries.blueprint.plugin.test.MyBean4;
@@ -46,7 +46,7 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertTrue;
 
 public class BeanTest {
-    private final Set<String> namespaces = new HashSet<String>(Arrays.asList(Generator.NS_JPA,
JavaxTransactionFactory.NS_TX));
+    private final Set<String> namespaces = new HashSet<String>(Arrays.asList(PersistenceUnitHandler.NS_JPA,
JavaxTransactionFactory.NS_TX));
     private final BlueprintConfigurationImpl blueprintConfiguration = new BlueprintConfigurationImpl(namespaces,
null);
     private final Context context = new Context(blueprintConfiguration);
 
@@ -56,9 +56,8 @@ public class BeanTest {
         bean.resolve(context);
         assertEquals(MyBean1.class, bean.clazz);
         assertEquals("myBean1", bean.id); // Name derived from class name
-        assertEquals(2, bean.persistenceFields.size());
-        assertEquals("em", bean.persistenceFields.get(0).getName());
-        assertEquals("emf", bean.persistenceFields.get(1).getName());
+        assertEquals(2, getPersistenceFields(bean).size());
+        assertEquals(Sets.newHashSet("em", "emf"), getPersistenceFields(bean));
         assertEquals(1, bean.properties.size());
         assertFalse(bean.isPrototype);
         Property prop = bean.properties.iterator().next();
@@ -81,7 +80,7 @@ public class BeanTest {
         bean.resolve(context);
         assertEquals(MyBean3.class, bean.clazz);
         assertEquals("myBean3", bean.id); // Name derived from class name
-        assertEquals("There should be no persistence fields", 0, bean.persistenceFields.size());
+        assertEquals("There should be no persistence fields", 0, getPersistenceFields(bean).size());
         assertEquals(5, bean.properties.size());
         assertTrue(bean.isPrototype);
 
@@ -102,7 +101,7 @@ public class BeanTest {
         String definedName = ServiceAImpl1.class.getAnnotation(Named.class).value();
         assertEquals("my1", definedName);
         assertEquals("Name should be defined using @Named", definedName, bean.id);
-        assertEquals("There should be no persistence fields", 0, bean.persistenceFields.size());
+        assertEquals("There should be no persistence fields", 0,getPersistenceFields(bean).size());
         assertTrue("There should be no transaction definition", getTransactionalDefs(bean).isEmpty());
         assertEquals("There should be no properties", 0, bean.properties.size());
         assertTrue(bean.isPrototype);
@@ -133,6 +132,16 @@ public class BeanTest {
         return transactionalDefs;
     }
 
+    private Set<String> getPersistenceFields(Bean bean) {
+        Set<String> beanWriters = bean.beanContentWriters.keySet();
+        Set<String> persistenceFields = new HashSet<>();
+        for (String beanWriter : beanWriters) {
+            if (beanWriter.startsWith("javax.persistence.field.")) {
+                persistenceFields.add(beanWriter.split("/")[1]);
+            }
+        }
+        return persistenceFields;
+    }
 
     @Test(expected = IllegalArgumentException.class)
     public void testMultipleInitMethods() {
@@ -175,7 +184,7 @@ public class BeanTest {
         bean.resolve(context);
         assertEquals(MyBean5.class, bean.clazz);
         assertEquals("myBean5", bean.id); // Name derived from class name
-        assertTrue("There should be no persistenceUnit", bean.persistenceFields.isEmpty());
+        assertTrue("There should be no persistenceUnit", getPersistenceFields(bean).isEmpty());
         assertEquals(0, bean.properties.size());
         assertEquals(8, bean.constructorArguments.size());
         assertEquals("my2", bean.constructorArguments.get(0).getRef());

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java?rev=1758293&r1=1758292&r2=1758293&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
Mon Aug 29 19:19:20 2016
@@ -19,7 +19,7 @@
 package org.apache.aries.blueprint.plugin.model;
 
 import org.apache.aries.blueprint.plugin.BlueprintConfigurationImpl;
-import org.apache.aries.blueprint.plugin.Generator;
+import org.apache.aries.blueprint.plugin.javax.PersistenceUnitHandler;
 import org.apache.aries.blueprint.plugin.spring.SpringTransactionalFactory;
 import org.apache.aries.blueprint.plugin.test.MyBean3;
 import org.apache.aries.blueprint.plugin.test.MyFactoryBean;
@@ -39,7 +39,7 @@ import java.util.Set;
 import static org.junit.Assert.assertEquals;
 
 public class ContextTest {
-    private final Set<String> namespaces = new HashSet<String>(Arrays.asList(Generator.NS_JPA,
SpringTransactionalFactory.NS_TX));
+    private final Set<String> namespaces = new HashSet<String>(Arrays.asList(PersistenceUnitHandler.NS_JPA,
SpringTransactionalFactory.NS_TX));
     private final BlueprintConfigurationImpl blueprintConfiguration = new BlueprintConfigurationImpl(namespaces,
null);
 
     @Test




Mime
View raw message