aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tjwat...@apache.org
Subject svn commit: r1684451 [2/4] - in /aries/branches/subsystemsR6: ./ application/application-itests/ application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/ async/ blueprint/blueprint-authz/ blueprint/blueprint-authz/src/m...
Date Tue, 09 Jun 2015 15:33:26 GMT
Modified: aries/branches/subsystemsR6/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryTest.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryTest.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryTest.java Tue Jun  9 15:33:24 2015
@@ -21,6 +21,8 @@ package org.apache.aries.blueprint.itest
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.ops4j.pax.exam.CoreOptions.keepCaches;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
 
 import java.io.InputStream;
 import java.util.Hashtable;
@@ -33,7 +35,6 @@ import org.apache.aries.blueprint.itests
 import org.apache.aries.blueprint.itests.cm.service.FooFactory;
 import org.apache.aries.blueprint.itests.cm.service.FooInterface;
 import org.junit.Test;
-import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.ProbeBuilder;
 import org.ops4j.pax.exam.TestProbeBuilder;
@@ -45,46 +46,49 @@ import org.osgi.service.cm.Configuration
 import org.osgi.service.cm.ConfigurationAdmin;
 
 public class ManagedServiceFactoryTest extends AbstractBlueprintIntegrationTest {
-	@Inject
-	ConfigurationAdmin ca;
-	
-	@ProbeBuilder
-	public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
-		probe.setHeader(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName());
-    	probe.setHeader(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName());
-		return probe;
-	}
+    private static final String TEST_BUNDLE = "org.apache.aries.blueprint.cm.test.b1";
+
+    @Inject
+    ConfigurationAdmin ca;
+
+    @ProbeBuilder
+    public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
+        probe.setHeader(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName());
+        probe.setHeader(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName());
+        return probe;
+    }
 
     @org.ops4j.pax.exam.Configuration
     public Option[] config() {
-    	InputStream testBundle = TinyBundles.bundle()
-    		.add(FooInterface.class)
-    		.add(Foo.class)
-    		.add(FooFactory.class)
-    		.add("OSGI-INF/blueprint/context.xml", 
-    				getResource("ManagedServiceFactoryTest.xml"))
-    		.set(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName())
-    		.set(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName())
-    		.build(TinyBundles.withBnd());
-    	return new Option[] {
-    			baseOptions(),
-    			Helper.blueprintBundles(),
-    			CoreOptions.keepCaches(),
-    			CoreOptions.streamBundle(testBundle)
-    	};
+        return new Option[] {
+            baseOptions(), 
+            Helper.blueprintBundles(), 
+            keepCaches(),
+            streamBundle(testBundle())
+        };
     }
-    
 
+    protected InputStream testBundle() {
+        return TinyBundles.bundle() //
+            .add(FooInterface.class) //
+            .add(Foo.class) //
+            .add(FooFactory.class) //
+            .add("OSGI-INF/blueprint/context.xml", getResource("ManagedServiceFactoryTest.xml"))
+            .set(Constants.BUNDLE_SYMBOLICNAME, TEST_BUNDLE) //
+            .set(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName()) //
+            .set(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName()) //
+            .build(TinyBundles.withBnd());
+    }
 
     @Test
     public void test1() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory", null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
-        
-		@SuppressWarnings("rawtypes")
-		ServiceReference sr = getServiceRef(Foo.class, "(key=foo1)");
+
+        @SuppressWarnings("rawtypes")
+        ServiceReference sr = getServiceRef(Foo.class, "(key=foo1)");
         Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
@@ -92,7 +96,7 @@ public class ManagedServiceFactoryTest e
         assertEquals("5", sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
@@ -110,20 +114,20 @@ public class ManagedServiceFactoryTest e
     @Test
     public void test2() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory2", null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
 
         @SuppressWarnings("rawtypes")
-		ServiceReference sr = getServiceRef(Foo.class, "(key=foo2)");
-		Foo foo = (Foo)context().getService(sr);
+        ServiceReference sr = getServiceRef(Foo.class, "(key=foo2)");
+        Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
         assertEquals("default", foo.getB());
         assertNull(sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
@@ -138,26 +142,24 @@ public class ManagedServiceFactoryTest e
         assertNull(sr.getProperty("b"));
     }
 
-
-
     @Test
     public void test3() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3", null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
 
         @SuppressWarnings("rawtypes")
-		ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
+        ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
         assertNotNull(sr);
-        Foo foo = (Foo) context().getService(sr);
+        Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
         assertEquals("default", foo.getB());
         assertEquals("5", sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
@@ -174,41 +176,41 @@ public class ManagedServiceFactoryTest e
     }
 
     @SuppressWarnings("rawtypes")
-	@Test
+    @Test
     public void testCreateAndUpdate() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3", null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
 
         Configuration cf2 = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3", null);
-        Hashtable<String,String> props2 = new Hashtable<String,String>();
+        Hashtable<String, String> props2 = new Hashtable<String, String>();
         props2.put("a", "7");
         cf2.update(props2);
 
         ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
         ServiceReference sr2 = getServiceRef(Foo.class, "(&(key=foo3)(a=7))");
 
-        Foo foo = (Foo) context().getService(sr);
+        Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
         assertEquals("default", foo.getB());
         assertEquals("5", sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        Foo foo2 = (Foo) context().getService(sr2);
+        Foo foo2 = (Foo)context().getService(sr2);
         assertNotNull(foo2);
         assertEquals(7, foo2.getA());
         assertEquals("default", foo2.getB());
         assertEquals("7", sr2.getProperty("a"));
         assertNull(sr2.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
 
-        props2 = new Hashtable<String,String>();
+        props2 = new Hashtable<String, String>();
         props2.put("a", "7");
         props2.put("b", "foo2");
         cf2.update(props2);
@@ -233,110 +235,111 @@ public class ManagedServiceFactoryTest e
         cf2.delete();
     }
 
-  @SuppressWarnings("rawtypes")
-@Test
-  public void testCreateAndUpdateUsingUpdateMethod() throws Exception {
-    Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4", null);
-    Hashtable<String, String> props = new Hashtable<String, String>();
-    props.put("a", "5");
-    cf.update(props);
-
-    Configuration cf2 = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4", null);
-    Hashtable<String, String> props2 = new Hashtable<String, String>();
-    props2.put("a", "7");
-    cf2.update(props2);
-
-    ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo4)(a=5))");
-    ServiceReference sr2 = getServiceRef(Foo.class, "(&(key=foo4)(a=7))");
-
-    Foo foo = (Foo) context().getService(sr);
-    assertNotNull(foo);
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-
-    Foo foo2 = (Foo) context().getService(sr2);
-    assertNotNull(foo2);
-    assertEquals(7, foo2.getA());
-    assertEquals("default", foo2.getB());
-    assertEquals("7", sr2.getProperty("a"));
-    assertNull(sr2.getProperty("b"));
-
-    props = new Hashtable<String, String>();
-    props.put("a", "5");
-    props.put("b", "foo");
-    cf.update(props);
-
-    props2 = new Hashtable<String, String>();
-    props2.put("a", "7");
-    props2.put("b", "foo2");
-    cf2.update(props2);
-
-    // Update after creation
-    Thread.sleep(500);
-    assertEquals(5, foo.getA());
-    assertEquals("foo", foo.getB());
-
-    // Update of service properties
-    assertEquals("5", sr.getProperty("a"));
-    assertEquals("foo", sr.getProperty("b"));
-
-    // 2a Update after creation
-    assertEquals(7, foo2.getA());
-    assertEquals("foo2", foo2.getB());
-
-    // 2b Update of service properties
-    assertEquals("7", sr2.getProperty("a"));
-    assertEquals("foo2", sr2.getProperty("b"));
-  }
-  
-  @Test
-  public void testFactoryCreation() throws Exception {
-    Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory5", null);
-    Hashtable<String, String> props = new Hashtable<String, String>();
-    props.put("a", "5");
-    cf.update(props);
+    @SuppressWarnings("rawtypes")
+    @Test
+    public void testCreateAndUpdateUsingUpdateMethod() throws Exception {
+        Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4", null);
+        Hashtable<String, String> props = new Hashtable<String, String>();
+        props.put("a", "5");
+        cf.update(props);
+
+        Configuration cf2 = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4", null);
+        Hashtable<String, String> props2 = new Hashtable<String, String>();
+        props2.put("a", "7");
+        cf2.update(props2);
+
+        ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo4)(a=5))");
+        ServiceReference sr2 = getServiceRef(Foo.class, "(&(key=foo4)(a=7))");
+
+        Foo foo = (Foo)context().getService(sr);
+        assertNotNull(foo);
+        assertEquals(5, foo.getA());
+        assertEquals("default", foo.getB());
+        assertEquals("5", sr.getProperty("a"));
+        assertNull(sr.getProperty("b"));
+
+        Foo foo2 = (Foo)context().getService(sr2);
+        assertNotNull(foo2);
+        assertEquals(7, foo2.getA());
+        assertEquals("default", foo2.getB());
+        assertEquals("7", sr2.getProperty("a"));
+        assertNull(sr2.getProperty("b"));
+
+        props = new Hashtable<String, String>();
+        props.put("a", "5");
+        props.put("b", "foo");
+        cf.update(props);
+
+        props2 = new Hashtable<String, String>();
+        props2.put("a", "7");
+        props2.put("b", "foo2");
+        cf2.update(props2);
+
+        // Update after creation
+        Thread.sleep(500);
+        assertEquals(5, foo.getA());
+        assertEquals("foo", foo.getB());
+
+        // Update of service properties
+        assertEquals("5", sr.getProperty("a"));
+        assertEquals("foo", sr.getProperty("b"));
+
+        // 2a Update after creation
+        assertEquals(7, foo2.getA());
+        assertEquals("foo2", foo2.getB());
+
+        // 2b Update of service properties
+        assertEquals("7", sr2.getProperty("a"));
+        assertEquals("foo2", sr2.getProperty("b"));
+    }
+
+    @Test
+    public void testFactoryCreation() throws Exception {
+        Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory5", null);
+        Hashtable<String, String> props = new Hashtable<String, String>();
+        props.put("a", "5");
+        cf.update(props);
+
+        @SuppressWarnings("rawtypes")
+        ServiceReference sr = getServiceRef(Foo.class, "(key=foo5)");
+        Foo foo = (Foo)context().getService(sr);
+        assertNotNull(foo);
+        assertEquals(5, foo.getA());
+        assertEquals("default", foo.getB());
+        assertEquals("5", sr.getProperty("a"));
+        assertNull(sr.getProperty("b"));
+
+        props = new Hashtable<String, String>();
+        props.put("a", "5");
+        props.put("b", "foo");
+        cf.update(props);
+        Thread.sleep(500);
+
+        // No update of bean after creation
+        assertEquals(5, foo.getA());
+        assertEquals("default", foo.getB());
+
+        // Only initial update of service properties
+        assertEquals("5", sr.getProperty("a"));
+        assertNull(sr.getProperty("b"));
+    }
 
     @SuppressWarnings("rawtypes")
