aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alien11...@apache.org
Subject svn commit: r1746761 - in /aries/trunk/blueprint/blueprint-maven-plugin: ./ src/main/java/org/apache/aries/blueprint/plugin/ src/main/java/org/apache/aries/blueprint/plugin/model/ src/main/java/org/apache/aries/blueprint/plugin/model/service/
Date Fri, 03 Jun 2016 20:52:55 GMT
Author: alien11689
Date: Fri Jun  3 20:52:55 2016
New Revision: 1746761

URL: http://svn.apache.org/viewvc?rev=1746761&view=rev
Log:
[ARIES-1561] Prepare ServiceProvider model and move service provider classes to separate package

Added:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/service/
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/service/ServiceProvider.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/service/ServiceProviderWriter.java
Removed:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceProviderWriter.java
Modified:
    aries/trunk/blueprint/blueprint-maven-plugin/   (props changed)
    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/model/Bean.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java

Propchange: aries/trunk/blueprint/blueprint-maven-plugin/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Jun  3 20:52:55 2016
@@ -5,3 +5,4 @@ target
 .project
 velocity.log
 .externalToolBuilders
+.idea

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=1746761&r1=1746760&r2=1746761&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
Fri Jun  3 20:52:55 2016
@@ -26,6 +26,7 @@ import org.apache.aries.blueprint.plugin
 import org.apache.aries.blueprint.plugin.model.Property;
 import org.apache.aries.blueprint.plugin.model.PropertyWriter;
 import org.apache.aries.blueprint.plugin.model.TransactionalDef;
+import org.apache.aries.blueprint.plugin.model.service.ServiceProviderWriter;
 
 import javax.persistence.PersistenceContext;
 import javax.persistence.PersistenceUnit;
@@ -89,7 +90,7 @@ public class Generator implements Proper
             }
 
             new OsgiServiceRefWriter(writer).write(context.getServiceRefs());
-            new OsgiServiceProviderWriter(writer).write(context.getBeans());
+            new ServiceProviderWriter(writer).write(context.getServiceProviders());
 
             writer.writeEndElement();
             writer.writeCharacters("\n");

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=1746761&r1=1746760&r2=1746761&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
Fri Jun  3 20:52:55 2016
@@ -18,6 +18,7 @@
  */
 package org.apache.aries.blueprint.plugin.model;
 
