incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r886718 - in /incubator/aries/trunk/blueprint/blueprint-core: ./ src/main/java/org/apache/aries/blueprint/ src/main/java/org/apache/aries/blueprint/container/ src/main/java/org/apache/aries/blueprint/namespace/ src/test/java/org/apache/arie...
Date Thu, 03 Dec 2009 09:27:06 GMT
Author: mahrwald
Date: Thu Dec  3 09:26:49 2009
New Revision: 886718

URL: http://svn.apache.org/viewvc?rev=886718&view=rev
Log:
ARIES-63 Add convenience getters for built-in beans to component definition registry

Modified:
    incubator/aries/trunk/blueprint/blueprint-core/pom.xml
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentDefinitionRegistry.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/ComponentDefinitionRegistryImpl.java
    incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java
    incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java
    incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/WiringTest.java

Modified: incubator/aries/trunk/blueprint/blueprint-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/pom.xml?rev=886718&r1=886717&r2=886718&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/pom.xml (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/pom.xml Thu Dec  3 09:26:49 2009
@@ -70,6 +70,12 @@
           <artifactId>slf4j-simple</artifactId>
           <scope>test</scope>
       </dependency>
+      <dependency>
+          <groupId>org.apache.aries.testsupport</groupId>
+          <artifactId>aries-testsupport-unit</artifactId>
+          <version>${version}</version>
+          <scope>test</scope>
+      </dependency>     
   </dependencies>
 
     <build>

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentDefinitionRegistry.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentDefinitionRegistry.java?rev=886718&r1=886717&r2=886718&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentDefinitionRegistry.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentDefinitionRegistry.java
Thu Dec  3 09:26:49 2009
@@ -19,6 +19,10 @@
 import java.util.List;
 import java.util.Set;
 
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.container.Converter;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
 import org.osgi.service.blueprint.reflect.Target;
 
@@ -41,5 +45,29 @@
     void registerInterceptorWithComponent(ComponentMetadata component, Interceptor interceptor);
     
     List<Interceptor> getInterceptors(ComponentMetadata component);
+    
+    /**
+     * Obtain the blueprint container of that this component definition registry belongs
to
+     * @return
+     */
+    BlueprintContainer getBlueprintContainer();
+    
+    /**
+     * Obtain the client bundle that defines this blueprint module
+     * @return
+     */
+    Bundle getBlueprintBundle();
+    
+    /**
+     * Obtain the client bundle context of the bundle that defines this blueprint module
+     * @return
+     */
+    BundleContext getBlueprintBundleContext();
+    
+    /**
+     * Obtain the blueprint converter of the current blueprint module
+     * @return
+     */
+    Converter getBlueprintConverter();
 
 }

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=886718&r1=886717&r2=886718&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
Thu Dec  3 09:26:49 2009
@@ -35,11 +35,11 @@
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
-import java.util.LinkedHashSet;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
@@ -52,12 +52,11 @@
 import org.apache.aries.blueprint.ExtendedBlueprintContainer;
 import org.apache.aries.blueprint.NamespaceHandler;
 import org.apache.aries.blueprint.Processor;
-import org.apache.aries.blueprint.reflect.PassThroughMetadataImpl;
-import org.apache.aries.blueprint.reflect.MetadataUtil;
 import org.apache.aries.blueprint.di.Recipe;
 import org.apache.aries.blueprint.di.Repository;
 import org.apache.aries.blueprint.namespace.ComponentDefinitionRegistryImpl;
 import org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl;
+import org.apache.aries.blueprint.reflect.MetadataUtil;
 import org.apache.aries.blueprint.utils.HeaderParser;
 import org.apache.aries.blueprint.utils.JavaUtils;
 import org.apache.aries.blueprint.utils.HeaderParser.PathElement;
@@ -145,7 +144,7 @@
         this.handlers = handlers;
         this.pathList = pathList;
         this.converter = new AggregateConverter(this);
