aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1715816 - in /aries/trunk/blueprint/blueprint-spring: ./ src/main/java/org/apache/aries/blueprint/spring/
Date Mon, 23 Nov 2015 13:55:54 GMT
Author: gnodet
Date: Mon Nov 23 13:55:53 2015
New Revision: 1715816

URL: http://svn.apache.org/viewvc?rev=1715816&view=rev
Log:
[ARIES-1456] Fix usage of deprecated APIs

Modified:
    aries/trunk/blueprint/blueprint-spring/pom.xml
    aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintBeanFactory.java
    aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java
    aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/SpringBeanProcessor.java

Modified: aries/trunk/blueprint/blueprint-spring/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring/pom.xml?rev=1715816&r1=1715815&r2=1715816&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-spring/pom.xml (original)
+++ aries/trunk/blueprint/blueprint-spring/pom.xml Mon Nov 23 13:55:53 2015
@@ -49,7 +49,6 @@
         <aries.osgi.import.pkg>
            org.apache.aries.blueprint;provide:=true;version="[1.0,2.0)",
            org.apache.aries.blueprint.ext;provide:=true;version="[1.0,2.0)",
-           org.apache.aries.blueprint.reflect;version="[1.0,2.0)",
            *
         </aries.osgi.import.pkg>
         <aries.osgi.private.pkg>

Modified: aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintBeanFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintBeanFactory.java?rev=1715816&r1=1715815&r2=1715816&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintBeanFactory.java
(original)
+++ aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintBeanFactory.java
Mon Nov 23 13:55:53 2015
@@ -21,14 +21,17 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.aries.blueprint.ComponentDefinitionRegistry;
-import org.apache.aries.blueprint.reflect.BeanMetadataImpl;
-import org.apache.aries.blueprint.reflect.RefMetadataImpl;
-import org.apache.aries.blueprint.reflect.ValueMetadataImpl;
 import org.apache.aries.blueprint.services.ExtendedBlueprintContainer;
-import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.service.blueprint.container.NoSuchComponentException;
 import org.osgi.service.blueprint.container.ReifiedType;
+import org.osgi.service.blueprint.reflect.BeanArgument;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.BeanProperty;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.Target;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.BeanDefinitionStoreException;
 import org.springframework.beans.factory.BeanFactory;
@@ -72,14 +75,11 @@ public class BlueprintBeanFactory extend
         super.removeBeanDefinition(beanName);
     }
 
