[jboss-osgi-commits] JBoss-OSGI SVN: r99122 - in projects/jboss-osgi/projects/runtime/framework/trunk/src: test/java/org/jboss/test/osgi/service and 4 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Thu Jan 7 11:52:04 EST 2010
Author: alesj
Date: 2010-01-07 11:52:03 -0500 (Thu, 07 Jan 2010)
New Revision: 99122
Added:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/FilterParserAndMatcher.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/jboss-beans.xml
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans2/
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans2/META-INF/
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans2/META-INF/MANIFEST.MF
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans2/META-INF/jboss-beans.xml
Removed:
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/jboss-beans.xml
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/MANIFEST.MF
Log:
[JBOSGI-141]; allow for service injection into bean via filter.
Copied: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/FilterParserAndMatcher.java (from rev 99103, projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/FilterParserAndMatcher.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/FilterParserAndMatcher.java 2010-01-07 16:52:03 UTC (rev 99122)
@@ -0,0 +1,90 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.bundle;
+
+import java.util.Dictionary;
+import java.util.Set;
+
+import org.jboss.beans.metadata.api.model.QualifierContent;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.spi.qualifier.QualifierMatcher;
+import org.jboss.kernel.spi.qualifier.QualifierParser;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+
+/**
+ * OSGi filter parsing and matching.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+class FilterParserAndMatcher implements QualifierParser, QualifierMatcher<Filter>
+{
+ static final FilterParserAndMatcher INSTANCE = new FilterParserAndMatcher();
+
+ private FilterParserAndMatcher()
+ {
+ }
+
+ public Class<Filter> getHandledType()
+ {
+ return Filter.class;
+ }
+
+ public QualifierContent getHandledContent()
+ {
+ return QualifierContent.getContent("filter");
+ }
+
+ public boolean matches(ControllerContext context, Set<Object> suppliedQualifiers, Filter filter)
+ {
+ MetaData metaData = context.getScopeInfo().getMetaData();
+ if (metaData == null)
+ return false;
+
+ MetaData instanceMD = metaData.getScopeMetaData(CommonLevels.INSTANCE);
+ if (instanceMD == null)
+ return false;
+
+ Dictionary dictionary = instanceMD.getMetaData(Dictionary.class);
+ return dictionary != null && filter.match(dictionary);
+ }
+
+ public Object parseWanted(ClassLoader cl, Object rawQualifier)
+ {
+ try
+ {
+ return FrameworkUtil.createFilter(String.valueOf(rawQualifier));
+ }
+ catch (InvalidSyntaxException e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public Object parseSupplied(ClassLoader cl, Object rawQualifier)
+ {
+ return parseWanted(cl, rawQualifier);
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2010-01-07 16:36:34 UTC (rev 99121)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2010-01-07 16:52:03 UTC (rev 99122)
@@ -46,8 +46,8 @@
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.jar.Attributes;
+import java.util.jar.Attributes.Name;
import java.util.jar.Manifest;
-import java.util.jar.Attributes.Name;
import org.jboss.dependency.spi.Controller;
import org.jboss.dependency.spi.ControllerContext;
@@ -68,6 +68,7 @@
import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.qualifier.QualifierMatchers;
import org.jboss.logging.Logger;
import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
import org.jboss.metadata.spi.loader.MutableMetaDataLoader;
@@ -279,8 +280,14 @@
}
}
+ // osgi ldap filter parsing and matching
+ FilterParserAndMatcher fpm = FilterParserAndMatcher.INSTANCE;
+
if (register)
{
+ QualifierMatchers.getInstance().addParser(fpm);
+ QualifierMatchers.getInstance().addMatcher(fpm);
+
MetaDataRetrievalFactory mdrFactory = factory;
if (mdrFactory == null)
{
@@ -296,6 +303,9 @@
else
{
repository.removeMetaDataRetrievalFactory(CommonLevels.INSTANCE);
+
+ QualifierMatchers.getInstance().removeParser(fpm.getHandledContent());
+ QualifierMatchers.getInstance().removeMatcher(fpm.getHandledType());
}
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java 2010-01-07 16:36:34 UTC (rev 99121)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java 2010-01-07 16:52:03 UTC (rev 99122)
@@ -460,6 +460,47 @@
}
}
+ public void testServiceInjection() throws Throwable
+ {
+ Bundle bundle = installBundle(assembleBundle("simple2", "/bundles/service/service-bundle2", A.class));
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext1 = bundle.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ Class<?> aClass = bundle.loadClass(A.class.getName());
+ Object a = aClass.newInstance();
+ Hashtable<String, Object> table = new Hashtable<String, Object>();
+ table.put("a", "b");
+ ServiceRegistration reg1 = bundleContext1.registerService(A.class.getName(), a, table);
+ assertNotNull(reg1);
+
+ AssembledDirectory mix = createAssembledDirectory("beans1", "");
+ addPath(mix, "/bundles/service/service-beans2", "");
+ addPackage(mix, C.class);
+ Deployment deployment = assertDeploy(mix);
+ try
+ {
+ checkComplete();
+
+ Bundle beans = getBundle(getDeploymentUnit(deployment));
+ beans.start();
+
+ Object c = getBean("C");
+ assertEquals(a, getter(c, "getA", "C"));
+ }
+ finally
+ {
+ undeploy(deployment);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
public void testFiltering() throws Throwable
{
Deployment bean = addBean("beanA", A.class);
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/MANIFEST.MF 2010-01-07 16:36:34 UTC (rev 99121)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/MANIFEST.MF 2010-01-07 16:52:03 UTC (rev 99122)
@@ -2,6 +2,6 @@
Implementation-Title: JBoss OSGi tests
Implementation-Version: test
Implementation-Vendor: jboss.org
-Bundle-Name: Service1
-Bundle-SymbolicName: org.jboss.test.osgi.service1
+Bundle-Name: Beans1
+Bundle-SymbolicName: org.jboss.test.osgi.beans1
Export-Package: org.jboss.test.osgi.service.support.a
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/jboss-beans.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/jboss-beans.xml 2010-01-07 16:36:34 UTC (rev 99121)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/jboss-beans.xml 2010-01-07 16:52:03 UTC (rev 99122)
@@ -1,5 +0,0 @@
-<deployment xmlns="urn:jboss:bean-deployer:2.0">
-
- <bean name="A" class="org.jboss.test.osgi.service.support.a.A" />
-
-</deployment>
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/jboss-beans.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/jboss-beans.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/jboss-beans.xml 2010-01-07 16:52:03 UTC (rev 99122)
@@ -0,0 +1,5 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="A" class="org.jboss.test.osgi.service.support.a.A"/>
+
+</deployment>
\ No newline at end of file
Copied: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans2/META-INF/MANIFEST.MF (from rev 99113, projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/MANIFEST.MF)
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans2/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans2/META-INF/MANIFEST.MF 2010-01-07 16:52:03 UTC (rev 99122)
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
+Bundle-Name: Beans2
+Bundle-SymbolicName: org.jboss.test.osgi.beans2
+Export-Package: org.jboss.test.osgi.service.support.c
+Import-Package: org.jboss.test.osgi.service.support.a
Copied: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans2/META-INF/jboss-beans.xml (from rev 99110, projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans1/META-INF/jboss-beans.xml)
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans2/META-INF/jboss-beans.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/service/service-beans2/META-INF/jboss-beans.xml 2010-01-07 16:52:03 UTC (rev 99122)
@@ -0,0 +1,11 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="C" class="org.jboss.test.osgi.service.support.c.C">
+ <property name="a">
+ <inject>
+ <qualifier content="filter" type="required">(a=b)</qualifier>
+ </inject>
+ </property>
+ </bean>
+
+</deployment>
\ No newline at end of file
More information about the jboss-osgi-commits
mailing list