-	ServiceReference sr = getServiceRef(Foo.class, "(key=foo5)");
-    Foo foo = (Foo) context().getService(sr);
-    assertNotNull(foo);
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-
-    props = new Hashtable<String, String>();
-    props.put("a", "5");
-    props.put("b", "foo");
-    cf.update(props);
-    Thread.sleep(500);
-
-    // No update of bean after creation
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-
-    // Only initial update of service properties
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-  }
-  
-	@SuppressWarnings("rawtypes")
-	private ServiceReference getServiceRef(Class serviceInterface, String filter) throws InvalidSyntaxException {
-		int tries = 0;
-		do {
-			 ServiceReference[] srAr = bundleContext.getServiceReferences(serviceInterface.getName(), filter);
-			 if (srAr != null && srAr.length > 0) {
-				 return (ServiceReference) srAr[0];
-			 }
-			 tries ++;
-			 try {
-				Thread.sleep(100);
-			} catch (InterruptedException e) {
-				// Ignore
-			}
-		}  while (tries < 100);
-      throw new RuntimeException("Could not find service " + serviceInterface.getName() + ", " + filter);
-	}
+    private ServiceReference getServiceRef(Class serviceInterface, String filter)
+        throws InvalidSyntaxException {
+        int tries = 0;
+        do {
+            ServiceReference[] srAr = bundleContext.getServiceReferences(serviceInterface.getName(), filter);
+            if (srAr != null && srAr.length > 0) {
+                return (ServiceReference)srAr[0];
+            }
+            tries++;
+            try {
+                Thread.sleep(100);
+            } catch (InterruptedException e) {
+                // Ignore
+            }
+        } while (tries < 100);
+        throw new RuntimeException("Could not find service " + serviceInterface.getName() + ", " + filter);
+    }
 }

Modified: aries/branches/subsystemsR6/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryUseSystemBundleTest.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryUseSystemBundleTest.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryUseSystemBundleTest.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryUseSystemBundleTest.java Tue Jun  9 15:33:24 2015
@@ -18,381 +18,92 @@
  */
 package org.apache.aries.blueprint.itests.cm;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.ops4j.pax.exam.CoreOptions.keepCaches;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 
-import java.io.InputStream;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
 
-import javax.inject.Inject;
-
-import org.apache.aries.blueprint.itests.AbstractBlueprintIntegrationTest;
 import org.apache.aries.blueprint.itests.Helper;
-import org.apache.aries.blueprint.itests.cm.service.Foo;
-import org.apache.aries.blueprint.itests.cm.service.FooFactory;
-import org.apache.aries.blueprint.itests.cm.service.FooInterface;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Test;
-import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.ProbeBuilder;
-import org.ops4j.pax.exam.TestProbeBuilder;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.hooks.service.EventListenerHook;
 import org.osgi.framework.hooks.service.FindHook;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
 
