[jboss-osgi-commits] JBoss-OSGI SVN: r100964 - in projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src: test/java/org/jboss/test/osgi/service and 3 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Mon Feb 15 07:02:12 EST 2010
Author: alesj
Date: 2010-02-15 07:02:10 -0500 (Mon, 15 Feb 2010)
New Revision: 100964
Added:
projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans3/
projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans3/META-INF/
projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans3/META-INF/MANIFEST.MF
projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans3/META-INF/jboss-beans.xml
Modified:
projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/AbstractDictionaryFactory.java
projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/JMXDictionaryFactory.java
projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java
projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java
projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
Log:
Test limited pojo exposure.
Modified: projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/AbstractDictionaryFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/AbstractDictionaryFactory.java 2010-02-15 11:55:33 UTC (rev 100963)
+++ projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/AbstractDictionaryFactory.java 2010-02-15 12:02:10 UTC (rev 100964)
@@ -24,7 +24,6 @@
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.kernel.spi.config.KernelConfigurator;
import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.system.microcontainer.ServiceControllerContext;
import org.jboss.util.collection.Iterators;
import org.osgi.framework.Constants;
@@ -64,12 +63,12 @@
}
}
- protected class ControllerContextDictionary extends Dictionary<String, Object>
+ protected abstract class AbstractDictionary extends Dictionary<String, Object>
{
private Map<Object, Object> map;
- private ControllerContext context;
+ private ControllerContext context;
- protected ControllerContextDictionary(ControllerContext context)
+ protected AbstractDictionary(ControllerContext context)
{
this.context = context;
this.map = new ConcurrentHashMap<Object, Object>(2);
@@ -110,6 +109,33 @@
if (value != EMPTY)
return value;
+ return getClasses(context);
+ }
+
+ protected abstract String[] getClasses(ControllerContext context);
+
+ public Object put(String key, Object value)
+ {
+ return map.put(key, value);
+ }
+
+ public Object remove(Object key)
+ {
+ return map.remove(key);
+ }
+ }
+
+ // this one exposes whole target type/class hierarchy
+ protected class GenericDictionary extends AbstractDictionary
+ {
+ protected GenericDictionary(ControllerContext context)
+ {
+ super(context);
+ }
+
+ @Override
+ protected String[] getClasses(ControllerContext context)
+ {
ClassInfo clazz;
Object target = context.getTarget();
if (target != null)
@@ -125,26 +151,16 @@
Set<String> clazzes = new HashSet<String>();
traverseClass(clazz, clazzes);
classes = clazzes.toArray(new String[clazzes.size()]);
- map.put(Constants.OBJECTCLASS, classes);
+ put(Constants.OBJECTCLASS, classes);
}
return classes;
}
-
+
protected ClassInfo getFromNullTarget(ControllerContext context)
{
return null;
}
- public Object put(String key, Object value)
- {
- return map.put(key, value);
- }
-
- public Object remove(Object key)
- {
- return map.remove(key);
- }
-
protected void traverseClass(ClassInfo clazz, Set<String> classes)
{
if (clazz == null || clazz == OBJECT)
Modified: projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/JMXDictionaryFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/JMXDictionaryFactory.java 2010-02-15 11:55:33 UTC (rev 100963)
+++ projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/JMXDictionaryFactory.java 2010-02-15 12:02:10 UTC (rev 100964)
@@ -23,13 +23,14 @@
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.system.metadata.ServiceMetaData;
import org.jboss.system.microcontainer.ServiceControllerContext;
+import org.osgi.framework.Constants;
import java.util.Dictionary;
/**
* JMX dictionary factory.
- * TODO - expose all classes, or just explicit target class and its mbean interface?
*
* @author <a href="ales.justin at jboss.org">Ales Justin</a>
*/
@@ -47,6 +48,32 @@
public Dictionary<String, Object> getDictionary(ServiceControllerContext context)
{
- return new ControllerContextDictionary(context);
+ return new JMXDictionary(context);
}
+
+ private class JMXDictionary extends GenericDictionary
+ {
+ protected JMXDictionary(ServiceControllerContext context)
+ {
+ super(context);
+ }
+
+ @Override
+ protected String[] getClasses(ControllerContext context)
+ {
+ ServiceControllerContext scc = ServiceControllerContext.class.cast(context);
+ ServiceMetaData smd = scc.getServiceMetaData();
+ if (smd != null)
+ {
+ String interfaceName = smd.getInterfaceName();
+ if (interfaceName != null)
+ {
+ String[] result = {interfaceName};
+ put(Constants.OBJECTCLASS, result);
+ return result;
+ }
+ }
+ return super.getClasses(context);
+ }
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java 2010-02-15 11:55:33 UTC (rev 100963)
+++ projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java 2010-02-15 12:02:10 UTC (rev 100964)
@@ -22,12 +22,17 @@
package org.jboss.osgi.framework.bundle;
import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Set;
import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.RelatedClassMetaData;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.kernel.spi.config.KernelConfigurator;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.reflect.spi.ClassInfo;
+import org.osgi.framework.Constants;
/**
* Kernel dictionary factory.
@@ -51,7 +56,7 @@
return new KernelDictionary(context);
}
- private class KernelDictionary extends ControllerContextDictionary
+ private class KernelDictionary extends GenericDictionary
{
private KernelDictionary(KernelControllerContext context)
{
@@ -59,6 +64,35 @@
}
@Override
+ protected String[] getClasses(ControllerContext context)
+ {
+ KernelControllerContext kcc = KernelControllerContext.class.cast(context);
+ BeanMetaData bmd = kcc.getBeanMetaData();
+ if (bmd != null)
+ {
+ Set<RelatedClassMetaData> rcmds = bmd.getRelated();
+ if (rcmds != null && rcmds.isEmpty() == false)
+ {
+ Set<String> classes = new HashSet<String>();
+ for (RelatedClassMetaData rcmd : rcmds)
+ {
+ if ("OSGi".equalsIgnoreCase(rcmd.getEnabled(String.class)))
+ {
+ classes.add(rcmd.getClassName());
+ }
+ }
+ if (classes.isEmpty() == false)
+ {
+ String[] result = classes.toArray(new String[classes.size()]);
+ put(Constants.OBJECTCLASS, result);
+ return result;
+ }
+ }
+ }
+ return super.getClasses(context);
+ }
+
+ @Override
protected ClassInfo getFromNullTarget(ControllerContext context)
{
KernelControllerContext kcc = KernelControllerContext.class.cast(context);
Modified: projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java 2010-02-15 11:55:33 UTC (rev 100963)
+++ projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java 2010-02-15 12:02:10 UTC (rev 100964)
@@ -374,7 +374,7 @@
ServiceReference ref = getServiceReferenceForContext(context);
if (filter.match(ref) && hasPermission(context))
{
- if (clazz == null || isSystemBundle == false || MDRUtils.matchClass(context, clazz))
+ if (clazz == null || MDRUtils.matchClass(context, clazz))
{
// Check the assignability
if (checkAssignable == false || MDRUtils.isAssignableTo(context, bundle))
Modified: projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java 2010-02-15 11:55:33 UTC (rev 100963)
+++ projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java 2010-02-15 12:02:10 UTC (rev 100964)
@@ -36,6 +36,7 @@
import org.jboss.test.osgi.DeployersTest;
import org.jboss.test.osgi.service.support.LazyBundle;
import org.jboss.test.osgi.service.support.a.A;
+import org.jboss.test.osgi.service.support.a.AMBean;
import org.jboss.test.osgi.service.support.c.C;
import org.jboss.test.osgi.service.support.d.D;
import org.jboss.virtual.AssembledDirectory;
@@ -544,4 +545,40 @@
undeploy(bean);
}
}
+
+ public void testExposedClasses() throws Throwable
+ {
+ AssembledDirectory mix = createAssembledDirectory("beans3", "");
+ addPath(mix, "/bundles/service/service-beans3", "");
+ addPackage(mix, A.class);
+ Deployment deployment = addDeployment(mix);
+ try
+ {
+ checkComplete();
+
+ Bundle bundle = getBundle(getDeploymentUnit(deployment));
+ bundle.start();
+
+ Bundle osgi = installBundle(assembleBundle("simple2", "/bundles/service/service-bundle1"));
+ try
+ {
+ osgi.start();
+ BundleContext bundleContext = osgi.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceReference[] refs = bundleContext.getServiceReferences(A.class.getName(), null);
+ assertNull(refs);
+ refs = bundleContext.getServiceReferences(AMBean.class.getName(), null);
+ assertNotNull(refs);
+ }
+ finally
+ {
+ uninstall(osgi);
+ }
+ }
+ finally
+ {
+ undeploy(deployment);
+ }
+ }
}
Copied: projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans3/META-INF/MANIFEST.MF (from rev 100962, projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans1/META-INF/MANIFEST.MF)
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans3/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans3/META-INF/MANIFEST.MF 2010-02-15 12:02:10 UTC (rev 100964)
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
+Bundle-Name: Beans3
+Bundle-SymbolicName: org.jboss.test.osgi.beans3
+Export-Package: org.jboss.test.osgi.service.support.a
Copied: projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans3/META-INF/jboss-beans.xml (from rev 100962, projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans1/META-INF/jboss-beans.xml)
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans3/META-INF/jboss-beans.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/branches/alesj_service-mix/src/test/resources/bundles/service/service-beans3/META-INF/jboss-beans.xml 2010-02-15 12:02:10 UTC (rev 100964)
@@ -0,0 +1,7 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="A" class="org.jboss.test.osgi.service.support.a.A">
+ <related-class name="org.jboss.test.osgi.service.support.a.AMBean">OSGi</related-class>
+ </bean>
+
+</deployment>
\ No newline at end of file
More information about the jboss-osgi-commits
mailing list