-        this.componentDefinitionRegistry = new ComponentDefinitionRegistryImpl();
+        this.componentDefinitionRegistry = new ComponentDefinitionRegistryImpl(this, bundleContext,
converter);
         this.executors = executors;
         this.processors = new ArrayList<Processor>();
         if (System.getSecurityManager() != null) {
@@ -250,10 +249,6 @@
                             eventDispatcher.blueprintEvent(new BlueprintEvent(BlueprintEvent.GRACE_PERIOD,
getBundleContext().getBundle(), getExtenderBundle(), missing.toArray(new String[missing.size()])));
                             return;
                         }
-                        componentDefinitionRegistry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintContainer",
this));
-                        componentDefinitionRegistry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintBundle",
bundleContext.getBundle()));
-                        componentDefinitionRegistry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintBundleContext",
bundleContext));
-                        componentDefinitionRegistry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintConverter",
converter));
                         if (xmlValidation) {
                             parser.validate(handlerSet.getSchema());
                         }

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/ComponentDefinitionRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/ComponentDefinitionRegistryImpl.java?rev=886718&r1=886717&r2=886718&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/ComponentDefinitionRegistryImpl.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/ComponentDefinitionRegistryImpl.java
Thu Dec  3 09:26:49 2009
@@ -31,7 +31,12 @@
 import org.apache.aries.blueprint.ComponentDefinitionRegistry;
 import org.apache.aries.blueprint.ComponentNameAlreadyInUseException;
 import org.apache.aries.blueprint.Interceptor;
+import org.apache.aries.blueprint.PassThroughMetadata;
 import org.apache.aries.blueprint.reflect.PassThroughMetadataImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.container.Converter;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
 import org.osgi.service.blueprint.reflect.Target;
 