-@SuppressWarnings({"rawtypes", "unchecked"})
-public class ManagedServiceFactoryUseSystemBundleTest extends AbstractBlueprintIntegrationTest {
-	private static final String CM_BUNDLE = "org.apache.aries.blueprint.cm";
-	private static final String TEST_BUNDLE = "org.apache.aries.blueprint.cm.test.b1";
-	@Inject
-	ConfigurationAdmin ca;
-	
-	@ProbeBuilder
-	public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
-		probe.setHeader(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName());
-    	probe.setHeader(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName());
-		return probe;
-	}
+/**
+ * Shows that the cm bundle can process config even if the events are hidden from it
+ * when the property to use the system bundle context is set
+ */
+@SuppressWarnings({"unchecked", "rawtypes"})
+public class ManagedServiceFactoryUseSystemBundleTest extends ManagedServiceFactoryTest {
+    private static final String CM_BUNDLE = "org.apache.aries.blueprint.cm";
 
     @org.ops4j.pax.exam.Configuration
     public Option[] config() {
-    	InputStream testBundle = TinyBundles.bundle()
-    		.add(FooInterface.class)
-    		.add(Foo.class)
-    		.add(FooFactory.class)
-    		.add("OSGI-INF/blueprint/context.xml", 
-    				getResource("ManagedServiceFactoryTest.xml"))
-    		.set(Constants.BUNDLE_SYMBOLICNAME, TEST_BUNDLE)
-    		.set(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName())
-    		.set(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName())
-    		.build(TinyBundles.withBnd());
-    	return new Option[] {
-    			baseOptions(),
-                CoreOptions.systemProperty("org.apache.aries.blueprint.use.system.context").value("true"),
-    			Helper.blueprintBundles(),
-    			CoreOptions.keepCaches(),
-    			CoreOptions.streamBundle(testBundle)
-    	};
-    }
-
-	ServiceRegistration eventHook;
-	ServiceRegistration findHook;
-	@Before
-	public void regiserHook() throws BundleException {
-		context().getBundleByName(CM_BUNDLE).stop();
-		final BundleContext systemContext = context().getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
-		eventHook = context().registerService(EventListenerHook.class, new EventListenerHook() {
-
-			@Override
-			public void event(ServiceEvent event,
-					Map contexts) {
-				if (CM_BUNDLE.equals(event.getServiceReference().getBundle().getSymbolicName())) {
-					// hide from everything but the system bundle
-					// TODO on R6 we should be able to even try hiding from the system bundle
-					// R5 it was not clear if hooks could hide from the system bundle
-					// equinox R5 does allow hiding from system bundle
-					contexts.keySet().retainAll(Collections.singleton(systemContext));
-				}
-			}
-
-		}, null);
-		findHook = context().registerService(FindHook.class, new FindHook(){
-			@Override
-			public void find(BundleContext context, String arg1, String arg2,
-					boolean arg3, Collection references) {
-				// hide from everything but the system bundle
-				// TODO on R6 we should be able to even try hiding from the system bundle
-				// R5 it was not clear if hooks could hide from the system bundle
-				// equinox R5 does allow hiding from system bundle
-				if (!context.equals(systemContext)) {
-					for (Iterator<ServiceReference> iReferences = references.iterator(); iReferences.hasNext();) {
-						if (CM_BUNDLE.equals(iReferences.next().getBundle().getSymbolicName())) {
-							iReferences.remove();
-						}
-					}
-				}
-			}
-			
-		}, null);
-		context().getBundleByName(CM_BUNDLE).start();
-	}
-
-	@After
-	public void unregisterHook() {
-		eventHook.unregister();
-		findHook.unregister();
-	}
-
-    @Test
-    public void test1() throws Exception {
-        Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory", null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
-        props.put("a", "5");
-        cf.update(props);
-        
-		ServiceReference sr = getServiceRef(Foo.class, "(key=foo1)");
-        Foo foo = (Foo)context().getService(sr);
-        assertNotNull(foo);
-        assertEquals(5, foo.getA());
-        assertEquals("default", foo.getB());
-        assertEquals("5", sr.getProperty("a"));
-        assertNull(sr.getProperty("b"));
-
-        props = new Hashtable<String,String>();
-        props.put("a", "5");
-        props.put("b", "foo");
-        cf.update(props);
-        Thread.sleep(500);
-
-        // No update of bean after creation
-        assertEquals(5, foo.getA());
-        assertEquals("default", foo.getB());
-
-        // Only initial update of service properties
-        assertEquals("5", sr.getProperty("a"));
-        assertNull(sr.getProperty("b"));
-    }
-
-    @Test
-    public void test2() throws Exception {
-        Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory2", null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
-        props.put("a", "5");
-        cf.update(props);
-
-		ServiceReference sr = getServiceRef(Foo.class, "(key=foo2)");
-		Foo foo = (Foo)context().getService(sr);
-        assertNotNull(foo);
-        assertEquals(5, foo.getA());
-        assertEquals("default", foo.getB());
-        assertNull(sr.getProperty("a"));
-        assertNull(sr.getProperty("b"));
-
-        props = new Hashtable<String,String>();
-        props.put("a", "5");
-        props.put("b", "foo");
-        cf.update(props);
-
-        // Update after creation
-        Thread.sleep(500);
-        assertEquals(5, foo.getA());
-        assertEquals("foo", foo.getB());
-
-        // No update of service properties
-        assertNull(sr.getProperty("a"));
-        assertNull(sr.getProperty("b"));
+        return new Option[] {
+            baseOptions(),
+            systemProperty("org.apache.aries.blueprint.use.system.context").value("true"),
+            Helper.blueprintBundles(), //
+            keepCaches(), //
+            streamBundle(testBundle())
+        };
     }
 
+    ServiceRegistration eventHook;
+    ServiceRegistration findHook;
 
+    @Before
+    public void regiserHook() throws BundleException {
+        context().getBundleByName(CM_BUNDLE).stop();
+        final BundleContext systemContext = context().getBundle(Constants.SYSTEM_BUNDLE_LOCATION)
+            .getBundleContext();
+        eventHook = context().registerService(EventListenerHook.class, new EventListenerHook() {
+            public void event(ServiceEvent event, Map contexts) {
+                if (CM_BUNDLE.equals(event.getServiceReference().getBundle().getSymbolicName())) {
+                    // hide from everything but the system bundle
+                    // TODO on R6 we should be able to even try hiding from the system bundle
+                    // R5 it was not clear if hooks could hide from the system bundle
+                    // equinox R5 does allow hiding from system bundle
+                    contexts.keySet().retainAll(Collections.singleton(systemContext));
+                }
+            }
+
+        }, null);
+        findHook = context().registerService(FindHook.class, new FindHook() {
+            public void find(BundleContext context, String arg1, String arg2, boolean arg3,
+                             Collection references) {
+                // hide from everything but the system bundle
+                // TODO on R6 we should be able to even try hiding from the system bundle
+                // R5 it was not clear if hooks could hide from the system bundle
+                // equinox R5 does allow hiding from system bundle
+                if (!context.equals(systemContext)) {
+                    for (Iterator<ServiceReference> iReferences = references.iterator(); iReferences
+                        .hasNext();) {
+                        if (CM_BUNDLE.equals(iReferences.next().getBundle().getSymbolicName())) {
+                            iReferences.remove();
+                        }
+                    }
+                }
+            }
 
-    @Test
-    public void test3() throws Exception {
-        Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3", null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
-        props.put("a", "5");
-        cf.update(props);
-
-		ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
-        assertNotNull(sr);
-        Foo foo = (Foo) context().getService(sr);
-        assertNotNull(foo);
-        assertEquals(5, foo.getA());
-        assertEquals("default", foo.getB());
-        assertEquals("5", sr.getProperty("a"));
-        assertNull(sr.getProperty("b"));
-
-        props = new Hashtable<String,String>();
-        props.put("a", "5");
-        props.put("b", "foo");
-        cf.update(props);
-
-        // Update after creation
-        Thread.sleep(500);
-        assertEquals(5, foo.getA());
-        assertEquals("foo", foo.getB());
-
-        // Update of service properties
-        assertEquals("5", sr.getProperty("a"));
-        assertEquals("foo", sr.getProperty("b"));
-        cf.delete();
+        }, null);
+        context().getBundleByName(CM_BUNDLE).start();
     }
 
-	@Test
-    public void testCreateAndUpdate() throws Exception {
-        Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3", null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
-        props.put("a", "5");
-        cf.update(props);
-
-        Configuration cf2 = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3", null);
-        Hashtable<String,String> props2 = new Hashtable<String,String>();
-        props2.put("a", "7");
-        cf2.update(props2);
-
-        ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
-        ServiceReference sr2 = getServiceRef(Foo.class, "(&(key=foo3)(a=7))");
-
-        Foo foo = (Foo) context().getService(sr);
-        assertNotNull(foo);
-        assertEquals(5, foo.getA());
-        assertEquals("default", foo.getB());
-        assertEquals("5", sr.getProperty("a"));
-        assertNull(sr.getProperty("b"));
-
-        Foo foo2 = (Foo) context().getService(sr2);
-        assertNotNull(foo2);
-        assertEquals(7, foo2.getA());
-        assertEquals("default", foo2.getB());
-        assertEquals("7", sr2.getProperty("a"));
-        assertNull(sr2.getProperty("b"));
-
-        props = new Hashtable<String,String>();
-        props.put("a", "5");
-        props.put("b", "foo");
-        cf.update(props);
-
-        props2 = new Hashtable<String,String>();
-        props2.put("a", "7");
-        props2.put("b", "foo2");
-        cf2.update(props2);
-
-        // Update after creation
-        Thread.sleep(500);
-        assertEquals(5, foo.getA());
-        assertEquals("foo", foo.getB());
-
-        // Update of service properties
-        assertEquals("5", sr.getProperty("a"));
-        assertEquals("foo", sr.getProperty("b"));
-
-        // 2a Update after creation
-        assertEquals(7, foo2.getA());
-        assertEquals("foo2", foo2.getB());
-
-        // 2b Update of service properties
-        assertEquals("7", sr2.getProperty("a"));
-        assertEquals("foo2", sr2.getProperty("b"));
-        cf.delete();
-        cf2.delete();
+    @After
+    public void unregisterHook() {
+        eventHook.unregister();
+        findHook.unregister();
     }
 
-  @Test
-  public void testCreateAndUpdateUsingUpdateMethod() throws Exception {
-    Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4", null);
-    Hashtable<String, String> props = new Hashtable<String, String>();
-    props.put("a", "5");
-    cf.update(props);
-
-    Configuration cf2 = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4", null);
-    Hashtable<String, String> props2 = new Hashtable<String, String>();
-    props2.put("a", "7");
-    cf2.update(props2);
-
-    ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo4)(a=5))");
-    ServiceReference sr2 = getServiceRef(Foo.class, "(&(key=foo4)(a=7))");
-
-    Foo foo = (Foo) context().getService(sr);
-    assertNotNull(foo);
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-
-    Foo foo2 = (Foo) context().getService(sr2);
-    assertNotNull(foo2);
-    assertEquals(7, foo2.getA());
-    assertEquals("default", foo2.getB());
-    assertEquals("7", sr2.getProperty("a"));
-    assertNull(sr2.getProperty("b"));
-
-    props = new Hashtable<String, String>();
-    props.put("a", "5");
-    props.put("b", "foo");
-    cf.update(props);
-
-    props2 = new Hashtable<String, String>();
-    props2.put("a", "7");
-    props2.put("b", "foo2");
-    cf2.update(props2);
-
-    // Update after creation
-    Thread.sleep(500);
-    assertEquals(5, foo.getA());
-    assertEquals("foo", foo.getB());
-
-    // Update of service properties
-    assertEquals("5", sr.getProperty("a"));
-    assertEquals("foo", sr.getProperty("b"));
-
-    // 2a Update after creation
-    assertEquals(7, foo2.getA());
-    assertEquals("foo2", foo2.getB());
-
-    // 2b Update of service properties
-    assertEquals("7", sr2.getProperty("a"));
-    assertEquals("foo2", sr2.getProperty("b"));
-  }
-  
-  @Test
-  public void testFactoryCreation() throws Exception {
-    Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory5", null);
-    Hashtable<String, String> props = new Hashtable<String, String>();
-    props.put("a", "5");
-    cf.update(props);
-
-	ServiceReference sr = getServiceRef(Foo.class, "(key=foo5)");
-    Foo foo = (Foo) context().getService(sr);
-    assertNotNull(foo);
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-
-    props = new Hashtable<String, String>();
-    props.put("a", "5");
-    props.put("b", "foo");
-    cf.update(props);
-    Thread.sleep(500);
-
-    // No update of bean after creation
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-
-    // Only initial update of service properties
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-  }
-  
-	private ServiceReference getServiceRef(Class serviceInterface, String filter) throws InvalidSyntaxException {
-		int tries = 0;
-		do {
-			 ServiceReference[] srAr = bundleContext.getServiceReferences(serviceInterface.getName(), filter);
-			 if (srAr != null && srAr.length > 0) {
-				 return (ServiceReference) srAr[0];
-			 }
-			 tries ++;
-			 try {
-				Thread.sleep(100);
-			} catch (InterruptedException e) {
-				// Ignore
-			}
-		}  while (tries < 100);
-      throw new RuntimeException("Could not find service " + serviceInterface.getName() + ", " + filter);
-	}
 }