-    public class SpringMetadata extends BeanMetadataImpl {
+    public class SpringMetadata implements BeanMetadata {
         private final String beanName;
 
         public SpringMetadata(String beanName) {
             this.beanName = beanName;
-            setFactoryComponent(new RefMetadataImpl(BlueprintNamespaceHandler.SPRING_BEAN_FACTORY_ID));
-            setFactoryMethod("getBean");
-            addArgument(new ValueMetadataImpl(beanName), null, -1);
         }
 
         public BeanDefinition getDefinition() {
@@ -106,6 +106,68 @@ public class BlueprintBeanFactory extend
             String[] dependson = getDefinition().getDependsOn();
             return dependson != null ? Arrays.asList(dependson) : Collections.<String>emptyList();
         }
+
+        @Override
+        public String getClassName() {
+            return null;
+        }
+
+        @Override
+        public String getInitMethod() {
+            return null;
+        }
+
+        @Override
+        public String getDestroyMethod() {
+            return null;
+        }
+
+        @Override
+        public List<BeanArgument> getArguments() {
+            return Collections.<BeanArgument>singletonList(new BeanArgument() {
+                @Override
+                public Metadata getValue() {
+                    return new ValueMetadata() {
+                        @Override
+                        public String getStringValue() {
+                            return beanName;
+                        }
+                        @Override
+                        public String getType() {
+                            return null;
+                        }
+                    };
+                }
+                @Override
+                public String getValueType() {
+                    return null;
+                }
+                @Override
+                public int getIndex() {
+                    return -1;
+                }
+            });
+        }
+
+        @Override
+        public List<BeanProperty> getProperties() {
+            return Collections.emptyList();
+        }
+
+        @Override
+        public String getFactoryMethod() {
+            return "getBean";
+        }
+
+        @Override
+        public Target getFactoryComponent() {
+            return new RefMetadata() {
+                @Override
+                public String getComponentId() {
+                    return BlueprintNamespaceHandler.SPRING_BEAN_FACTORY_ID;
+                }
+            };
+        }
     }
 
 

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=1715816&r1=1715815&r2=1715816&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
Mon Nov 23 13:55:53 2015
@@ -25,9 +25,9 @@ import org.apache.aries.blueprint.Compon
 import org.apache.aries.blueprint.NamespaceHandler;
 import org.apache.aries.blueprint.ParserContext;
 import org.apache.aries.blueprint.PassThroughMetadata;
-import org.apache.aries.blueprint.reflect.BeanMetadataImpl;
-import org.apache.aries.blueprint.reflect.PassThroughMetadataImpl;
-import org.apache.aries.blueprint.reflect.RefMetadataImpl;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.aries.blueprint.mutable.MutablePassThroughMetadata;
+import org.apache.aries.blueprint.mutable.MutableRefMetadata;
 import org.apache.aries.blueprint.services.ExtendedBlueprintContainer;
 import org.osgi.framework.Bundle;
 import org.osgi.service.blueprint.reflect.BeanMetadata;
@@ -35,7 +35,6 @@ import org.osgi.service.blueprint.reflec
 import org.osgi.service.blueprint.reflect.Metadata;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.beans.factory.parsing.EmptyReaderEventListener;
 import org.springframework.beans.factory.parsing.FailFastProblemReporter;
 import org.springframework.beans.factory.parsing.NullSourceExtractor;
@@ -112,45 +111,80 @@ public class BlueprintNamespaceHandler i
 
     private org.springframework.beans.factory.xml.ParserContext getOrCreateParserContext(ParserContext
parserContext) {
         ComponentDefinitionRegistry registry = parserContext.getComponentDefinitionRegistry();
-        org.springframework.beans.factory.xml.ParserContext springContext;
-        ComponentMetadata contextMetadata = registry.getComponentDefinition(SPRING_CONTEXT_ID);
-        if (contextMetadata == null) {
-            ExtendedBlueprintContainer container = getBlueprintContainer(parserContext);
-            // Create spring application context
-            SpringApplicationContext applicationContext = new SpringApplicationContext(container);
-            registry.registerComponentDefinition(new PassThroughMetadataImpl(
+        ExtendedBlueprintContainer container = getBlueprintContainer(parserContext);
+        // Create spring application context
+        SpringApplicationContext applicationContext = getPassThrough(parserContext,
+                SPRING_APPLICATION_CONTEXT_ID, SpringApplicationContext.class);
+        if (applicationContext == null) {
+            applicationContext = new SpringApplicationContext(container);
+            registry.registerComponentDefinition(createPassThrough(parserContext,
                     SPRING_APPLICATION_CONTEXT_ID, applicationContext
             ));
-            // Create registry
-            DefaultListableBeanFactory beanFactory = applicationContext.getBeanFactory();
-            registry.registerComponentDefinition(new PassThroughMetadataImpl(
+        }
+        // Create registry
+        DefaultListableBeanFactory beanFactory = getPassThrough(parserContext,
+                SPRING_BEAN_FACTORY_ID, DefaultListableBeanFactory.class);
+        if (beanFactory == null) {
+            beanFactory = applicationContext.getBeanFactory();
+            registry.registerComponentDefinition(createPassThrough(parserContext,
                     SPRING_BEAN_FACTORY_ID, beanFactory
             ));
+        }
+        // Create spring parser context
+        org.springframework.beans.factory.xml.ParserContext springParserContext
+                = getPassThrough(parserContext, SPRING_CONTEXT_ID, org.springframework.beans.factory.xml.ParserContext.class);
+        if (springParserContext == null) {
             // Create spring context
-            springContext = createSpringParserContext(parserContext, beanFactory);
-            registry.registerComponentDefinition(new PassThroughMetadataImpl(
-                    SPRING_CONTEXT_ID, springContext
+            springParserContext = createSpringParserContext(parserContext, beanFactory);
+            registry.registerComponentDefinition(createPassThrough(parserContext,
+                    SPRING_CONTEXT_ID, springParserContext
             ));
-            // Create processor
-            BeanMetadataImpl bm = new BeanMetadataImpl();
+        }
+        // Create processor
+        if (!parserContext.getComponentDefinitionRegistry().containsComponentDefinition(SPRING_BEAN_PROCESSOR_ID))
{
+            MutableBeanMetadata bm = parserContext.createMetadata(MutableBeanMetadata.class);
             bm.setId(SPRING_BEAN_PROCESSOR_ID);
             bm.setProcessor(true);
             bm.setScope(BeanMetadata.SCOPE_SINGLETON);
             bm.setRuntimeClass(SpringBeanProcessor.class);
             bm.setActivation(BeanMetadata.ACTIVATION_EAGER);
-            bm.addArgument(new RefMetadataImpl("blueprintBundleContext"), null, 0);
-            bm.addArgument(new RefMetadataImpl("blueprintContainer"), null, 0);
-            bm.addArgument(new RefMetadataImpl(SPRING_APPLICATION_CONTEXT_ID), null, 0);
+            bm.addArgument(createRef(parserContext, "blueprintBundleContext"), null, 0);
+            bm.addArgument(createRef(parserContext, "blueprintContainer"), null, 0);
+            bm.addArgument(createRef(parserContext, SPRING_APPLICATION_CONTEXT_ID), null,
0);
             registry.registerComponentDefinition(bm);
-        } else {
-            PassThroughMetadata ptm = (PassThroughMetadata) contextMetadata;
-            springContext = (org.springframework.beans.factory.xml.ParserContext) ptm.getObject();
         }
-        return springContext;
+        return springParserContext;
+    }
+
+    private ComponentMetadata createPassThrough(ParserContext parserContext, String id, Object
o) {
+        MutablePassThroughMetadata pt = parserContext.createMetadata(MutablePassThroughMetadata.class);
+        pt.setId(id);
+        pt.setObject(o);
+        return pt;
+    }
+
+    private Metadata createRef(ParserContext parserContext, String id) {
+        MutableRefMetadata ref = parserContext.createMetadata(MutableRefMetadata.class);
+        ref.setComponentId(id);
+        return ref;
     }
 
     private ExtendedBlueprintContainer getBlueprintContainer(ParserContext parserContext)
{
-        return (ExtendedBlueprintContainer) ((PassThroughMetadata) parserContext.getComponentDefinitionRegistry().getComponentDefinition("blueprintContainer")).getObject();
+        ExtendedBlueprintContainer container = getPassThrough(parserContext, "blueprintContainer",
ExtendedBlueprintContainer.class);
+        if (container == null) {
+            throw new IllegalStateException();
+        }
+        return container;
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> T getPassThrough(ParserContext parserContext, String name, Class<T>
clazz) {
+        Metadata metadata = parserContext.getComponentDefinitionRegistry().getComponentDefinition(name);
+        if (metadata instanceof PassThroughMetadata) {
+            return (T) ((PassThroughMetadata) metadata).getObject();
+        } else {
+            return null;
+        }
     }
 
     private org.springframework.beans.factory.xml.ParserContext createSpringParserContext(ParserContext
parserContext, DefaultListableBeanFactory registry) {

Modified: aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/SpringBeanProcessor.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/SpringBeanProcessor.java?rev=1715816&r1=1715815&r2=1715816&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/SpringBeanProcessor.java
(original)
+++ aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/SpringBeanProcessor.java
Mon Nov 23 13:55:53 2015
@@ -31,11 +31,8 @@ import org.springframework.beans.factory
 import org.springframework.beans.factory.BeanClassLoaderAware;
 import org.springframework.beans.factory.BeanFactoryAware;
 import org.springframework.beans.factory.BeanNameAware;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.context.support.AbstractApplicationContext;
 
 public class SpringBeanProcessor implements BeanProcessor, ComponentDefinitionRegistryProcessor
{
 



Mime
View raw message