aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1716136 - in /aries/trunk/blueprint: blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/ blueprint-testbundles/src/main/java/org/apache/aries/blueprint/testbundles/ blueprint-testbundles/src/main/resources/OSGI-INF/blueprint/
Date Tue, 24 Nov 2015 13:56:35 GMT
Author: gnodet
Date: Tue Nov 24 13:56:34 2015
New Revision: 1716136

URL: http://svn.apache.org/viewvc?rev=1716136&view=rev
Log:
[ARIES-1456] Add support for auto-wiring and nested <beans> element

Added:
    aries/trunk/blueprint/blueprint-testbundles/src/main/java/org/apache/aries/blueprint/testbundles/BeanC.java
Modified:
    aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BeansNamespaceHandler.java
    aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java
    aries/trunk/blueprint/blueprint-testbundles/src/main/resources/OSGI-INF/blueprint/config.xml

Modified: aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BeansNamespaceHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BeansNamespaceHandler.java?rev=1716136&r1=1716135&r2=1716136&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BeansNamespaceHandler.java
(original)
+++ aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BeansNamespaceHandler.java
Tue Nov 24 13:56:34 2015
@@ -16,13 +16,20 @@
  */
 package org.apache.aries.blueprint.spring;
 
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
 import org.springframework.beans.factory.BeanDefinitionStoreException;
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.config.BeanDefinitionHolder;
 import org.springframework.beans.factory.parsing.BeanComponentDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
 import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
+import org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader;
 import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.beans.factory.xml.XmlReaderContext;
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
@@ -52,6 +59,9 @@ public class BeansNamespaceHandler imple
                 // Send registration event.
                 parserContext.getReaderContext().fireComponentRegistered(new BeanComponentDefinition(bdHolder));
             }
+        } else if (DefaultBeanDefinitionDocumentReader.NESTED_BEANS_ELEMENT.equals(ele.getLocalName()))
{
+            MyDefaultBeanDefinitionDocumentReader reader = new MyDefaultBeanDefinitionDocumentReader();
+            reader.registerBeanDefinitions(ele, parserContext.getReaderContext());
         } else {
             throw new UnsupportedOperationException();
         }
@@ -62,4 +72,21 @@ public class BeansNamespaceHandler imple
     public BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder definition, ParserContext
parserContext) {
         return definition;
     }
+
+    private static class MyDefaultBeanDefinitionDocumentReader extends DefaultBeanDefinitionDocumentReader
{
+
+        public void registerBeanDefinitions(final Element ele, XmlReaderContext readerContext)
{
+            Document doc = (Document) Proxy.newProxyInstance(getClass().getClassLoader(),
new Class[]{Document.class}, new InvocationHandler() {
+                @Override
+                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
+                    if (method.getName().equals("getDocumentElement")) {
+                        return ele;
+                    }
+                    throw new UnsupportedOperationException();
+                }
+            });
+            registerBeanDefinitions(doc, readerContext);
+        }
+
+    }
 }

Modified: aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java?rev=1716136&r1=1716135&r2=1716136&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java
(original)
+++ aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java
Tue Nov 24 13:56:34 2015
@@ -23,6 +23,7 @@ import java.util.Set;
 
 import org.apache.aries.blueprint.ComponentDefinitionRegistry;
 import org.apache.aries.blueprint.NamespaceHandler;
+import org.apache.aries.blueprint.NamespaceHandler2;
 import org.apache.aries.blueprint.ParserContext;
 import org.apache.aries.blueprint.PassThroughMetadata;
 import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
@@ -55,7 +56,7 @@ import org.w3c.dom.Node;
 /**
  * Blueprint NamespaceHandler wrapper for a spring NamespaceHandler
  */
-public class BlueprintNamespaceHandler implements NamespaceHandler {
+public class BlueprintNamespaceHandler implements NamespaceHandler2 {
 
     public static final String SPRING_CONTEXT_ID = "." + org.springframework.beans.factory.xml.ParserContext.class.getName();
     public static final String SPRING_BEAN_PROCESSOR_ID = "." + SpringBeanProcessor.class.getName();
@@ -78,6 +79,11 @@ public class BlueprintNamespaceHandler i
     }
 
     @Override
+    public boolean usePsvi() {
+        return true;
+    }
+
+    @Override
     public URL getSchemaLocation(String s) {
         if (schemas.containsKey(s)) {
             return bundle.getResource(schemas.getProperty(s));

Added: aries/trunk/blueprint/blueprint-testbundles/src/main/java/org/apache/aries/blueprint/testbundles/BeanC.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-testbundles/src/main/java/org/apache/aries/blueprint/testbundles/BeanC.java?rev=1716136&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-testbundles/src/main/java/org/apache/aries/blueprint/testbundles/BeanC.java
(added)
+++ aries/trunk/blueprint/blueprint-testbundles/src/main/java/org/apache/aries/blueprint/testbundles/BeanC.java
Tue Nov 24 13:56:34 2015
@@ -0,0 +1,38 @@
+/**
+ *  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.testbundles;
+
+import javax.annotation.PostConstruct;
+
+public class BeanC {
+
+    private final BeanA beanA;
+    private boolean initialized;
+
+    public BeanC(BeanA beanA) {
+        this.beanA = beanA;
+    }
+
+    @PostConstruct
+    public void start() {
+        this.initialized = true;
+    }
+
+    public boolean isInitialized() {
+        return initialized;
+    }
+}

Modified: aries/trunk/blueprint/blueprint-testbundles/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-testbundles/src/main/resources/OSGI-INF/blueprint/config.xml?rev=1716136&r1=1716135&r2=1716136&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-testbundles/src/main/resources/OSGI-INF/blueprint/config.xml
(original)
+++ aries/trunk/blueprint/blueprint-testbundles/src/main/resources/OSGI-INF/blueprint/config.xml
Tue Nov 24 13:56:34 2015
@@ -28,6 +28,12 @@
 
     <annotation-driven xmlns="http://www.springframework.org/schema/tx"/>
 
+    <bean:beans default-autowire="constructor">
+
+        <bean:bean id="beanC" class="org.apache.aries.blueprint.testbundles.BeanC"/>
+
+    </bean:beans>
+
     <bean id="beanB" class="org.apache.aries.blueprint.testbundles.BeanB">
         <property name="beanA" ref="beanA"/>
     </bean>
@@ -42,6 +48,7 @@
         <ref bean="beanA" />
         <ref bean="beanB"/>
         <ref bean="serializable"/>
+        <ref bean="beanC"/>
     </util:list>
 
     <util:constant id="serializable"



Mime
View raw message