Propchange: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jun  9 15:33:24 2015
@@ -0,0 +1,7 @@
+*.iml
+target
+.settings
+.classpath
+.project
+velocity.log
+.externalToolBuilders

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/pom.xml?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/pom.xml (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/pom.xml Tue Jun  9 15:33:24 2015
@@ -31,7 +31,7 @@
     <groupId>org.apache.aries.blueprint</groupId>
     <artifactId>blueprint-maven-plugin</artifactId>
     <packaging>maven-plugin</packaging>
-    <version>1.0.1-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
     <name>Apache Aries Blueprint Maven Plugin</name>
     <description>
         Maven plugin to create blueprint files from annotations
@@ -52,13 +52,47 @@
         <plugins>
             <plugin>
                 <artifactId>maven-compiler-plugin</artifactId>
-                <version>3.1</version>
                 <configuration>
                     <target>1.7</target>
                     <source>1.7</source>
                 </configuration>
             </plugin>
         </plugins>
+        <pluginManagement>
+        	<plugins>
+        		<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
+        		<plugin>
+        			<groupId>org.eclipse.m2e</groupId>
+        			<artifactId>lifecycle-mapping</artifactId>
+        			<version>1.0.0</version>
+        			<configuration>
+        				<lifecycleMappingMetadata>
+        					<pluginExecutions>
+        						<pluginExecution>
+        							<pluginExecutionFilter>
+        								<groupId>
+        									org.apache.maven.plugins
+        								</groupId>
+        								<artifactId>
+        									maven-plugin-plugin
+        								</artifactId>
+        								<versionRange>
+        									[3.2,)
+        								</versionRange>
+        								<goals>
+        									<goal>descriptor</goal>
+        								</goals>
+        							</pluginExecutionFilter>
+        							<action>
+        								<ignore />
+        							</action>
+        						</pluginExecution>
+        					</pluginExecutions>
+        				</lifecycleMappingMetadata>
+        			</configuration>
+        		</plugin>
+        	</plugins>
+        </pluginManagement>
     </build>
 
     <dependencies>
@@ -73,6 +107,11 @@
             <version>1.2</version>
         </dependency>
         <dependency>
+            <groupId>javax.enterprise</groupId>
+            <artifactId>cdi-api</artifactId>
+            <version>1.2</version>
+        </dependency>
+        <dependency>
             <groupId>javax.persistence</groupId>
             <artifactId>persistence-api</artifactId>
             <version>1.0.2</version>

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java Tue Jun  9 15:33:24 2015
@@ -21,6 +21,7 @@ package org.apache.aries.blueprint.plugi
 import java.io.OutputStream;
 import java.lang.reflect.Field;
 
+import javax.persistence.PersistenceContext;
 import javax.persistence.PersistenceUnit;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
@@ -28,7 +29,8 @@ import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.aries.blueprint.plugin.model.Bean;
 import org.apache.aries.blueprint.plugin.model.Context;
-import org.apache.aries.blueprint.plugin.model.OsgiServiceBean;
+import org.apache.aries.blueprint.plugin.model.OsgiServiceRef;
+import org.apache.aries.blueprint.plugin.model.ProducedBean;
 import org.apache.aries.blueprint.plugin.model.Property;
 import org.apache.aries.blueprint.plugin.model.PropertyWriter;
 import org.apache.aries.blueprint.plugin.model.TransactionalDef;
@@ -88,6 +90,9 @@ public class Generator implements Proper
         writer.writeAttribute("id", bean.id);
         writer.writeAttribute("class", bean.clazz.getName());
         writer.writeAttribute("ext", NS_EXT, "field-injection", "true");
+        if (bean instanceof ProducedBean) {
+            writeFactory((ProducedBean)bean);
+        }
         if (bean.initMethod != null) {
             writer.writeAttribute("init-method", bean.initMethod);
         }
@@ -97,11 +102,14 @@ public class Generator implements Proper
         writer.writeCharacters("\n");
         writeTransactional(bean.transactionDef);
 
-        if (bean.persistenceUnitField != null) {
-            writePersistenceUnit(bean.persistenceUnitField);
-        }
+        writePersistenceFields(bean.persistenceFields);
     }
     
+    private void writeFactory(ProducedBean bean) throws XMLStreamException {
+        writer.writeAttribute("factory-ref", bean.factoryBeanId);
+        writer.writeAttribute("factory-method", bean.factoryMethod);
+    }
+
     private void writeTransactional(TransactionalDef transactionDef)
             throws XMLStreamException {
         if (transactionDef != null) {
@@ -113,24 +121,39 @@ public class Generator implements Proper
         }
     }
 