+import org.apache.aries.blueprint.plugin.model.service.ServiceProvider;
 import org.ops4j.pax.cdi.api.OsgiService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -50,6 +51,7 @@ public class Bean extends BeanRef {
     public List<Field> persistenceFields;
     public Set<TransactionalDef> transactionDefs = new HashSet<>();
     public boolean isPrototype;
+    public List<ServiceProvider> serviceProviders = new ArrayList<>();
 
     public Bean(Class<?> clazz) {
         super(clazz, BeanRef.getBeanName(clazz));
@@ -73,6 +75,11 @@ public class Bean extends BeanRef {
         this.isPrototype = isPrototype(clazz);
         this.persistenceFields = introspector.fieldsWith(PersistenceContext.class, PersistenceUnit.class);
         setQualifiersFromAnnotations(clazz.getAnnotations());
+
+        ServiceProvider serviceProvider = ServiceProvider.fromBean(this);
+        if(serviceProvider != null){
+            serviceProviders.add(serviceProvider);
+        }
     }
 
     private boolean isPrototype(Class<?> clazz) {

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java?rev=1746761&r1=1746760&r2=1746761&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
Fri Jun  3 20:52:55 2016
@@ -18,6 +18,7 @@
  */
 package org.apache.aries.blueprint.plugin.model;
 
+import org.apache.aries.blueprint.plugin.model.service.ServiceProvider;
 import org.ops4j.pax.cdi.api.OsgiService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -29,21 +30,23 @@ import javax.inject.Named;
 import javax.inject.Singleton;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
 public class Context implements Matcher {
 
-    SortedSet<BeanRef> reg;
+    SortedSet<BeanRef> reg = new TreeSet<BeanRef>();
+    private final List<ServiceProvider> serviceProviders = new ArrayList<>();
 
     public Context(Class<?>... beanClasses) {
         this(Arrays.asList(beanClasses));
     }
 
     public Context(Collection<Class<?>> beanClasses) {
-        this.reg = new TreeSet<BeanRef>();
         addBlueprintRefs();
         addBeans(beanClasses);
     }
@@ -65,11 +68,16 @@ public class Context implements Matcher
         Bean bean = new Bean(clazz);
         reg.add(bean);
         addServiceRefs(clazz);
-        addProducedBeans(clazz, bean);
+        addProducedBeans(bean);
+        addServiceProviders(bean);
     }
 
-    private void addProducedBeans(Class<?> clazz, BeanRef factoryBean) {
-        for (Method method : clazz.getMethods()) {
+    private void addServiceProviders(Bean bean) {
+        serviceProviders.addAll(bean.serviceProviders);
+    }
+
+    private void addProducedBeans(BeanRef factoryBean) {
+        for (Method method : factoryBean.clazz.getMethods()) {
             Produces produces = method.getAnnotation(Produces.class);
             Named named = method.getAnnotation(Named.class);
             Singleton singleton = method.getAnnotation(Singleton.class);
@@ -135,4 +143,7 @@ public class Context implements Matcher
         return serviceRefs;
     }
 
+    public List<ServiceProvider> getServiceProviders() {
+        return serviceProviders;
+    }
 }

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/service/ServiceProvider.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/service/ServiceProvider.java?rev=1746761&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/service/ServiceProvider.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/service/ServiceProvider.java
Fri Jun  3 20:52:55 2016
@@ -0,0 +1,46 @@
+package org.apache.aries.blueprint.plugin.model.service;
+
+import com.google.common.collect.Lists;
+import org.apache.aries.blueprint.plugin.model.Bean;
+import org.ops4j.pax.cdi.api.OsgiServiceProvider;
+import org.ops4j.pax.cdi.api.Properties;
+import org.ops4j.pax.cdi.api.Property;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ServiceProvider {
+    public final List<String> interfaces;
+    public final String beanRef;
+    public final Map<String, String> serviceProperties;
+
+    public ServiceProvider(List<String> interfaces, String beanRef, Map<String,
String> serviceProperties) {
+        this.interfaces = interfaces;
+        this.beanRef = beanRef;
+        this.serviceProperties = serviceProperties;
+    }
+
+    public static ServiceProvider fromBean(Bean bean) {
+        OsgiServiceProvider serviceProvider = bean.clazz.getAnnotation(OsgiServiceProvider.class);
+        if (serviceProvider == null) {
+            return null;
+        }
+
+        List<String> interfaceNames = Lists.newArrayList();
+        for (Class<?> serviceIf : serviceProvider.classes()) {
+            interfaceNames.add(serviceIf.getName());
+        }
+
+        Properties properties = bean.clazz.getAnnotation(Properties.class);
+
+        Map<String, String> propertiesAsMap = new HashMap<>();
+        if (properties != null) {
+            for (Property property : properties.value()) {
+                propertiesAsMap.put(property.name(), property.value());
+            }
+        }
+
+        return new ServiceProvider(interfaceNames, bean.id, propertiesAsMap);
+    }
+}

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/service/ServiceProviderWriter.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/service/ServiceProviderWriter.java?rev=1746761&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/service/ServiceProviderWriter.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/service/ServiceProviderWriter.java
Fri Jun  3 20:52:55 2016
@@ -0,0 +1,108 @@
+/**
+ * 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
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.model.service;
+
+import com.google.common.collect.Iterables;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.util.Collection;
+import java.util.Map;
+
+public class ServiceProviderWriter {
+    private final XMLStreamWriter writer;
+
+    public ServiceProviderWriter(XMLStreamWriter writer) {
+        this.writer = writer;
+    }
+
+    public void write(Collection<ServiceProvider> serviceProviders) throws XMLStreamException
{
+        for (ServiceProvider serviceProvider : serviceProviders) {
+            write(serviceProvider);
+        }
+    }
+
+    private void write(ServiceProvider serviceProvider) throws XMLStreamException {
+
+        // If there are no properties to write and only one service attribute (either
+        // interface="MyServiceInterface" or auto-export="interfaces") then create an
+        // empty element
+        boolean writeEmptyElement = serviceProvider.serviceProperties.isEmpty() &&
serviceProvider.interfaces.size() < 2;
+        if (writeEmptyElement) {
+            writer.writeEmptyElement("service");
+        } else {
+            writer.writeStartElement("service");
+        }
+        writer.writeAttribute("ref", serviceProvider.beanRef);
+
+        if (serviceProvider.interfaces.size() == 0) {
+            writer.writeAttribute("auto-export", "interfaces");
+        } else if (serviceProvider.interfaces.size() == 1) {
+            writer.writeAttribute("interface", Iterables.getOnlyElement(serviceProvider.interfaces));
+        } else {
+            writeInterfacesElement(serviceProvider.interfaces);
+        }
+
+        writer.writeCharacters("\n");
+
+        if (!serviceProvider.serviceProperties.isEmpty()) {
+            writeProperties(serviceProvider.serviceProperties);
+        }
+
+        if (!writeEmptyElement) {
+            writer.writeEndElement();
+            writer.writeCharacters("\n");
+        }
+    }
+
+    private void writeInterfacesElement(Iterable<String> interfaceNames) throws XMLStreamException
+    {
+        writer.writeCharacters("\n");
+        writer.writeCharacters("    ");
+        writer.writeStartElement("interfaces");
+        writer.writeCharacters("\n");
+        for (String interfaceName : interfaceNames) {
+            writer.writeCharacters("        ");
+            writer.writeStartElement("value");
+            writer.writeCharacters(interfaceName);
+            writer.writeEndElement();
+            writer.writeCharacters("\n");
+        }
+        writer.writeCharacters("    ");
+        writer.writeEndElement();
+    }
+
+    private void writeProperties(Map<String,String> properties) throws XMLStreamException
{
+        writer.writeCharacters("    ");
+        writer.writeStartElement("service-properties");
+        writer.writeCharacters("\n");
+        for (Map.Entry<String,String> property : properties.entrySet()) {
+            writer.writeCharacters("        ");
+            writer.writeEmptyElement("entry");
+            writer.writeAttribute("key", property.getKey());
+            writer.writeAttribute("value", property.getValue());
+            writer.writeCharacters("\n");
+        }
+        writer.writeCharacters("    ");
+        writer.writeEndElement();
+        writer.writeCharacters("\n");
+    }
+
+
+}



Mime
View raw message