geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r764886 - in /geronimo/sandbox/blueprint/org.apache.felix.blueprint/src: main/java/org/apache/felix/blueprint/context/ test/java/org/apache/felix/blueprint/
Date Tue, 14 Apr 2009 17:17:03 GMT
Author: gawor
Date: Tue Apr 14 17:17:02 2009
New Revision: 764886

URL: http://svn.apache.org/viewvc?rev=764886&view=rev
Log:
quick hack to get things working again: make sure to use Bundle.loadClass() to load classes

Modified:
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java?rev=764886&r1=764885&r2=764886&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
Tue Apr 14 17:17:02 2009
@@ -26,6 +26,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.xbean.recipe.Option;
 import org.apache.xbean.recipe.Repository;
 import org.apache.xbean.recipe.DefaultRepository;
 import org.apache.xbean.recipe.ObjectRecipe;
@@ -34,6 +35,7 @@
 import org.apache.xbean.recipe.ConstructionException;
 import org.apache.xbean.recipe.ReferenceRecipe;
 import org.apache.xbean.recipe.Recipe;
+import org.osgi.framework.Bundle;
 import org.osgi.service.blueprint.namespace.ComponentDefinitionRegistry;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
 import org.osgi.service.blueprint.reflect.LocalComponentMetadata;
@@ -58,7 +60,13 @@
  */
 public class Instanciator {
 
-    public static Repository createRepository(ComponentDefinitionRegistry registry) throws
Exception {
+    private Bundle bundle;
+    
+    public Instanciator(Bundle bundle) {
+        this.bundle = bundle;
+    }
+    
+    public Repository createRepository(ComponentDefinitionRegistry registry) throws Exception
{
         Repository repository = new DefaultRepository();
         // Create recipes
         for (String name : (Set<String>) registry.getComponentDefinitionNames()) {
@@ -69,10 +77,11 @@
         return repository;
     }
 
-    private static Recipe createRecipe(ComponentMetadata component) {
+    private Recipe createRecipe(ComponentMetadata component) {
         if (component instanceof LocalComponentMetadata) {
             LocalComponentMetadata local = (LocalComponentMetadata) component;
-            ObjectRecipe recipe = new ObjectRecipe(local.getClassName());
+            ObjectRecipe recipe = new BundleObjectRecipe(local.getClassName());
+            recipe.allow(Option.PRIVATE_PROPERTIES);
             recipe.setName(component.getName());
             for (PropertyInjectionMetadata property : (Collection<PropertyInjectionMetadata>)
local.getPropertyInjectionMetadata()) {
                 Object value = getValue(property.getValue());
@@ -92,7 +101,7 @@
         }
     }
 
-    private static Object getValue(Value v) {
+    private Object getValue(Value v) {
         if (v instanceof NullValue) {
             return null;
         } else if (v instanceof TypedStringValue) {
@@ -138,5 +147,27 @@
             throw new IllegalStateException("Unsupported value: " + v.getClass().getName());
         }
     }
+    
+    private class BundleObjectRecipe extends ObjectRecipe {
+        
+        String typeName;
+        
+        public BundleObjectRecipe(String typeName) {
+            super(typeName);
+            this.typeName = typeName;
+        }
+        
+        @Override
+        public Class getType() {
+            if (bundle == null) {
+                return super.getType();
+            }
+            try {
+                return bundle.loadClass(typeName);
+            } catch (ClassNotFoundException e) {
+                throw new ConstructionException("Type class could not be found: " + typeName);
+            }
+        }
+    }
 
 }

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java?rev=764886&r1=764885&r2=764886&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java
Tue Apr 14 17:17:02 2009
@@ -61,7 +61,8 @@
             Parser parser = new Parser();
             parser.parse(urls);
             componentDefinitionRegistry = parser.getRegistry();
-            Repository repository = Instanciator.createRepository(componentDefinitionRegistry);
+            Instanciator i = new Instanciator(bundleContext.getBundle());
+            Repository repository = i.createRepository(componentDefinitionRegistry);
             ObjectGraph graph = new ObjectGraph(repository);
             graph.createAll(new ArrayList<String>(componentDefinitionRegistry.getComponentDefinitionNames()));
             sender.sendCreated(this);

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java?rev=764886&r1=764885&r2=764886&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
Tue Apr 14 17:17:02 2009
@@ -32,7 +32,8 @@
     public void testWiring() throws Exception {
         Parser parser = parse("/test-wiring.xml");
 
-        Repository repository = Instanciator.createRepository(parser.getRegistry());
+        Instanciator i = new Instanciator(null);
+        Repository repository = i.createRepository(parser.getRegistry());
         ObjectGraph graph = new ObjectGraph(repository);
         Object obj = graph.create("pojoA");
         assertNotNull(obj);



Mime
View raw message