-    private void writePersistenceUnit(Field field) throws XMLStreamException {
-        PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
-        if (persistenceUnit !=null) {
+    
+    private void writePersistenceFields(Field[] fields) throws XMLStreamException {
+        for (Field field : fields) {
+            writePersistenceField(field);
+        }
+    }
+
+    private void writePersistenceField(Field field) throws XMLStreamException {
+        PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
+        if (persistenceContext != null) {
             writer.writeCharacters("    ");
             writer.writeEmptyElement("jpa", "context", NS_JPA);
+            writer.writeAttribute("unitname", persistenceContext.unitName());
+            writer.writeAttribute("property", field.getName());
+            writer.writeCharacters("\n");
+        }
+        PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
+        if (persistenceUnit != null) {
+            writer.writeCharacters("    ");
+            writer.writeEmptyElement("jpa", "unit", NS_JPA);
             writer.writeAttribute("unitname", persistenceUnit.unitName());
             writer.writeAttribute("property", field.getName());
             writer.writeCharacters("\n");
         }
     }
-    
+
     private void writeServiceRefs() throws XMLStreamException {
-        for (OsgiServiceBean serviceBean : context.getServiceRefs()) {
+        for (OsgiServiceRef serviceBean : context.getServiceRefs()) {
             writeServiceRef(serviceBean);
         }
     }
 
-    private void writeServiceRef(OsgiServiceBean serviceBean) throws XMLStreamException {
+    private void writeServiceRef(OsgiServiceRef serviceBean) throws XMLStreamException {
         writer.writeEmptyElement("reference");
         writer.writeAttribute("id", serviceBean.id);
         writer.writeAttribute("interface", serviceBean.clazz.getName());

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java Tue Jun  9 15:33:24 2015
@@ -21,28 +21,26 @@ package org.apache.aries.blueprint.plugi
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
-import javax.inject.Named;
+import javax.persistence.PersistenceContext;
 import javax.persistence.PersistenceUnit;
 
-import org.springframework.stereotype.Component;
-
-public class Bean implements Comparable<Bean>{
-    public String id;
-    public Class<?> clazz;
+public class Bean extends BeanRef {
     public String initMethod;
     public String destroyMethod;
     public SortedSet<Property> properties;
-    public Field persistenceUnitField;
-    public TransactionalDef transactionDef; 
-    
+    public Field[] persistenceFields;
+    public TransactionalDef transactionDef;
+
     public Bean(Class<?> clazz) {
-        this.clazz = clazz;
-        this.id = getBeanName(clazz);
+        super(clazz);
+
         for (Method method : clazz.getDeclaredMethods()) {
             PostConstruct postConstruct = getEffectiveAnnotation(method, PostConstruct.class);
             if (postConstruct != null) {
@@ -53,7 +51,7 @@ public class Bean implements Comparable<
                 this.destroyMethod = method.getName();
             }
         }
-        this.persistenceUnitField = getPersistenceUnit();
+        this.persistenceFields = getPersistenceFields();
         this.transactionDef = new JavaxTransactionFactory().create(clazz);
         if (this.transactionDef == null) {
             this.transactionDef = new SpringTransactionFactory().create(clazz);
@@ -61,20 +59,22 @@ public class Bean implements Comparable<
         properties = new TreeSet<Property>();
     }
 
-    private Field getPersistenceUnit() {
+    private Field[] getPersistenceFields() {
+        List<Field> persistenceFields = new ArrayList<Field>();
         Field[] fields = clazz.getDeclaredFields();
         for (Field field : fields) {
+            PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
             PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
-            if (persistenceUnit !=null) {
-                 return field;
+            if (persistenceContext !=null || persistenceUnit != null) {
+                 persistenceFields.add(field);
             }
         }
-        return null;
+        return persistenceFields.toArray(new Field[]{});
     }
     
     public void resolve(Matcher matcher) {
         Class<?> curClass = this.clazz;
-        while (curClass != Object.class) {
+        while (curClass != null && curClass != Object.class) {
             resolveProperties(matcher, curClass);
             curClass = curClass.getSuperclass();
         }
@@ -89,23 +89,6 @@ public class Bean implements Comparable<
         }
     }
 
-    public static String getBeanName(Class<?> clazz) {
-        Component component = clazz.getAnnotation(Component.class);
-        Named named = clazz.getAnnotation(Named.class);
-        if (component != null && !"".equals(component.value())) {
-            return component.value();
-        } else if (named != null && !"".equals(named.value())) {
-            return named.value();    
-        } else {
-            String name = clazz.getSimpleName();
-            return getBeanNameFromSimpleName(name);
-        }
-    }
-
-    private static String getBeanNameFromSimpleName(String name) {
-        return name.substring(0, 1).toLowerCase() + name.substring(1, name.length());
-    }
-    
     private static <T extends Annotation> T getEffectiveAnnotation(Method method, Class<T> annotationClass) {
         final Class<?> methodClass = method.getDeclaringClass();
         final String name = method.getName();
@@ -144,17 +127,7 @@ public class Bean implements Comparable<
             return null;
         }
     }
-    
 
-    public boolean matches(Class<?> destType, String destId) {
-        boolean assignable = destType.isAssignableFrom(this.clazz);
-        return assignable && ((destId == null) || id.equals(destId));
-    }
-
-    @Override
-    public int compareTo(Bean other) {
-        return this.clazz.getName().compareTo(other.clazz.getName());
-    }
 
     @Override
     public int hashCode() {

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java Tue Jun  9 15:33:24 2015
@@ -19,28 +19,32 @@
 package org.apache.aries.blueprint.plugin.model;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import javax.inject.Named;
+import javax.enterprise.inject.Produces;
 
 import org.ops4j.pax.cdi.api.OsgiService;
-import org.springframework.beans.factory.annotation.Qualifier;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.container.Converter;
 
 public class Context implements Matcher {
 
     SortedSet<Bean> beans;
-    SortedSet<OsgiServiceBean> serviceRefs;
-    
+    SortedSet<OsgiServiceRef> serviceRefs;
+
     public Context(Class<?>... beanClasses) {
         this(Arrays.asList(beanClasses));
     }
 
     public Context(Collection<Class<?>> beanClasses) {
         this.beans = new TreeSet<Bean>();
-        this.serviceRefs = new TreeSet<OsgiServiceBean>();
+        this.serviceRefs = new TreeSet<OsgiServiceRef>();
         addBeans(beanClasses);
     }
 
@@ -49,6 +53,18 @@ public class Context implements Matcher
             Bean bean = new Bean(clazz);
             beans.add(bean);
             addServiceRefs(clazz);
+            addProducedBeans(clazz, bean.id);
+        }
+    }
+
+    private void addProducedBeans(Class<?> clazz, String factoryBeanId) {
+        for (Method method : clazz.getMethods()) {
+            Produces produces = method.getAnnotation(Produces.class);
+            if (produces != null) {
+                Class<?> producedClass = method.getReturnType();
+                ProducedBean producedBean = new ProducedBean(producedClass, factoryBeanId, method.getName());
+                beans.add(producedBean);
+            }
         }
     }
 
@@ -56,52 +72,50 @@ public class Context implements Matcher
         for (Field field : clazz.getDeclaredFields()) {
             OsgiService osgiService = field.getAnnotation(OsgiService.class);
             if (osgiService != null) {
-                serviceRefs.add(new OsgiServiceBean(field.getType(), osgiService));
+                serviceRefs.add(new OsgiServiceRef(field));
             }
         }
     }
-    
+
     public void resolve() {
         for (Bean bean : beans) {
             bean.resolve(this);
         }
     }
     
-    public Bean getMatching(Field field) {
-        String destId = getDestinationId(field);
-        // TODO Replace loop by lookup
+    public BeanRef getMatching(BeanRef template) {
         for (Bean bean : beans) {
-            if (bean.matches(field.getType(), destId)) {
+            if (bean.matches(template)) {
                 return bean;
             }
         }
-        for (Bean bean : serviceRefs) {
-            if (bean.matches(field.getType(), destId)) {
+        for (BeanRef bean : serviceRefs) {
+            if (bean.matches(template)) {
                 return bean;
             }
         }
+        if (template.clazz == BundleContext.class) {
+            return new BeanRef(BundleContext.class, "blueprintBundleContext");
+        }
+        if (template.clazz == Bundle.class) {
+            return new BeanRef(Bundle.class, "blueprintBundle");
+        }
+        if (template.clazz == BlueprintContainer.class) {
+            return new BeanRef(BlueprintContainer.class, "blueprintContainer");
+        }
+        if (template.clazz == Converter.class) {
+            return new BeanRef(Converter.class, "blueprintConverter");
+        }
+        
         return null;
     }
 
-	private String getDestinationId(Field field) {
-		Named named = field.getAnnotation(Named.class);
-		if (named != null) {
-			return named.value();
-		}
-		Qualifier qualifier = field.getAnnotation(Qualifier.class);
-        if (qualifier != null) {
-        	return qualifier.value();
-        }
-		return null;
-	}
-
     public SortedSet<Bean> getBeans() {
         return beans;
     }
-    
-    public SortedSet<OsgiServiceBean> getServiceRefs() {
+
+    public SortedSet<OsgiServiceRef> getServiceRefs() {
         return serviceRefs;
     }
 
-
 }

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java Tue Jun  9 15:33:24 2015
@@ -18,9 +18,8 @@
  */
 package org.apache.aries.blueprint.plugin.model;
 
-import java.lang.reflect.Field;
 
 
 public interface Matcher {
-    Bean getMatching(Field field);
+    BeanRef getMatching(BeanRef template);
 }

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java Tue Jun  9 15:33:24 2015
@@ -41,7 +41,7 @@ public class Property implements Compara
     public static Property create(Matcher matcher, Field field) {
         Value value = field.getAnnotation(Value.class);
         if (needsInject(field)) {
-            Bean matching = matcher.getMatching(field);
+            BeanRef matching = matcher.getMatching(new BeanRef(field));
             String ref = (matching == null) ? getRefName(field) : matching.id;
             return new Property(field.getName(), ref, null);
         } else if (value != null){

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java Tue Jun  9 15:33:24 2015
@@ -21,16 +21,33 @@ package org.apache.aries.blueprint.plugi
 import static java.util.Arrays.asList;
 import static org.apache.aries.blueprint.plugin.FilteredClassFinder.findClasses;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.Set;
 
-import org.apache.aries.blueprint.plugin.Generator;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+
 import org.apache.aries.blueprint.plugin.model.Context;
 import org.apache.aries.blueprint.plugin.test.MyBean1;
+import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.xbean.finder.ClassFinder;
+import org.junit.Assert;
 import org.junit.Test;
-
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
 
 public class GeneratorTest {
+
+    private XPath xpath;
+    private Document document;
+
     @Test
     public void testGenerate() throws Exception {
         ClassFinder classFinder = new ClassFinder(this.getClass().getClassLoader());
@@ -38,7 +55,45 @@ public class GeneratorTest {
         Set<Class<?>> beanClasses = findClasses(classFinder, asList(packageName));
         Context context = new Context(beanClasses);
         context.resolve();
-        new Generator(context, System.out).generate();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        new Generator(context, os).generate();
+        System.out.println(os.toString("UTF-8"));
+
+        document = readToDocument(os);
+        xpath = XPathFactory.newInstance().newXPath();
+        //xpath.setNamespaceContext(new NameSpaces(document));
+        Node bean1 = (Node) xpath.evaluate("/blueprint/bean[@id='myBean1']", document, XPathConstants.NODE);
+
+        // Bean
+        Assert.assertEquals(MyBean1.class.getName(), xpath.evaluate("@class", bean1));
+        Assert.assertEquals("init", xpath.evaluate("@init-method", bean1));
+        Assert.assertEquals("destroy", xpath.evaluate("@destroy-method", bean1));
+        Assert.assertEquals("true", xpath.evaluate("@field-injection", bean1));
+        
+        // @Transactional
+        Assert.assertEquals("*", xpath.evaluate("transaction/@method", bean1));
+        Assert.assertEquals("Required", xpath.evaluate("transaction/@value", bean1));
+
+        // @PersistenceContext
+        Assert.assertEquals("person", xpath.evaluate("context/@unitname", bean1));
+        Assert.assertEquals("em", xpath.evaluate("context/@property", bean1));
+        
+        // @PersistenceUnit
+        Assert.assertEquals("person", xpath.evaluate("unit/@unitname", bean1));
+        Assert.assertEquals("emf", xpath.evaluate("unit/@property", bean1));
+        
+        // @Autowired
+        Assert.assertEquals("my1", xpath.evaluate("property[@name='bean2']/@ref", bean1));
+
+
     }
-    
+
+    private Document readToDocument(ByteArrayOutputStream os) throws ParserConfigurationException,
+        SAXException, IOException {
+        InputStream is = new ByteArrayInputStream(os.toByteArray());
+        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder builder = builderFactory.newDocumentBuilder();
+        return builder.parse(is);
+    }
+
 }

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java Tue Jun  9 15:33:24 2015
@@ -25,7 +25,9 @@ import javax.inject.Named;
 
 import org.apache.aries.blueprint.plugin.test.MyBean1;
 import org.apache.aries.blueprint.plugin.test.MyBean3;
+import org.apache.aries.blueprint.plugin.test.MyBean4;
 import org.apache.aries.blueprint.plugin.test.ServiceAImpl1;
+import org.junit.Assert;
 import org.junit.Test;
 
 
@@ -39,7 +41,9 @@ public class BeanTest {
         assertEquals("myBean1", bean.id); // Name derived from class name
         assertEquals("init", bean.initMethod);
         assertEquals("destroy", bean.destroyMethod);
-        assertEquals("em", bean.persistenceUnitField.getName());
+        Assert.assertEquals(2, bean.persistenceFields.length);
+        assertEquals("em", bean.persistenceFields[0].getName());
+        assertEquals("emf", bean.persistenceFields[1].getName());
         assertEquals("*", bean.transactionDef.getMethod());
         assertEquals("Required", bean.transactionDef.getType());
         assertEquals(1, bean.properties.size());
@@ -56,10 +60,10 @@ public class BeanTest {
         assertEquals("myBean3", bean.id); // Name derived from class name
         assertNull("There should be no initMethod", bean.initMethod);
         assertNull("There should be no destroyMethod", bean.destroyMethod);
-        assertNull("There should be no persistenceUnit", bean.persistenceUnitField);
+        assertEquals("There should be no persistence fields", 0, bean.persistenceFields.length);
         assertEquals("*", bean.transactionDef.getMethod());
         assertEquals("RequiresNew", bean.transactionDef.getType());
-        assertEquals(3, bean.properties.size());
+        assertEquals(5, bean.properties.size());
     }
     
     @Test
@@ -71,9 +75,18 @@ public class BeanTest {
         assertEquals("Name should be defined using @Named", definedName, bean.id);
         assertNull("There should be no initMethod", bean.initMethod);
         assertNull("There should be no destroyMethod", bean.destroyMethod);
-        assertNull("There should be no persistenceUnit", bean.persistenceUnitField);
+        assertEquals("There should be no persistence fields", 0, bean.persistenceFields.length);
         assertNull("There should be no transaction definition", bean.transactionDef);
         assertEquals("There should be no properties", 0, bean.properties.size());
     }
+    
+    @Test
+    public void testBlueprintBundleContext() {
+        Bean bean = new Bean(MyBean4.class);
+        bean.resolve(new Context());
+        Property bcProp = bean.properties.iterator().next();
+        assertEquals("bundleContext", bcProp.name);
+        assertEquals("blueprintBundleContext", bcProp.ref);
+    }
 
 }

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java Tue Jun  9 15:33:24 2015
@@ -18,16 +18,19 @@
  */
 package org.apache.aries.blueprint.plugin.model;
 
-import java.lang.reflect.Field;
+import static org.junit.Assert.assertEquals;
 
-import org.apache.aries.blueprint.plugin.model.Bean;
-import org.apache.aries.blueprint.plugin.model.Context;
-import org.apache.aries.blueprint.plugin.model.OsgiServiceBean;
 import org.apache.aries.blueprint.plugin.test.MyBean3;
+import org.apache.aries.blueprint.plugin.test.MyFactoryBean;
+import org.apache.aries.blueprint.plugin.test.MyProduced;
 import org.apache.aries.blueprint.plugin.test.ServiceB;
 import org.apache.aries.blueprint.plugin.test.ServiceReferences;
 import org.junit.Assert;
 import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.container.Converter;
 
 public class ContextTest {
 
@@ -42,16 +45,40 @@ public class ContextTest {
     public void testLists2()  {
         Context context = new Context(ServiceReferences.class);
         Assert.assertEquals(1, context.getBeans().size());
-        Assert.assertEquals(1, context.getServiceRefs().size());
+        Assert.assertEquals(2, context.getServiceRefs().size());
     }
     
     @Test
     public void testMatching() throws NoSuchFieldException, SecurityException  {
         Context context = new Context(ServiceReferences.class);
-        Field field = ServiceReferences.class.getDeclaredFields()[0];
-        Bean matching = context.getMatching(field);
-        Assert.assertEquals(OsgiServiceBean.class, matching.getClass());
+        BeanRef matching = context.getMatching(new BeanRef(ServiceB.class));
+        Assert.assertEquals(OsgiServiceRef.class, matching.getClass());
         Assert.assertEquals(ServiceB.class, matching.clazz);
         Assert.assertEquals("serviceB", matching.id);
     }
+    
+    private void assertSpecialRef(String expectedId, Class<?> clazz) {
+        Context context = new Context();
+        BeanRef ref = context.getMatching(new BeanRef(clazz));
+        assertEquals(expectedId, ref.id);
+    }
+    
+    @Test
+    public void testSpecialRefs() {
+        assertSpecialRef("blueprintBundleContext", BundleContext.class);
+        assertSpecialRef("blueprintBundle", Bundle.class);
+        assertSpecialRef("blueprintContainer", BlueprintContainer.class);
+        assertSpecialRef("blueprintConverter", Converter.class);
+    }
+    
+    @Test
+    public void testProduced() throws NoSuchFieldException, SecurityException  {
+        Context context = new Context(MyFactoryBean.class);
+        
+        ProducedBean matching = (ProducedBean)context.getMatching(new BeanRef(MyProduced.class));
+        Assert.assertEquals(MyProduced.class, matching.clazz);
+        Assert.assertEquals("myFactoryBean", matching.factoryBeanId);
+        Assert.assertEquals("create", matching.factoryMethod);
+    }
+    
 }

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/PropertyTest.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/PropertyTest.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/PropertyTest.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/PropertyTest.java Tue Jun  9 15:33:24 2015
@@ -34,7 +34,7 @@ public class PropertyTest {
     public void testRefInject() throws XMLStreamException {
         Field field = TestBeanForRef.class.getDeclaredFields()[0];
         Matcher matcher = new Matcher() {
-            public Bean getMatching(Field field) {
+            public Bean getMatching(BeanRef template) {
                 return new Bean(ServiceAImpl1.class);
             }
         };
@@ -48,7 +48,7 @@ public class PropertyTest {
     public void testRefAutowired() throws XMLStreamException {
         Field field = TestBeanForRef.class.getDeclaredFields()[1];
         Matcher matcher = new Matcher() {
-            public Bean getMatching(Field field) {
+            public Bean getMatching(BeanRef template) {
                 return null;
             }
         };

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java Tue Jun  9 15:33:24 2015
@@ -20,6 +20,7 @@ package org.apache.aries.blueprint.plugi
 
 import javax.inject.Singleton;
 import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
 import javax.persistence.PersistenceUnit;
 import javax.transaction.Transactional;
 import javax.transaction.Transactional.TxType;
@@ -33,9 +34,12 @@ public class MyBean1 extends ParentBean
     @Autowired
     ServiceA bean2;
     
-    @PersistenceUnit(unitName="person")
+    @PersistenceContext(unitName="person")
     EntityManager em;
     
+    @PersistenceUnit(unitName="person")
+    EntityManager emf;
+    
     public void init() {
     }
     

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean3.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean3.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean3.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean3.java Tue Jun  9 15:33:24 2015
@@ -40,4 +40,11 @@ public class MyBean3 {
 
     @Inject
     ServiceB serviceB;
+    
+    @Inject
+    @Named("serviceB2Id")
+    ServiceB serviceB2;
+    
+    @Inject
+    MyProduced myProduced;
 }

Modified: aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java Tue Jun  9 15:33:24 2015
@@ -20,6 +20,7 @@
 package org.apache.aries.blueprint.plugin.test;
 
 import javax.inject.Inject;
+import javax.inject.Named;
 
 import org.ops4j.pax.cdi.api.OsgiService;
 import org.springframework.stereotype.Component;
@@ -27,4 +28,6 @@ import org.springframework.stereotype.Co
 @Component
 public class ServiceReferences {
     @Inject @OsgiService ServiceB serviceB;
+    
+    @Named("serviceB2Id") @Inject @OsgiService ServiceB serviceB2;
 }

Modified: aries/branches/subsystemsR6/blueprint/blueprint-noosgi/pom.xml
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-noosgi/pom.xml?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-noosgi/pom.xml (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-noosgi/pom.xml Tue Jun  9 15:33:24 2015
@@ -31,7 +31,7 @@
     <groupId>org.apache.aries.blueprint</groupId>
     <artifactId>org.apache.aries.blueprint.noosgi</artifactId>
     <packaging>jar</packaging>
-    <version>1.0.1-SNAPSHOT</version>
+    <version>1.1.1-SNAPSHOT</version>
     <name>Apache Aries Blueprint no-OSGI</name>
     <description>
         This jar contains everything needed to run Blueprint outside OSGi.
@@ -45,8 +45,8 @@
 
     <properties>
         <blueprint.api.version>1.0.0</blueprint.api.version>
-        <blueprint.core.version>1.0.0</blueprint.core.version>
-        <blueprint.parser.version>1.0.0</blueprint.parser.version>
+        <blueprint.core.version>1.4.3</blueprint.core.version>
+        <blueprint.parser.version>1.3.0</blueprint.parser.version>
         <proxy.impl.version>1.0.3</proxy.impl.version>
     </properties>
 

Modified: aries/branches/subsystemsR6/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java Tue Jun  9 15:33:24 2015
@@ -18,6 +18,19 @@
  */
 package org.apache.aries.blueprint.container;
 
+import java.net.URI;
+import java.net.URL;
+import java.security.AccessControlContext;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import org.apache.aries.blueprint.ComponentDefinitionRegistryProcessor;
 import org.apache.aries.blueprint.ExtendedBeanMetadata;
 import org.apache.aries.blueprint.Processor;
@@ -32,16 +45,24 @@ import org.apache.aries.blueprint.servic
 import org.osgi.service.blueprint.container.ComponentDefinitionException;
 import org.osgi.service.blueprint.container.Converter;
 import org.osgi.service.blueprint.container.NoSuchComponentException;
-import org.osgi.service.blueprint.reflect.*;
+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.CollectionMetadata;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.MapEntry;
+import org.osgi.service.blueprint.reflect.MapMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.PropsMetadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.ReferenceListener;
+import org.osgi.service.blueprint.reflect.RegistrationListener;
+import org.osgi.service.blueprint.reflect.ServiceMetadata;
+import org.osgi.service.blueprint.reflect.ServiceReferenceMetadata;
+import org.osgi.service.blueprint.reflect.Target;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.net.URI;
-import java.net.URL;
-import java.security.AccessControlContext;
-import java.util.*;
-import java.util.concurrent.atomic.AtomicBoolean;
-
 public class BlueprintContainerImpl implements ExtendedBlueprintContainer {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(BlueprintContainerImpl.class);
@@ -55,7 +76,8 @@ public class BlueprintContainerImpl impl
     private BlueprintRepository repository;
     private List<Processor> processors = new ArrayList<Processor>();
     private Map<String, String> properties;
-
+    private NamespaceHandlerSet nsHandlerSet;
+    
     public BlueprintContainerImpl(ClassLoader loader, List<URL> resources) throws Exception {
         this(loader, resources, null, true);
     }
@@ -65,16 +87,20 @@ public class BlueprintContainerImpl impl
     }
 
     public BlueprintContainerImpl(ClassLoader loader, List<URL> resources, Map<String, String> properties, boolean init) throws Exception {
+        this(loader, resources, properties, null, init);
+    }
+    public BlueprintContainerImpl(ClassLoader loader, List<URL> resources, Map<String, String> properties, 
+                                  NamespaceHandlerSet nsHandlerSet, boolean init) throws Exception {
         this.loader = loader;
         this.converter = new AggregateConverter(this);
         this.componentDefinitionRegistry = new ComponentDefinitionRegistryImpl();
         this.resources = resources;
         this.properties = properties;
+        this.nsHandlerSet = nsHandlerSet;
         if (init) {
             init();
         }
     }
-
     public String getProperty(String key) {
         if (properties != null && properties.containsKey(key)) {
             return properties.get(key);
@@ -83,7 +109,7 @@ public class BlueprintContainerImpl impl
     }
 
     protected NamespaceHandlerSet createNamespaceHandlerSet(Set<URI> namespaces) {
-        NamespaceHandlerSet handlerSet = new SimpleNamespaceHandlerSet();
+        NamespaceHandlerSet handlerSet = createNamespaceHandlerSet();
         // Check namespaces
         Set<URI> unsupported = new LinkedHashSet<URI>();
         for (URI ns : namespaces) {
@@ -97,7 +123,14 @@ public class BlueprintContainerImpl impl
         return handlerSet;
     }
 
+    protected NamespaceHandlerSet createNamespaceHandlerSet() {
+        return nsHandlerSet == null ? new SimpleNamespaceHandlerSet() : nsHandlerSet;
+    } 
+    
     public void init() throws Exception {
+        init(true);
+    }
+    public void init(boolean validate) throws Exception {
         // Parse xml resources
         Parser parser = new Parser();
         parser.parse(getResources());
@@ -107,8 +140,10 @@ public class BlueprintContainerImpl impl
         NamespaceHandlerSet handlerSet = createNamespaceHandlerSet(namespaces);
         // Add predefined beans
         componentDefinitionRegistry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintContainer", this));
-        // Validate
-        parser.validate(handlerSet.getSchema());
+        if (validate) {
+            // Validate
+            parser.validate(handlerSet.getSchema());
+        }
         // Populate
         parser.populate(handlerSet, componentDefinitionRegistry);
         // Create repository

Modified: aries/branches/subsystemsR6/blueprint/blueprint-web/pom.xml
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-web/pom.xml?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-web/pom.xml (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-web/pom.xml Tue Jun  9 15:33:24 2015
@@ -32,7 +32,7 @@
     <artifactId>org.apache.aries.blueprint.web</artifactId>
     <packaging>jar</packaging>
     <name>Apache Aries Blueprint Web</name>
-    <version>1.0.1-SNAPSHOT</version>
+    <version>1.1.1-SNAPSHOT</version>
     <description>
         This bundle contains a Servlet ContextListener for bootstrapping
         blueprint inside web containers.
@@ -45,7 +45,8 @@
     </scm>
 
     <properties>
-        <blueprint.nosgi.version>1.0.0</blueprint.nosgi.version>
+        <blueprint.nosgi.version>1.1.0</blueprint.nosgi.version>
+        <blueprint.parser.version>1.3.1-SNAPSHOT</blueprint.parser.version>
         <lastReleaseVersion>1.0.0</lastReleaseVersion>
     </properties>
 
@@ -53,7 +54,7 @@
         <profile>
             <id>dev</id>
             <properties>
-              <blueprint.nosgi.version>1.0.0-SNAPSHOT</blueprint.nosgi.version>
+              <blueprint.nosgi.version>1.1.0-SNAPSHOT</blueprint.nosgi.version>
             </properties>
         </profile>
     </profiles>
@@ -65,6 +66,12 @@
             <version>${blueprint.nosgi.version}</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>blueprint-parser</artifactId>
+            <version>${blueprint.parser.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-servlet_2.5_spec</artifactId>
             <version>1.2</version>

Modified: aries/branches/subsystemsR6/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java (original)
+++ aries/branches/subsystemsR6/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java Tue Jun  9 15:33:24 2015
@@ -17,20 +17,30 @@
  */
 package org.apache.aries.blueprint.web;
 
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletException;
+import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.Set;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.aries.blueprint.NamespaceHandler;
+import org.apache.aries.blueprint.Namespaces;
 import org.apache.aries.blueprint.container.BlueprintContainerImpl;
+import org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet;
+import org.apache.aries.blueprint.parser.NamespaceHandlerSet;
 
 /**
  * Initialises all the blueprint XML files called <code>META-INF/blueprint.xml</code> on the classpath
@@ -39,17 +49,20 @@ public class BlueprintContextListener im
 
     public static final String CONTAINER_ATTRIBUTE = "org.apache.aries.blueprint.container";
 
-    public static final String LOCATION = "blueprintLocation";
-
+    public static final String CONTEXT_LOCATION = "blueprintLocation";
+    public static final String DEFAULT_CONTEXT_LOCATION = "META-INF/blueprint.xml";
+    
+    public static final String NAMESPACE_HANDLERS_PARAMETER = "blueprintNamespaceHandlers";
+    public static final String NAMESPACE_HANDLERS_LOCATION = "META-INF/blueprint.handlers";
+    
     public static final String PROPERTIES = "blueprintProperties";
-
-    public static final String DEFAULT_LOCATION = "META-INF/blueprint.xml";
+    
 
     public void contextInitialized(ServletContextEvent event) {
         ServletContext servletContext = event.getServletContext();
-        String location = servletContext.getInitParameter(LOCATION);
+        String location = servletContext.getInitParameter(CONTEXT_LOCATION);
         if (location == null) {
-            location = DEFAULT_LOCATION;
+            location = DEFAULT_CONTEXT_LOCATION;
         }
         List<URL> resourcePaths = new ArrayList<URL>();
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
@@ -83,13 +96,87 @@ public class BlueprintContextListener im
                 }
             }
 
-            BlueprintContainerImpl container = new BlueprintContainerImpl(classLoader, resourcePaths, properties, true);
+            NamespaceHandlerSet nsHandlerSet = getNamespaceHandlerSet(servletContext, classLoader);
+            BlueprintContainerImpl container = new BlueprintContainerImpl(classLoader, resourcePaths, properties, nsHandlerSet, true);
             servletContext.setAttribute(CONTAINER_ATTRIBUTE, container);
         } catch (Exception e) {
             servletContext.log("Failed to startup blueprint container. " + e, e);
         }
     }
+    
+    protected NamespaceHandlerSet getNamespaceHandlerSet(ServletContext servletContext, ClassLoader tccl) {
+        NamespaceHandlerSet nsSet = getNamespaceHandlerSetFromParameter(servletContext, tccl);
+        if (nsSet != null) {
+            return nsSet;
+        }
+        return getNamespaceHandlerSetFromLocation(servletContext, tccl);
+    }
 
+    protected NamespaceHandlerSet getNamespaceHandlerSetFromParameter(ServletContext servletContext, ClassLoader tccl) {
+        String handlersProp = servletContext.getInitParameter(NAMESPACE_HANDLERS_PARAMETER);
+        if (handlersProp == null) {
+            return null;
+        }
+        return getNamespaceHandlerSetFromClassNames(servletContext, tccl, Arrays.asList(handlersProp.split(",")));
+    }
+        
+    protected NamespaceHandlerSet getNamespaceHandlerSetFromLocation(ServletContext servletContext, ClassLoader tccl) {
+        List<String> handlerClassNames = new LinkedList<String>();
+        try {
+            Enumeration<URL> resources = tccl.getResources(NAMESPACE_HANDLERS_LOCATION);
+            while (resources.hasMoreElements()) {
+                URL resource = resources.nextElement();
+                BufferedReader br = new BufferedReader(new InputStreamReader(resource.openStream()));
+                try {
+                    for (String line = br.readLine(); line != null; line = br.readLine()) {
+                        String trimmedLine = line.trim();
+                        if (trimmedLine.isEmpty() || trimmedLine.startsWith("#")) {
+                            continue;
+                        }
+                        handlerClassNames.add(trimmedLine);
+                    }
+                } finally {
+                    br.close();
+                }
+            }
+        } catch (IOException ex) {
+            throw new RuntimeException("Failed to load namespace handler resources", ex);
+        }
+        if (!handlerClassNames.isEmpty()) {
+            return getNamespaceHandlerSetFromClassNames(servletContext, tccl, handlerClassNames);
+        } else {
+            return null;
+        }
+        
+    }
+    
+    protected NamespaceHandlerSet getNamespaceHandlerSetFromClassNames(ServletContext servletContext, ClassLoader tccl, 
+        List<String> handlerClassNames) {
+        SimpleNamespaceHandlerSet nsSet = new SimpleNamespaceHandlerSet();
+        
+        for (String name : handlerClassNames) {
+            String trimmedName = name.trim();
+            Object instance = null; 
+            try {
+                instance = tccl.loadClass(trimmedName).newInstance();
+            } catch (Exception ex) {
+                throw new RuntimeException("Failed to load NamespaceHandler: " + trimmedName, ex);
+            }
+            if (!(instance instanceof NamespaceHandler)) {
+                throw new RuntimeException("Invalid NamespaceHandler: " + trimmedName);
+            }
+            NamespaceHandler nsHandler = (NamespaceHandler)instance;
+            Namespaces namespaces = nsHandler.getClass().getAnnotation(Namespaces.class);
+            if (namespaces != null) {
+                for (String ns : namespaces.value()) {
+                    nsSet.addNamespace(URI.create(ns), nsHandler.getSchemaLocation(ns), nsHandler);    
+                }
+            }
+        }
+        
+        return nsSet;
+    }
+    
     public void contextDestroyed(ServletContextEvent event) {
         ServletContext servletContext = event.getServletContext();
         Object container = servletContext.getAttribute(CONTAINER_ATTRIBUTE);

Modified: aries/branches/subsystemsR6/jmx/jmx-core-whiteboard/pom.xml
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/jmx/jmx-core-whiteboard/pom.xml?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/jmx/jmx-core-whiteboard/pom.xml (original)
+++ aries/branches/subsystemsR6/jmx/jmx-core-whiteboard/pom.xml Tue Jun  9 15:33:24 2015
@@ -78,7 +78,7 @@
         <dependency>
             <groupId>org.apache.aries.jmx</groupId>
             <artifactId>org.apache.aries.jmx.core</artifactId>
-            <version>1.1.3-SNAPSHOT</version>
+            <version>1.1.4-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>

Modified: aries/branches/subsystemsR6/jmx/jmx-core/pom.xml
URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/jmx/jmx-core/pom.xml?rev=1684451&r1=1684450&r2=1684451&view=diff
==============================================================================
--- aries/branches/subsystemsR6/jmx/jmx-core/pom.xml (original)
+++ aries/branches/subsystemsR6/jmx/jmx-core/pom.xml Tue Jun  9 15:33:24 2015
@@ -32,7 +32,7 @@
     <artifactId>org.apache.aries.jmx.core</artifactId>
     <packaging>bundle</packaging>
     <name>Apache Aries JMX Core</name>
-    <version>1.1.3-SNAPSHOT</version>
+    <version>1.1.4-SNAPSHOT</version>
     <description>
         This bundle contains the core implementation 
 		of the JMX Control specification



Mime
View raw message