@@ -44,16 +49,31 @@
  * @version $Rev: 760378 $, $Date: 2009-03-31 11:31:38 +0200 (Tue, 31 Mar 2009) $
  */
 public class ComponentDefinitionRegistryImpl implements ComponentDefinitionRegistry {
-
+    
+    private static final String COMP_ID_BLUEPRINT_CONVERTER = "blueprintConverter";
+    private static final String COMP_ID_BLUEPRINT_BUNDLE_CONTEXT = "blueprintBundleContext";
+    private static final String COMP_ID_BLUEPRINT_BUNDLE = "blueprintBundle";
+    private static final String COMP_ID_BLUEPRINT_CONTAINER = "blueprintContainer";
+    
     private final Map<String, ComponentMetadata> components;
     private final List<Target> typeConverters;
     private final Map<ComponentMetadata, List<Interceptor>> interceptors;
 
-    public ComponentDefinitionRegistryImpl() {
+    public ComponentDefinitionRegistryImpl(BlueprintContainer container, 
+            BundleContext applicationBundleContext, Converter blueprintConverter) {
         // Use a linked hash map to keep the declaration order 
         components = Collections.synchronizedMap(new LinkedHashMap<String, ComponentMetadata>());
         typeConverters = new CopyOnWriteArrayList<Target>();
         interceptors = Collections.synchronizedMap(new HashMap<ComponentMetadata, List<Interceptor>>());
+
+        registerComponentDefinition(
+                new PassThroughMetadataImpl(COMP_ID_BLUEPRINT_CONTAINER, container));
+        registerComponentDefinition(
+                new PassThroughMetadataImpl(COMP_ID_BLUEPRINT_BUNDLE, applicationBundleContext.getBundle()));
+        registerComponentDefinition(
+                new PassThroughMetadataImpl(COMP_ID_BLUEPRINT_BUNDLE_CONTEXT, applicationBundleContext));
+        registerComponentDefinition(
+                new PassThroughMetadataImpl(COMP_ID_BLUEPRINT_CONVERTER, blueprintConverter));
     }
 
     public boolean containsComponentDefinition(String name) {
@@ -124,5 +144,25 @@
     public List<Interceptor> getInterceptors(ComponentMetadata component) {
         return interceptors.get(component);
     }
+
+    public Bundle getBlueprintBundle() {
+        PassThroughMetadata meta = (PassThroughMetadata) components.get(COMP_ID_BLUEPRINT_BUNDLE);
+        return (Bundle) meta.getObject();
+    }
+
+    public BundleContext getBlueprintBundleContext() {
+        PassThroughMetadata meta = (PassThroughMetadata) components.get(COMP_ID_BLUEPRINT_BUNDLE_CONTEXT);
+        return (BundleContext) meta.getObject();
+    }
+
+    public BlueprintContainer getBlueprintContainer() {
+        PassThroughMetadata meta = (PassThroughMetadata) components.get(COMP_ID_BLUEPRINT_CONTAINER);
+        return (BlueprintContainer) meta.getObject();
+    }
+
+    public Converter getBlueprintConverter() {
+        PassThroughMetadata meta = (PassThroughMetadata) components.get(COMP_ID_BLUEPRINT_CONVERTER);
+        return (Converter) meta.getObject();
+    }
     
 }

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java?rev=886718&r1=886717&r2=886718&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java
Thu Dec  3 09:26:49 2009
@@ -18,18 +18,22 @@
  */
 package org.apache.aries.blueprint;
 
+import java.io.IOException;
 import java.net.URI;
 import java.util.Collections;
 import java.util.Set;
-import java.io.IOException;
 
 import javax.xml.validation.Schema;
 
 import junit.framework.TestCase;
+
 import org.apache.aries.blueprint.container.NamespaceHandlerRegistry;
 import org.apache.aries.blueprint.container.Parser;
 import org.apache.aries.blueprint.namespace.ComponentDefinitionRegistryImpl;
-import org.osgi.framework.Bundle;
+import org.apache.aries.unittest.mocks.Skeleton;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.container.Converter;
 import org.xml.sax.SAXException;
 
 public abstract class AbstractBlueprintTest extends TestCase {
@@ -59,7 +63,10 @@
     }
 
     protected ComponentDefinitionRegistryImpl parse(String name, NamespaceHandlerRegistry.NamespaceHandlerSet
handlers) throws Exception {
-        ComponentDefinitionRegistryImpl registry = new ComponentDefinitionRegistryImpl();
+        ComponentDefinitionRegistryImpl registry = new ComponentDefinitionRegistryImpl(
+                Skeleton.newMock(BlueprintContainer.class),
+                Skeleton.newMock(BundleContext.class),
+                Skeleton.newMock(Converter.class));
         Parser parser = new Parser();
         parser.parse(Collections.singletonList(getClass().getResource(name)));
         parser.populate(handlers, registry);

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java?rev=886718&r1=886717&r2=886718&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java
Thu Dec  3 09:26:49 2009
@@ -30,10 +30,9 @@
         super(new TestBundleContext(), null, null, null, null, null);
         this.registry = registry;
         if (registry != null) {
+            // overwrite the dummy container with something proper because it is needed somewhere
+            registry.removeComponentDefinition("blueprintContainer");
             registry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintContainer",
this));
-            registry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintBundle",
getBundleContext().getBundle()));
-            registry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintBundleContext",
getBundleContext()));
-            registry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintConverter",
getConverter()));
         }
     }
 

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/WiringTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/WiringTest.java?rev=886718&r1=886717&r2=886718&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/WiringTest.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/WiringTest.java
Thu Dec  3 09:26:49 2009
@@ -411,6 +411,14 @@
         assertNotNull(repository.create("c3"));
     }
     
+    public void testDefaultBeans() throws Exception {
+        ComponentDefinitionRegistryImpl registry = parse("/test-circular.xml");
+        assertNotNull(registry.getBlueprintContainer());
+        assertNotNull(registry.getBlueprintBundle());
+        assertNotNull(registry.getBlueprintBundleContext());
+        assertNotNull(registry.getBlueprintConverter());
+    }
+    
     private TestBlueprintContainer createBlueprintContainer() throws Exception {
         ComponentDefinitionRegistryImpl registry = parse("/test-circular.xml");
         return new TestBlueprintContainer(registry);



Mime
View raw message