JBoss-OSGI SVN: r97184 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-30 14:08:52 -0500 (Mon, 30 Nov 2009)
New Revision: 97184
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ServiceRefDictionary.java
Log:
Use current size, it might change.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ServiceRefDictionary.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ServiceRefDictionary.java 2009-11-30 19:01:24 UTC (rev 97183)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ServiceRefDictionary.java 2009-11-30 19:08:52 UTC (rev 97184)
@@ -59,10 +59,11 @@
{
String[] keys = ref.getPropertyKeys();
int index = 0;
+ int size = size();
public boolean hasMoreElements()
{
- return index < size();
+ return index < size;
}
public String nextElement()
@@ -78,10 +79,11 @@
{
String[] keys = ref.getPropertyKeys();
int index = 0;
+ int size = size();
public boolean hasMoreElements()
{
- return index < size();
+ return index < size;
}
public Object nextElement()
14 years, 5 months
JBoss-OSGI SVN: r97183 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-30 14:01:24 -0500 (Mon, 30 Nov 2009)
New Revision: 97183
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/MDRUtils.java
Log:
Expose classes via MDR.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/MDRUtils.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/MDRUtils.java 2009-11-30 18:34:12 UTC (rev 97182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/MDRUtils.java 2009-11-30 19:01:24 UTC (rev 97183)
@@ -191,7 +191,7 @@
*/
public static boolean matchClass(ControllerContext context, String clazz)
{
- String[] classes = getProperty(context, Constants.OBJECTCLASS, String[].class);
+ String[] classes = getClasses(context);
return classes != null && Arrays.asList(classes).contains(clazz);
}
@@ -218,6 +218,17 @@
}
/**
+ * Get classes.
+ *
+ * @param context the context
+ * @return the exsposed classes
+ */
+ public static String[] getClasses(ControllerContext context)
+ {
+ return getProperty(context, Constants.OBJECTCLASS, String[].class);
+ }
+
+ /**
* Is context assignable to bundle.
*
* @param context the context
14 years, 5 months
JBoss-OSGI SVN: r97182 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-30 13:34:12 -0500 (Mon, 30 Nov 2009)
New Revision: 97182
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
Log:
No need for duplicate getServiceRef call.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-30 17:51:29 UTC (rev 97181)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-30 18:34:12 UTC (rev 97182)
@@ -39,8 +39,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
@@ -1200,7 +1198,7 @@
* @param checkAssignable whether to check isAssignable
* @return the services
*/
- Collection<ControllerContext> getServices(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
+ Collection<ServiceReference> getServices(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
{
Set<ControllerContext> contexts;
KernelController controller = kernel.getController();
@@ -1230,9 +1228,10 @@
if (filter == null)
filter = NoFilter.INSTANCE;
- // Use a sorted set to order services according to spec
- SortedSet<ControllerContext> result = new TreeSet<ControllerContext>(ContextComparator.INSTANCE);
- for (ControllerContext context : contexts)
+ List<ControllerContext> sorted = new ArrayList<ControllerContext>(contexts);
+ Collections.sort(sorted, ContextComparator.INSTANCE); // Sort by the spec, should bubble up
+ Collection<ServiceReference> result = new ArrayList<ServiceReference>();
+ for (ControllerContext context : sorted)
{
if (isUnregistered(context) == false)
{
@@ -1243,7 +1242,7 @@
{
// Check the assignability
if (checkAssignable == false || MDRUtils.isAssignableTo(context, bundle))
- result.add(context);
+ result.add(ref);
}
}
}
@@ -1260,12 +1259,11 @@
*/
ServiceReference getServiceReference(AbstractBundleState bundle, String clazz)
{
- Collection<ControllerContext> contexts = getServices(bundle, clazz, null, true);
- if (contexts == null || contexts.isEmpty())
+ Collection<ServiceReference> services = getServices(bundle, clazz, null, true);
+ if (services == null || services.isEmpty())
return null;
- ControllerContext context = contexts.iterator().next();
- return getServiceReferenceForContext(context);
+ return services.iterator().next();
}
/**
@@ -1279,17 +1277,11 @@
*/
ServiceReference[] getServiceReferences(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
{
- Collection<ControllerContext> contexts = getServices(bundle, clazz, filter, checkAssignable);
- if (contexts == null || contexts.isEmpty())
+ Collection<ServiceReference> services = getServices(bundle, clazz, filter, checkAssignable);
+ if (services == null || services.isEmpty())
return null;
- ServiceReference[] result = new ServiceReference[contexts.size()];
-
- int i = 0;
- for (ControllerContext context : contexts)
- result[i++] = getServiceReferenceForContext(context);
-
- return result;
+ return services.toArray(new ServiceReference[services.size()]);
}
/**
14 years, 5 months
JBoss-OSGI SVN: r97179 - projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-30 11:39:07 -0500 (Mon, 30 Nov 2009)
New Revision: 97179
Modified:
projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java
Log:
Fix NPE in OSGiBundle.uninstall() when context not available
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java 2009-11-30 16:33:57 UTC (rev 97178)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java 2009-11-30 16:39:07 UTC (rev 97179)
@@ -122,7 +122,7 @@
assertNotUninstalled();
try
{
- BundleContext context = bundle.getBundleContext();
+ BundleContext context = ((EmbeddedRuntime)getRuntime()).getBundleContext();
ServiceReference sref = context.getServiceReference(DeployerService.class.getName());
if (sref != null)
{
14 years, 5 months
JBoss-OSGI SVN: r97176 - projects/jboss-osgi/trunk.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-30 11:13:51 -0500 (Mon, 30 Nov 2009)
New Revision: 97176
Modified:
projects/jboss-osgi/trunk/pom.xml
Log:
Update deployers
Modified: projects/jboss-osgi/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/pom.xml 2009-11-30 16:13:33 UTC (rev 97175)
+++ projects/jboss-osgi/trunk/pom.xml 2009-11-30 16:13:51 UTC (rev 97176)
@@ -63,7 +63,7 @@
<version.jboss.osgi.jta>1.0.0</version.jboss.osgi.jta>
<version.jboss.osgi.microcontainer>2.0.9-SNAPSHOT</version.jboss.osgi.microcontainer>
<version.jboss.osgi.reflect>2.0.2-SNAPSHOT</version.jboss.osgi.reflect>
- <version.jboss.osgi.runtime.deployers>1.0.3</version.jboss.osgi.runtime.deployers>
+ <version.jboss.osgi.runtime.deployers>1.0.3-SNAPSHOT</version.jboss.osgi.runtime.deployers>
<version.jboss.osgi.runtime.equinox>3.5.1-SNAPSHOT</version.jboss.osgi.runtime.equinox>
<version.jboss.osgi.runtime.felix>2.0.2-SNAPSHOT</version.jboss.osgi.runtime.felix>
<version.jboss.osgi.runtime.jbossas>1.0.2</version.jboss.osgi.runtime.jbossas>
14 years, 5 months
JBoss-OSGI SVN: r97175 - in projects/jboss-osgi/projects/bundles/microcontainer/trunk: src/main/java/org/jboss/osgi/microcontainer and 3 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-30 11:13:33 -0500 (Mon, 30 Nov 2009)
New Revision: 97175
Added:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocator.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocatorMBean.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/DeployerServiceTestCase.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/MicrocontainerServiceRefreshTestCase.java
Removed:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeanDeployer.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/resources/META-INF/base-deployers-beans.xml
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java
Log:
More work on MC service restart issue
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml 2009-11-30 16:09:19 UTC (rev 97174)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml 2009-11-30 16:13:33 UTC (rev 97175)
@@ -49,7 +49,7 @@
<version.jboss.osgi.jaxb>2.1.10-SNAPSHOT</version.jboss.osgi.jaxb>
<version.jboss.osgi.jmx>1.0.2-SNAPSHOT</version.jboss.osgi.jmx>
<version.jboss.osgi.reflect>2.0.2-SNAPSHOT</version.jboss.osgi.reflect>
- <version.jboss.osgi.runtime.deployers>1.0.3</version.jboss.osgi.runtime.deployers>
+ <version.jboss.osgi.runtime.deployers>1.0.3-SNAPSHOT</version.jboss.osgi.runtime.deployers>
<version.jboss.osgi.spi>1.0.3-SNAPSHOT</version.jboss.osgi.spi>
<version.jboss.osgi.xml.binding>2.0.2-SNAPSHOT</version.jboss.osgi.xml.binding>
<version.osgi>4.2.0</version.osgi>
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java 2009-11-30 16:09:19 UTC (rev 97174)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -35,7 +35,6 @@
import org.jboss.osgi.deployment.deployer.DeployerService;
import org.jboss.osgi.deployment.deployer.Deployment;
import org.jboss.osgi.deployment.deployer.DeploymentRegistryService;
-import org.jboss.osgi.spi.OSGiConstants;
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -131,8 +130,7 @@
depList.add(vfsdep);
MutableAttachments att = (MutableAttachments)vfsdep.getPredeterminedManagedObjects();
- att.addAttachment(OSGiConstants.PROPERTY_START_LEVEL, new Integer(dep.getStartLevel()));
- att.addAttachment(OSGiConstants.PROPERTY_AUTO_START, new Boolean(dep.isAutoStart()));
+ att.addAttachment(Deployment.class, dep);
getMainDeployer().addDeployment(vfsdep);
}
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeanDeployer.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeanDeployer.java 2009-11-30 16:09:19 UTC (rev 97174)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeanDeployer.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -27,12 +27,11 @@
import org.jboss.kernel.spi.deployment.KernelDeployment;
import org.jboss.osgi.jbossxb.UnmarshallerService;
import org.jboss.osgi.spi.NotImplementedException;
-import org.jboss.virtual.VirtualFile;
import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
import org.jboss.xb.util.JBossXBHelper;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
+import org.osgi.framework.FrameworkUtil;
import org.xml.sax.InputSource;
/**
@@ -43,33 +42,6 @@
*/
public class EmbeddedBeanDeployer extends BeanDeployer
{
- private BundleContext systemContext;
-
- public void setSystemContext(BundleContext systemContext)
- {
- this.systemContext = systemContext;
- }
-
- static UnmarshallerService getUnmarshallerService(BundleContext context)
- {
- ServiceReference sref = context.getServiceReference(UnmarshallerService.class.getName());
- if (sref == null)
- throw new IllegalStateException("Cannot obtain: " + UnmarshallerService.class.getName());
-
- UnmarshallerService unmarshaller = (UnmarshallerService)context.getService(sref);
- unmarshaller.addClassBinding("urn:jboss:aop-beans:1.0", "org.jboss.aop.microcontainer.beans.metadata.AOPDeployment");
- unmarshaller.addClassBinding("urn:jboss:bean-deployer", "org.jboss.kernel.plugins.deployment.AbstractKernelDeployment10");
- unmarshaller.addClassBinding("urn:jboss:bean-deployer:2.0", "org.jboss.kernel.plugins.deployment.AbstractKernelDeployment");
- unmarshaller.addClassBinding("urn:jboss:javabean:1.0", "org.jboss.javabean.plugins.jaxb.JavaBean10");
- unmarshaller.addClassBinding("urn:jboss:javabean:2.0", "org.jboss.javabean.plugins.jaxb.JavaBean20");
- unmarshaller.addClassBinding("urn:jboss:policy:1.0", "org.jboss.beans.metadata.plugins.policy.AbstractPolicyMetaData");
- unmarshaller.addClassBinding("urn:jboss:classloading:1.0", "org.jboss.classloading.spi.metadata.ClassLoadingMetaData10");
- unmarshaller.addClassBinding("urn:jboss:classloader:1.0", "org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory10");
- unmarshaller.addClassBinding("urn:jboss:deployers:2.0", "org.jboss.deployers.vfs.plugins.xb.SchemaResolverDeployerMetaData");
-
- return unmarshaller;
- }
-
@Override
protected JBossXBHelper<KernelDeployment> getHelper()
{
@@ -86,7 +58,9 @@
@Override
public void setFeature(String featureName, boolean flag) throws Exception
{
- UnmarshallerService unmarshaller = getUnmarshallerService(systemContext);
+ // Get the UnmarshallerService in the context of the microcontainer bundle
+ BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
+ UnmarshallerService unmarshaller = EmbeddedXMLDeployer.getUnmarshallerService(context);
unmarshaller.setFeature(featureName, flag);
}
@@ -94,7 +68,9 @@
@SuppressWarnings("unchecked")
public T parse(InputSource source) throws Exception
{
- UnmarshallerService unmarshaller = getUnmarshallerService(systemContext);
+ // Get the UnmarshallerService in the context of the microcontainer bundle
+ BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
+ UnmarshallerService unmarshaller = EmbeddedXMLDeployer.getUnmarshallerService(context);
return (T)unmarshaller.unmarshal(source);
}
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java 2009-11-30 16:09:19 UTC (rev 97174)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -23,8 +23,6 @@
// $Id$
-import java.net.URL;
-
import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
@@ -40,8 +38,6 @@
{
// Provide logging
private static Logger log = LoggerFactory.getLogger(EmbeddedKernelBootstrap.class);
-
- private EmbeddedXMLDeployer deployer;
public EmbeddedKernelBootstrap(BundleContext context)
{
@@ -57,46 +53,7 @@
{
throw new IllegalStateException("Cannot bootstrap kernel", e);
}
+ kernel = getKernel();
}
- deployer = new EmbeddedXMLDeployer(context, kernel);
}
-
- /**
- * Deploy MC beans from URL
- */
- public void deploy(URL url)
- {
- log.debug("deploy: " + url);
- ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
- deployer.deploy(url);
- deployer.validate();
- }
- catch (Throwable e)
- {
- throw new IllegalStateException("Cannot deploy beans from: " + url, e);
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(ctxLoader);
- }
- }
-
- /**
- * Undeploy MC beans from URL
- */
- public void undeploy(URL url)
- {
- log.debug("undeploy: " + url);
- try
- {
- deployer.undeploy(url);
- }
- catch (Throwable e)
- {
- throw new IllegalStateException("Cannot undeploy beans from: " + url, e);
- }
- }
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java 2009-11-30 16:09:19 UTC (rev 97174)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -24,9 +24,6 @@
// $Id$
import java.net.URL;
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.plugins.deployment.BasicKernelDeployer;
@@ -35,6 +32,7 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.jbossxb.UnmarshallerService;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
/**
* An XML deployer that unlike the {@link BasicXMLDeployer} does not cache
@@ -50,9 +48,6 @@
private BundleContext context;
- /** The deployments by url or name */
- private Map<String, KernelDeployment> deploymentsByName = new ConcurrentHashMap<String, KernelDeployment>();
-
/**
* Create a new XML deployer
*
@@ -65,56 +60,7 @@
this.context = context;
}
- public Collection<String> getDeploymentNames()
- {
- return deploymentsByName.keySet();
- }
-
- public void deploy(KernelDeployment deployment) throws Throwable
- {
- super.deploy(deployment);
- deploymentsByName.put(deployment.getName(), deployment);
- }
-
- public void undeploy(KernelDeployment deployment)
- {
- deploymentsByName.remove(deployment.getName());
- super.undeploy(deployment);
- }
-
/**
- * Undeploy a url
- *
- * @param url the url to undeploy
- * @throws IllegalStateException if the url is unknown
- */
- public void undeploy(final URL url)
- {
- if (url == null)
- throw new IllegalArgumentException("Null url");
-
- undeploy(url.toString());
- }
-
- /**
- * Undeploy a name deployment
- *
- * @param name the name of the deployment to undeploy
- * @throws IllegalStateException if the name is unknown
- */
- public void undeploy(final String name)
- {
- if (name == null)
- throw new IllegalArgumentException("Null name");
-
- KernelDeployment deployment = deploymentsByName.remove(name);
- if (deployment == null)
- throw new IllegalStateException("Unknown deployment " + name);
-
- undeploy(deployment);
- }
-
- /**
* Deploy a url
*
* @param url the url to deploy
@@ -133,7 +79,7 @@
long start = System.currentTimeMillis();
- UnmarshallerService unmarshaller = EmbeddedBeanDeployer.getUnmarshallerService(context);
+ UnmarshallerService unmarshaller = EmbeddedXMLDeployer.getUnmarshallerService(context);
KernelDeployment deployment = (KernelDeployment)unmarshaller.unmarshal(url.toString());
if (deployment == null)
throw new RuntimeException("The xml " + url + " is not well formed!");
@@ -156,4 +102,24 @@
return deployment;
}
+
+ static UnmarshallerService getUnmarshallerService(BundleContext context)
+ {
+ ServiceReference sref = context.getServiceReference(UnmarshallerService.class.getName());
+ if (sref == null)
+ throw new IllegalStateException("Cannot obtain: " + UnmarshallerService.class.getName());
+
+ UnmarshallerService unmarshaller = (UnmarshallerService)context.getService(sref);
+ unmarshaller.addClassBinding("urn:jboss:aop-beans:1.0", "org.jboss.aop.microcontainer.beans.metadata.AOPDeployment");
+ unmarshaller.addClassBinding("urn:jboss:bean-deployer", "org.jboss.kernel.plugins.deployment.AbstractKernelDeployment10");
+ unmarshaller.addClassBinding("urn:jboss:bean-deployer:2.0", "org.jboss.kernel.plugins.deployment.AbstractKernelDeployment");
+ unmarshaller.addClassBinding("urn:jboss:javabean:1.0", "org.jboss.javabean.plugins.jaxb.JavaBean10");
+ unmarshaller.addClassBinding("urn:jboss:javabean:2.0", "org.jboss.javabean.plugins.jaxb.JavaBean20");
+ unmarshaller.addClassBinding("urn:jboss:policy:1.0", "org.jboss.beans.metadata.plugins.policy.AbstractPolicyMetaData");
+ unmarshaller.addClassBinding("urn:jboss:classloading:1.0", "org.jboss.classloading.spi.metadata.ClassLoadingMetaData10");
+ unmarshaller.addClassBinding("urn:jboss:classloader:1.0", "org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory10");
+ unmarshaller.addClassBinding("urn:jboss:deployers:2.0", "org.jboss.deployers.vfs.plugins.xb.SchemaResolverDeployerMetaData");
+
+ return unmarshaller;
+ }
}
\ No newline at end of file
Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocator.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocator.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.microcontainer.internal;
+
+//$Id$
+
+import org.jboss.kernel.Kernel;
+
+/**
+ * An MBean that allows the the microcontainer bundle to
+ * register its kernel instance with the MBeanServer.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 30-Nov-2009
+ */
+public class KernelLocator implements KernelLocatorMBean
+{
+ private Kernel kernel;
+
+ public KernelLocator(Kernel kernel)
+ {
+ this.kernel = kernel;
+ }
+
+ public Kernel getKernel()
+ {
+ return kernel;
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocator.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocatorMBean.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocatorMBean.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocatorMBean.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.microcontainer.internal;
+
+//$Id$
+
+import javax.management.ObjectName;
+
+import org.jboss.kernel.Kernel;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+
+/**
+ * An MBean that allows the the microcontainer bundle to
+ * register its kernel instance with the MBeanServer.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 23-Jan-2009
+ */
+public interface KernelLocatorMBean
+{
+ /**
+ * The object name under which the KernelLocator is registered: 'jboss.osgi:service=KernelLocator'
+ */
+ ObjectName MBEAN_KERNEL_LOCATOR = ObjectNameFactory.create("jboss.osgi:service=KernelLocator");
+
+ Kernel getKernel();
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocatorMBean.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java 2009-11-30 16:09:19 UTC (rev 97174)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -44,18 +44,8 @@
if ("org.jboss.osgi.framework".equals(systemBundleName))
return;
- ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-
- mcService = new MicrocontainerServiceImpl(context);
- mcService.start();
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(ctxLoader);
- }
+ mcService = new MicrocontainerServiceImpl(context);
+ mcService.start();
}
public void stop(BundleContext context)
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java 2009-11-30 16:09:19 UTC (rev 97174)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -58,35 +58,22 @@
public class MicrocontainerServiceImpl extends AbstractMicrocontainerService implements MicrocontainerServiceMBean
{
private BundleContext context;
- private EmbeddedKernelBootstrap deployer;
+ private Kernel kernel;
public MicrocontainerServiceImpl(BundleContext context)
{
this.context = context;
-
VFS.init();
-
- deployer = new EmbeddedKernelBootstrap(context);
}
public Kernel getKernel()
{
- return deployer.getKernel();
+ return kernel;
}
void start()
{
- final MicrocontainerService mcServiceImpl = this;
-
- final Kernel kernel = getKernel();
- final KernelController controller = kernel.getController();
-
- // Preregister some beans
- installBean(controller, BEAN_SYSTEM_BUNDLE_CONTEXT, context);
- installBean(controller, BEAN_KERNEL, kernel);
- installBean(controller, BEAN_KERNEL_CONTROLLER, controller);
-
- // Setup a filter to track both services
+ // Setup a filter to track the JMX and XMLBinding service
Filter filter;
try
{
@@ -99,6 +86,8 @@
throw new IllegalArgumentException("Invalid filter syntax");
}
+ final MicrocontainerService mcService = this;
+
// Register the MicrocontainerServiceMBean
ServiceTracker tracker = new ServiceTracker(context, filter, null)
{
@@ -119,15 +108,10 @@
if (mbeanServer != null && xmlService != null)
{
- // Install the MBeanServer
- installBean(controller, BEAN_MBEAN_SERVER, mbeanServer);
+ initializeMicrocontainerService(mbeanServer);
- // Deploy the deployer beans
- URL deployersURL = context.getBundle().getResource("META-INF/base-deployers-beans.xml");
- deployer.deploy(deployersURL);
-
// Register the MicrocontainerService
- context.registerService(MicrocontainerService.class.getName(), mcServiceImpl, null);
+ context.registerService(MicrocontainerService.class.getName(), mcService, null);
// Register the Microcontainer DeployerService
registerMicrocontainerDeployerService();
@@ -144,25 +128,44 @@
void stop()
{
- Kernel kernel = getKernel();
- KernelController controller = kernel.getController();
-
ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
if (sref != null)
{
MBeanServer mbeanServer = (MBeanServer)context.getService(sref);
unregisterMicrocontainerServiceMBean(mbeanServer);
- uninstallBean(controller, BEAN_MBEAN_SERVER);
}
+ }
- // Undeploy the deployer beans
- URL deployersURL = context.getBundle().getResource("META-INF/base-deployers-beans.xml");
- deployer.undeploy(deployersURL);
-
- // Uninstall preregister some beans
- uninstallBean(controller, BEAN_SYSTEM_BUNDLE_CONTEXT);
- uninstallBean(controller, BEAN_KERNEL);
- uninstallBean(controller, BEAN_KERNEL_CONTROLLER);
+ private void initializeMicrocontainerService(MBeanServer mbeanServer)
+ {
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ EmbeddedKernelBootstrap bootstrap = new EmbeddedKernelBootstrap(context);
+
+ kernel = bootstrap.getKernel();
+ KernelController controller = kernel.getController();
+ BundleContext sysContext = context.getBundle(0).getBundleContext();
+
+ // Preregister some beans
+ installBean(controller, BEAN_BUNDLE_CONTEXT, sysContext);
+ installBean(controller, BEAN_KERNEL, kernel);
+ installBean(controller, BEAN_KERNEL_CONTROLLER, controller);
+ installBean(controller, BEAN_MBEAN_SERVER, mbeanServer);
+
+ // Deploy the deployer beans
+ URL deployersURL = context.getBundle().getResource("META-INF/base-deployers-beans.xml");
+ new EmbeddedXMLDeployer(context, kernel).deploy(deployersURL);
+ }
+ catch (Throwable th)
+ {
+ throw new IllegalStateException("Cannot initilize the MicrocontainerService", th);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(ctxLoader);
+ }
}
private void registerMicrocontainerDeployerService()
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/resources/META-INF/base-deployers-beans.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/resources/META-INF/base-deployers-beans.xml 2009-11-30 16:09:19 UTC (rev 97174)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/resources/META-INF/base-deployers-beans.xml 2009-11-30 16:13:33 UTC (rev 97175)
@@ -52,7 +52,6 @@
<!-- POJO Deployment -->
<bean name="BeanDeployer" class="org.jboss.osgi.microcontainer.internal.EmbeddedBeanDeployer">
- <property name="systemContext"><inject bean="jboss.osgi:service=BundleContext" /></property>
<property name="suffix">jboss-beans.xml</property>
</bean>
<bean name="KernelDeploymentDeployer" class="org.jboss.osgi.deployer.BundleContainedBeansDeployer">
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java 2009-11-30 16:09:19 UTC (rev 97174)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -24,9 +24,15 @@
//$Id: BasicXMLBindingTestCase.java 97031 2009-11-26 14:54:08Z thomas.diesler(a)jboss.com $
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import java.util.List;
+
+import javax.management.ObjectName;
+
import org.jboss.osgi.microcontainer.MicrocontainerCapability;
import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.osgi.spi.management.MicrocontainerServiceMBean;
import org.jboss.osgi.testing.OSGiBundle;
import org.jboss.osgi.testing.OSGiRuntime;
import org.jboss.osgi.testing.OSGiTest;
@@ -48,16 +54,25 @@
try
{
runtime.addCapability(new MicrocontainerCapability());
-
+
OSGiBundle bundle = runtime.installBundle("simple-bundle.jar");
bundle.start();
-
+
// The bean should have registered itself to the MBeanServer
SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class, SomeBeanMBean.MBEAN_NAME, runtime.getMBeanServer());
assertEquals("hello", someBean.echo("hello"));
-
+
// The service should be able to access the bean via the MicrocontainerService
assertEquals("hello", someBean.callSomeService("hello"));
+
+ // Uninstall the user bundle
+ bundle.uninstall();
+
+ // Check that the beans are unregistered
+ ObjectName serviceOName = MicrocontainerServiceMBean.MBEAN_MICROCONTAINER_SERVICE;
+ MicrocontainerServiceMBean mcService = MBeanProxy.get(MicrocontainerServiceMBean.class, serviceOName, runtime.getMBeanServer());
+ List<String> beanNames = mcService.getRegisteredBeans();
+ assertFalse("SomeBean unregistered " + beanNames, beanNames.contains("SomeBean"));
}
finally
{
Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/DeployerServiceTestCase.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/DeployerServiceTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/DeployerServiceTestCase.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.test.osgi.microcontainer;
+
+//$Id$
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.jboss.osgi.deployment.deployer.DeployerService;
+import org.jboss.osgi.microcontainer.MicrocontainerCapability;
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiServiceReference;
+import org.jboss.osgi.testing.OSGiTest;
+import org.junit.Test;
+
+/**
+ * Test Microcontainer DeployerService
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 26-Nov-2009
+ */
+public class DeployerServiceTestCase extends OSGiTest
+{
+ @Test
+ public void testMicrocontainerService() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ OSGiServiceReference sref = runtime.getServiceReference(DeployerService.class.getName());
+ assertNotNull("DeployerService", sref);
+ assertEquals("system", sref.getProperty("provider"));
+
+ runtime.addCapability(new MicrocontainerCapability());
+ OSGiBundle serviceBundle = runtime.getBundle("jboss-osgi-microcontainer", null);
+
+ sref = runtime.getServiceReference(DeployerService.class.getName());
+ assertNotNull("DeployerService", sref);
+ assertEquals("microcontainer", sref.getProperty("provider"));
+
+ // Uninstall the mc service bundle
+ serviceBundle.uninstall();
+
+ sref = runtime.getServiceReference(DeployerService.class.getName());
+ assertNotNull("DeployerService", sref);
+ assertEquals("system", sref.getProperty("provider"));
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/DeployerServiceTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/MicrocontainerServiceRefreshTestCase.java (from rev 97156, projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/MicrocontainerServiceRefreshTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/MicrocontainerServiceRefreshTestCase.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.test.osgi.microcontainer;
+
+//$Id: BasicXMLBindingTestCase.java 97031 2009-11-26 14:54:08Z thomas.diesler(a)jboss.com $
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.jboss.osgi.microcontainer.MicrocontainerCapability;
+import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.osgi.spi.service.MicrocontainerService;
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiPackageAdmin;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiServiceReference;
+import org.jboss.osgi.testing.OSGiTest;
+import org.jboss.test.osgi.microcontainer.simple.SomeBeanMBean;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ * Test MicrocontainerService restart
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 26-Nov-2009
+ */
+public class MicrocontainerServiceRefreshTestCase extends OSGiTest
+{
+ @Test
+ public void testMicrocontainerService() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ runtime.addCapability(new MicrocontainerCapability());
+
+ OSGiBundle serviceBundle = runtime.getBundle("jboss-osgi-microcontainer", null);
+ assertEquals("MicrocontainerService ACTIVE", Bundle.ACTIVE, serviceBundle.getState());
+
+ OSGiBundle bundle = runtime.installBundle("simple-bundle.jar");
+ bundle.start();
+
+ // The service should be able to access the bean via the MicrocontainerService
+ SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class, SomeBeanMBean.MBEAN_NAME, runtime.getMBeanServer());
+ assertEquals("hello", someBean.callSomeService("hello"));
+
+ // Uninstall the user bundle
+ bundle.uninstall();
+
+ // Refresh all packages. This should stop/start the MC bundle
+ OSGiPackageAdmin packageAdmin = runtime.getPackageAdmin();
+ packageAdmin.refreshPackages(null);
+
+ // Wait some time for the refresh to finish
+ Thread.sleep(1000);
+
+ // Check if the MC bundle is still active (or could be restarted)
+ assertEquals("MicrocontainerService ACTIVE", Bundle.ACTIVE, serviceBundle.getState());
+
+ // Check if the service is available
+ OSGiServiceReference sref = runtime.getServiceReference(MicrocontainerService.class.getName());
+ assertNotNull("MicrocontainerService available", sref);
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
+}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java 2009-11-30 16:09:19 UTC (rev 97174)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java 2009-11-30 16:13:33 UTC (rev 97175)
@@ -1,83 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.test.osgi.microcontainer;
-
-//$Id: BasicXMLBindingTestCase.java 97031 2009-11-26 14:54:08Z thomas.diesler(a)jboss.com $
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.jboss.osgi.microcontainer.MicrocontainerCapability;
-import org.jboss.osgi.spi.management.MBeanProxy;
-import org.jboss.osgi.spi.service.MicrocontainerService;
-import org.jboss.osgi.testing.OSGiBundle;
-import org.jboss.osgi.testing.OSGiPackageAdmin;
-import org.jboss.osgi.testing.OSGiRuntime;
-import org.jboss.osgi.testing.OSGiServiceReference;
-import org.jboss.osgi.testing.OSGiTest;
-import org.jboss.test.osgi.microcontainer.simple.SomeBeanMBean;
-import org.junit.Ignore;
-import org.junit.Test;
-
-/**
- * Test MicrocontainerService
- *
- * @author thomas.diesler(a)jboss.com
- * @since 26-Nov-2009
- */
-@Ignore
-public class RefreshMicrocontainerServiceTestCase extends OSGiTest
-{
- @Test
- public void testMicrocontainerService() throws Exception
- {
- OSGiRuntime runtime = getDefaultRuntime();
- try
- {
- runtime.addCapability(new MicrocontainerCapability());
-
- OSGiBundle bundle = runtime.installBundle("simple-bundle.jar");
- bundle.start();
-
- // The service should be able to access the bean via the MicrocontainerService
- SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class, SomeBeanMBean.MBEAN_NAME, runtime.getMBeanServer());
- assertEquals("hello", someBean.callSomeService("hello"));
-
- // Uninstall the user bundle
- bundle.uninstall();
-
- // Refresh all packages. This should stop/start the MC bundle
- OSGiPackageAdmin packageAdmin = runtime.getPackageAdmin();
- packageAdmin.refreshPackages(null);
-
- // Wait some time for the refresh to finish
- Thread.sleep(1000);
-
- OSGiServiceReference sref = runtime.getServiceReference(MicrocontainerService.class.getName());
- assertNotNull("MicrocontainerService available", sref);
- }
- finally
- {
- runtime.shutdown();
- }
- }
-}
\ No newline at end of file
14 years, 5 months
JBoss-OSGI SVN: r97174 - in projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk: src/main/java/org/jboss/osgi/jbossxb/internal and 3 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-30 11:09:19 -0500 (Mon, 30 Nov 2009)
New Revision: 97174
Added:
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingDocumentBuilderFactory.java
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingSAXParserFactory.java
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/java/org/jboss/test/osgi/jbossxb/refresh/UnmarshallerServiceRefreshTestCase.java
Removed:
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/DocumentBuilderFactoryOSGi.java
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/SAXParserFactoryOSGi.java
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/java/org/jboss/test/osgi/jbossxb/refresh/RefreshServiceTestCase.java
Modified:
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/pom.xml
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/UnmarshallerServiceImpl.java
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingActivator.java
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/resources/META-INF/services/javax.xml.parsers.DocumentBuilderFactory
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/resources/META-INF/services/javax.xml.parsers.SAXParserFactory
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/resources/jboss-osgi-framework.properties
Log:
Delegate to SAXParserFactory and DocumentBuilderFactory services
Modified: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/pom.xml 2009-11-30 16:06:48 UTC (rev 97173)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/pom.xml 2009-11-30 16:09:19 UTC (rev 97174)
@@ -161,7 +161,6 @@
org.w3c.dom*,
org.xml.sax*,
- <!-- import -->
com.wutka.dtd,
org.apache.xerces.*,
org.jboss.logging,
Deleted: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/DocumentBuilderFactoryOSGi.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/DocumentBuilderFactoryOSGi.java 2009-11-30 16:06:48 UTC (rev 97173)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/DocumentBuilderFactoryOSGi.java 2009-11-30 16:09:19 UTC (rev 97174)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.jbossxb.internal;
-
-//$Id$
-
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
-
-/**
- * A {@link DocumentBuilderFactory}
- *
- * @author thomas.diesler(a)jboss.com
- * @since 13-May-2009
- */
-public class DocumentBuilderFactoryOSGi extends DocumentBuilderFactoryImpl
-{
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/SAXParserFactoryOSGi.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/SAXParserFactoryOSGi.java 2009-11-30 16:06:48 UTC (rev 97173)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/SAXParserFactoryOSGi.java 2009-11-30 16:09:19 UTC (rev 97174)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.jbossxb.internal;
-
-//$Id$
-
-import javax.xml.parsers.SAXParserFactory;
-
-import org.apache.xerces.jaxp.SAXParserFactoryImpl;
-
-/**
- * A {@link SAXParserFactory}
- *
- * @author thomas.diesler(a)jboss.com
- * @since 13-May-2009
- */
-public class SAXParserFactoryOSGi extends SAXParserFactoryImpl
-{
-}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/UnmarshallerServiceImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/UnmarshallerServiceImpl.java 2009-11-30 16:06:48 UTC (rev 97173)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/UnmarshallerServiceImpl.java 2009-11-30 16:09:19 UTC (rev 97174)
@@ -64,11 +64,35 @@
schemaBindingResolver = new DefaultSchemaResolver();
bundleLoader = BundleClassLoader.createClassLoader(context.getBundle());
log.debug("UnmarshallerService using: " + bundleLoader);
+
+ // Initialize the JBossXB unmarshaller in the context of this bundle
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ unmarshaller = factory.newUnmarshaller();
+ }
+ catch (Throwable th)
+ {
+ log.error("Cannot initialze unmarshaller", th);
+ if (th instanceof RuntimeException)
+ throw (RuntimeException)th;
+ if (th instanceof Error)
+ throw (Error)th;
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(ctxLoader);
+ }
}
public void setFeature(String featureName, boolean flag)
{
factory.setFeature(featureName, flag);
+
+ // A feature change dicards a previously used unmarshaller
+ // The factory constructs a new one with the canged feature set.
+ unmarshaller = null;
}
public void setNamespaceAware(boolean namespaces)
@@ -137,11 +161,13 @@
{
Thread.currentThread().setContextClassLoader(bundleLoader);
schemaBindingResolver.addClassBinding(nsUri, className);
- log.debug("Add mapping of '" + nsUri + "' to " + className);
+ if (log.isTraceEnabled())
+ log.trace("Add mapping of '" + nsUri + "' to " + className);
}
catch (ClassNotFoundException ex)
{
- log.debug("Ignore mapping of '" + nsUri + "' to " + className);
+ if (log.isTraceEnabled())
+ log.trace("Ignore mapping of '" + nsUri + "' to " + className);
}
finally
{
Modified: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingActivator.java 2009-11-30 16:06:48 UTC (rev 97173)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingActivator.java 2009-11-30 16:09:19 UTC (rev 97174)
@@ -29,8 +29,6 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* A {@link BundleActivator} that initializes the JBossXB bundle
@@ -40,23 +38,26 @@
*/
public class XMLBindingActivator implements BundleActivator
{
- // Provide logging
- private static Logger log = LoggerFactory.getLogger(XMLBindingActivator.class);
-
public void start(BundleContext context) throws Exception
{
- ServiceFactory unmarshallerFactory = new ServiceFactory()
+ // Register a service factory that creates an JBossXB unmarshaller
+ // in the context of the client bundle
+ ServiceFactory serviceFactory = new ServiceFactory()
{
public Object getService(Bundle bundle, ServiceRegistration registration)
{
+ XMLBindingSAXParserFactory.setBundleContext(bundle.getBundleContext());
+ XMLBindingDocumentBuilderFactory.setBundleContext(bundle.getBundleContext());
return new UnmarshallerServiceImpl(bundle.getBundleContext());
}
public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
{
+ XMLBindingSAXParserFactory.setBundleContext(null);
+ XMLBindingDocumentBuilderFactory.setBundleContext(null);
}
};
- context.registerService(UnmarshallerService.class.getName(), unmarshallerFactory, null);
+ context.registerService(UnmarshallerService.class.getName(), serviceFactory, null);
}
public void stop(BundleContext context) throws Exception
Copied: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingDocumentBuilderFactory.java (from rev 97156, projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/DocumentBuilderFactoryOSGi.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingDocumentBuilderFactory.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingDocumentBuilderFactory.java 2009-11-30 16:09:19 UTC (rev 97174)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jbossxb.internal;
+
+//$Id$
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.xml.XMLParserActivator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A {@link DocumentBuilderFactory}
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 13-May-2009
+ */
+public class XMLBindingDocumentBuilderFactory extends DocumentBuilderFactory
+{
+ // Provide logging
+ private static Logger log;
+
+ private static BundleContext context;
+ private Map<String, Boolean> features = new HashMap<String, Boolean>();
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ public static void setBundleContext(BundleContext context)
+ {
+ // The log4j initialization routine may use this DocumentBuilderFactory
+ // Only create the logger, when we are running in an OSGi context
+ log = LoggerFactory.getLogger(XMLBindingDocumentBuilderFactory.class);
+
+ XMLBindingDocumentBuilderFactory.context = context;
+ }
+
+ @Override
+ public boolean getFeature(String name)
+ {
+ Boolean value = features.get(name);
+ return value != null ? value.booleanValue() : false;
+ }
+
+ @Override
+ public void setFeature(String name, boolean value)
+ {
+ features.put(name, new Boolean(value));
+ }
+
+ @Override
+ public Object getAttribute(String name)
+ {
+ return attributes.get(name);
+ }
+
+ @Override
+ public void setAttribute(String name, Object value)
+ {
+ attributes.put(name, value);
+ }
+
+ /**
+ * Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder} using the currently configured parameters.
+ *
+ * If the bundle context is available, which would be the case if this bundle was started
+ * try using the registered DocumentBuilderFactory service.
+ *
+ * If there is no DocumentBuilderFactory service for the given parameters, use the Apache Xerces DocumentBuilderFactoryImpl.
+ */
+ @Override
+ public DocumentBuilder newDocumentBuilder() throws ParserConfigurationException
+ {
+ String validating = "(" + XMLParserActivator.PARSER_VALIDATING + "=" + isValidating() + ")";
+ String namespaceAware = "(" + XMLParserActivator.PARSER_NAMESPACEAWARE + "=" + isNamespaceAware() + ")";
+ String filter = "(&" + validating + namespaceAware + ")";
+
+ DocumentBuilderFactory factory = null;
+
+ // First try to obtain the DocumentBuilderFactory service
+ if (context != null)
+ {
+ try
+ {
+ ServiceReference[] srefs = context.getServiceReferences(DocumentBuilderFactory.class.getName(), filter);
+ if (srefs != null)
+ {
+ if (srefs.length > 1)
+ logDebug("Multiple DocumentBuilderFactory services: " + Arrays.asList(srefs));
+
+ logDebug("Using DocumentBuilderFactory service: " + srefs[0]);
+ factory = (DocumentBuilderFactory)context.getService(srefs[0]);
+ }
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ // ignore
+ }
+ }
+
+ // Fall back to Apache Xerces DocumentBuilderFactoryImpl
+ if (factory == null)
+ {
+ logDebug("Cannot obtain DocumentBuilderFactory service " + filter + ". Now use " + DocumentBuilderFactoryImpl.class.getName());
+ factory = new DocumentBuilderFactoryImpl();
+ }
+
+ // Set the features on the factory
+ for (Map.Entry<String, Boolean> entry : features.entrySet())
+ {
+ logDebug("Set feature [" + entry.getKey() + "=" + entry.getValue() + "]");
+ factory.setFeature(entry.getKey(), entry.getValue());
+ }
+
+ // Set the attributes on the factory
+ for (Map.Entry<String, Object> entry : attributes.entrySet())
+ {
+ logDebug("Set attribute [" + entry.getKey() + "=" + entry.getValue() + "]");
+ factory.setAttribute(entry.getKey(), entry.getValue());
+ }
+
+ return factory.newDocumentBuilder();
+ }
+
+ private void logDebug(String message)
+ {
+ if (log != null)
+ log.debug(message);
+ }
+}
\ No newline at end of file
Copied: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingSAXParserFactory.java (from rev 97156, projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/SAXParserFactoryOSGi.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingSAXParserFactory.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingSAXParserFactory.java 2009-11-30 16:09:19 UTC (rev 97174)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jbossxb.internal;
+
+//$Id$
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.xerces.jaxp.SAXParserFactoryImpl;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.xml.XMLParserActivator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
+
+/**
+ * A {@link SAXParserFactory}
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 13-May-2009
+ */
+public class XMLBindingSAXParserFactory extends SAXParserFactory
+{
+ // Provide logging
+ private static Logger log;
+
+ private static BundleContext context;
+ private Map<String, Boolean> features = new HashMap<String, Boolean>();
+
+ public static void setBundleContext(BundleContext context)
+ {
+ // The log4j initialization routine may use this DocumentBuilderFactory
+ // Only create the logger, when we are running in an OSGi context
+ log = LoggerFactory.getLogger(XMLBindingSAXParserFactory.class);
+
+ XMLBindingSAXParserFactory.context = context;
+ }
+
+ @Override
+ public boolean getFeature(String name)
+ {
+ Boolean value = features.get(name);
+ return value != null ? value.booleanValue() : false;
+ }
+
+ @Override
+ public void setFeature(String name, boolean value)
+ {
+ features.put(name, new Boolean(value));
+ }
+
+ /**
+ * Creates a new instance of a {@link javax.xml.parsers.SAXParserFactory} using the currently configured parameters.
+ *
+ * If the bundle context is available, which would be the case if this bundle was started
+ * try using the registered SAXParserFactory service.
+ *
+ * If there is no SAXParserFactory service for the given parameters, use the Apache Xerces SAXParserFactoryImpl.
+ */
+ @Override
+ public SAXParser newSAXParser() throws ParserConfigurationException, SAXException
+ {
+ String validating = "(" + XMLParserActivator.PARSER_VALIDATING + "=" + isValidating() + ")";
+ String namespaceAware = "(" + XMLParserActivator.PARSER_NAMESPACEAWARE + "=" + isNamespaceAware() + ")";
+ String filter = "(&" + validating + namespaceAware + ")";
+
+ SAXParserFactory factory = null;
+
+ // First try to obtain the SAXParserFactory service
+ if (context != null)
+ {
+ try
+ {
+ ServiceReference[] srefs = context.getServiceReferences(SAXParserFactory.class.getName(), filter);
+ if (srefs != null)
+ {
+ if (srefs.length > 1)
+ logDebug("Multiple SAXParserFactory services: " + Arrays.asList(srefs));
+
+ logDebug("Using SAXParserFactory service: " + srefs[0]);
+ factory = (SAXParserFactory)context.getService(srefs[0]);
+ }
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ // ignore
+ }
+ }
+
+ // Fall back to Apache Xerces SAXParserFactoryImpl
+ if (factory == null)
+ {
+ logDebug("Cannot obtain SAXParserFactory service " + filter + ". Now use " + SAXParserFactoryImpl.class.getName());
+ factory = new SAXParserFactoryImpl();
+ }
+
+ // Set the features on the factory
+ for (Map.Entry<String, Boolean> entry : features.entrySet())
+ {
+ logDebug("Set feature [" + entry.getKey() + "=" + entry.getValue() + "]");
+ factory.setFeature(entry.getKey(), entry.getValue());
+ }
+
+ return factory.newSAXParser();
+ }
+
+ private void logDebug(String message)
+ {
+ if (log != null)
+ log.debug(message);
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/resources/META-INF/services/javax.xml.parsers.DocumentBuilderFactory
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/resources/META-INF/services/javax.xml.parsers.DocumentBuilderFactory 2009-11-30 16:06:48 UTC (rev 97173)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/resources/META-INF/services/javax.xml.parsers.DocumentBuilderFactory 2009-11-30 16:09:19 UTC (rev 97174)
@@ -1 +1 @@
-org.jboss.osgi.jbossxb.internal.DocumentBuilderFactoryOSGi
\ No newline at end of file
+org.jboss.osgi.jbossxb.internal.XMLBindingDocumentBuilderFactory
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/resources/META-INF/services/javax.xml.parsers.SAXParserFactory
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/resources/META-INF/services/javax.xml.parsers.SAXParserFactory 2009-11-30 16:06:48 UTC (rev 97173)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/main/resources/META-INF/services/javax.xml.parsers.SAXParserFactory 2009-11-30 16:09:19 UTC (rev 97174)
@@ -1 +1 @@
-org.jboss.osgi.jbossxb.internal.SAXParserFactoryOSGi
\ No newline at end of file
+org.jboss.osgi.jbossxb.internal.XMLBindingSAXParserFactory
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/java/org/jboss/test/osgi/jbossxb/refresh/RefreshServiceTestCase.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/java/org/jboss/test/osgi/jbossxb/refresh/RefreshServiceTestCase.java 2009-11-30 16:06:48 UTC (rev 97173)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/java/org/jboss/test/osgi/jbossxb/refresh/RefreshServiceTestCase.java 2009-11-30 16:09:19 UTC (rev 97174)
@@ -1,86 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.test.osgi.jbossxb.refresh;
-
-//$Id: BasicXMLBindingTestCase.java 97031 2009-11-26 14:54:08Z thomas.diesler(a)jboss.com $
-
-import static org.junit.Assert.*;
-import static org.junit.Assume.assumeNotNull;
-
-import org.jboss.osgi.husky.BridgeFactory;
-import org.jboss.osgi.husky.HuskyCapability;
-import org.jboss.osgi.husky.RuntimeContext;
-import org.jboss.osgi.jbossxb.XMLBindingCapability;
-import org.jboss.osgi.testing.OSGiBundle;
-import org.jboss.osgi.testing.OSGiPackageAdmin;
-import org.jboss.osgi.testing.OSGiRuntime;
-import org.jboss.osgi.testing.OSGiTest;
-import org.jboss.test.osgi.jbossxb.simple.bundle.BookingActivator;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.packageadmin.PackageAdmin;
-
-/**
- * Test XMLBindingService
- *
- * @author thomas.diesler(a)jboss.com
- * @since 26-Nov-2009
- */
-public class RefreshServiceTestCase extends OSGiTest
-{
- @Test
- public void testUnmarshaller() throws Exception
- {
- OSGiRuntime runtime = getDefaultRuntime();
- try
- {
- runtime.addCapability(new XMLBindingCapability());
-
- OSGiBundle serviceBundle = runtime.getBundle("jboss-osgi-xml-binding", null);
- serviceBundle.start();
-
- OSGiBundle userBundle = runtime.installBundle("simple-booking.jar");
- userBundle.start();
- userBundle.uninstall();
-
- serviceBundle.uninstall();
-
- OSGiPackageAdmin packageAdmin = runtime.getPackageAdmin();
- packageAdmin.refreshPackages(null);
-
- serviceBundle = runtime.installBundle("bundles/jboss-osgi-xml-binding.jar");
- serviceBundle.start();
-
- userBundle = runtime.installBundle("simple-booking.jar");
- userBundle.start();
- }
- finally
- {
- runtime.shutdown();
- }
- }
-}
\ No newline at end of file
Copied: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/java/org/jboss/test/osgi/jbossxb/refresh/UnmarshallerServiceRefreshTestCase.java (from rev 97156, projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/java/org/jboss/test/osgi/jbossxb/refresh/RefreshServiceTestCase.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/java/org/jboss/test/osgi/jbossxb/refresh/UnmarshallerServiceRefreshTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/java/org/jboss/test/osgi/jbossxb/refresh/UnmarshallerServiceRefreshTestCase.java 2009-11-30 16:09:19 UTC (rev 97174)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.test.osgi.jbossxb.refresh;
+
+//$Id: BasicXMLBindingTestCase.java 97031 2009-11-26 14:54:08Z thomas.diesler(a)jboss.com $
+
+import org.jboss.osgi.jbossxb.XMLBindingCapability;
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiPackageAdmin;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiTest;
+import org.junit.Test;
+
+/**
+ * Test XMLBindingService
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 26-Nov-2009
+ */
+public class UnmarshallerServiceRefreshTestCase extends OSGiTest
+{
+ @Test
+ public void testUnmarshaller() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ runtime.addCapability(new XMLBindingCapability());
+
+ OSGiBundle serviceBundle = runtime.getBundle("jboss-osgi-xml-binding", null);
+ serviceBundle.start();
+
+ OSGiBundle userBundle = runtime.installBundle("simple-booking.jar");
+ userBundle.start();
+ userBundle.uninstall();
+
+ serviceBundle.uninstall();
+
+ OSGiPackageAdmin packageAdmin = runtime.getPackageAdmin();
+ packageAdmin.refreshPackages(null);
+
+ serviceBundle = runtime.installBundle("bundles/jboss-osgi-xml-binding.jar");
+ serviceBundle.start();
+
+ userBundle = runtime.installBundle("simple-booking.jar");
+ userBundle.start();
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/resources/jboss-osgi-framework.properties
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/resources/jboss-osgi-framework.properties 2009-11-30 16:06:48 UTC (rev 97173)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/src/test/resources/jboss-osgi-framework.properties 2009-11-30 16:09:19 UTC (rev 97174)
@@ -4,12 +4,15 @@
# $Id$
#
+# Felix config properties
+felix.bootdelegation.implicit=false
+
# Properties to configure the Framework
org.osgi.framework.storage=${test.archive.directory}/../osgi-store
org.osgi.framework.storage.clean=onFirstInit
# Framework bootdelegation
-# org.osgi.framework.bootdelegation=
+org.osgi.framework.bootdelegation=sun.reflect
# Extra System Packages
org.osgi.framework.system.packages.extra=\
14 years, 5 months
JBoss-OSGI SVN: r97173 - in projects/jboss-osgi/projects/runtime/deployers/trunk: src/main/java/org/jboss/osgi/deployer and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-30 11:06:48 -0500 (Mon, 30 Nov 2009)
New Revision: 97173
Modified:
projects/jboss-osgi/projects/runtime/deployers/trunk/pom.xml
projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaDataDeployer.java
projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartLevelDeployer.java
projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
Log:
Use Deployment.class instead of individual property attachments
Modified: projects/jboss-osgi/projects/runtime/deployers/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/deployers/trunk/pom.xml 2009-11-30 16:06:26 UTC (rev 97172)
+++ projects/jboss-osgi/projects/runtime/deployers/trunk/pom.xml 2009-11-30 16:06:48 UTC (rev 97173)
@@ -20,7 +20,7 @@
<artifactId>jboss-osgi-deployers</artifactId>
<packaging>jar</packaging>
- <version>1.0.4-SNAPSHOT</version>
+ <version>1.0.3-SNAPSHOT</version>
<!-- Parent -->
<parent>
@@ -30,8 +30,9 @@
</parent>
<properties>
- <version.jboss.deployers>2.0.8.GA</version.jboss.deployers>
- <version.jboss.osgi.spi>1.0.3</version.jboss.osgi.spi>
+ <version.jboss.deployers>2.0.9.GA</version.jboss.deployers>
+ <version.jboss.osgi.deployment>1.0.0</version.jboss.osgi.deployment>
+ <version.jboss.osgi.spi>1.0.3-SNAPSHOT</version.jboss.osgi.spi>
<version.osgi>4.2.0</version.osgi>
</properties>
@@ -43,6 +44,11 @@
<version>${version.jboss.osgi.spi}</version>
</dependency>
<dependency>
+ <groupId>org.jboss.osgi.runtime</groupId>
+ <artifactId>jboss-osgi-deployment</artifactId>
+ <version>${version.jboss.osgi.deployment}</version>
+ </dependency>
+ <dependency>
<groupId>org.jboss.deployers</groupId>
<artifactId>jboss-deployers-vfs</artifactId>
<version>${version.jboss.deployers}</version>
Modified: projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaDataDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaDataDeployer.java 2009-11-30 16:06:26 UTC (rev 97172)
+++ projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaDataDeployer.java 2009-11-30 16:06:48 UTC (rev 97173)
@@ -28,6 +28,7 @@
import org.jboss.deployers.vfs.spi.deployer.ManifestDeployer;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.osgi.deployment.deployer.Deployment;
import org.jboss.osgi.spi.OSGiConstants;
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.Constants;
@@ -45,6 +46,7 @@
public BundleMetaDataDeployer()
{
super(BundleMetaData.class);
+ addInput(Deployment.class);
}
@Override
@@ -56,7 +58,8 @@
String symbolicName = metaData.getSymbolicName();
log.debug("Bundle-SymbolicName: " + symbolicName + " in " + file);
- metaData.setBundleLocation(unit.getRoot().toURL());
+ Deployment dep = unit.getAttachment(Deployment.class);
+ metaData.setBundleLocation(dep.getLocation());
// Add a marker that this is an OSGi deployment
unit.addAttachment(OSGiConstants.KEY_BUNDLE_SYMBOLIC_NAME, symbolicName);
Modified: projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartLevelDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartLevelDeployer.java 2009-11-30 16:06:26 UTC (rev 97172)
+++ projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartLevelDeployer.java 2009-11-30 16:06:48 UTC (rev 97173)
@@ -26,7 +26,7 @@
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.spi.OSGiConstants;
+import org.jboss.osgi.deployment.deployer.Deployment;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.service.startlevel.StartLevel;
@@ -50,7 +50,7 @@
public BundleStartLevelDeployer()
{
super(Bundle.class);
- addOutput(OSGiConstants.PROPERTY_START_LEVEL);
+ addInput(Deployment.class);
}
public void setSystemContext(BundleContext systemContext)
@@ -60,7 +60,9 @@
public void deploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
{
- Integer propStart = unit.getAttachment(OSGiConstants.PROPERTY_START_LEVEL, Integer.class);
+ Deployment dep = unit.getAttachment(Deployment.class);
+ Integer propStart = dep.getStartLevel();
+
StartLevel startLevel = getStartLevel();
if (propStart != null && startLevel != null)
{
Modified: projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java 2009-11-30 16:06:26 UTC (rev 97172)
+++ projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java 2009-11-30 16:06:48 UTC (rev 97173)
@@ -30,6 +30,7 @@
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.deployment.deployer.Deployment;
import org.jboss.osgi.spi.OSGiConstants;
import org.jboss.osgi.spi.util.ExportedPackageHelper;
import org.osgi.framework.Bundle;
@@ -56,7 +57,7 @@
public BundleStartStopDeployer()
{
super(Bundle.class);
- addInput(OSGiConstants.PROPERTY_START_LEVEL);
+ addInput(Deployment.class);
}
public void setSystemContext(BundleContext systemContext)
@@ -66,9 +67,8 @@
public void deploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
{
- Boolean autoStart = unit.getAttachment(OSGiConstants.PROPERTY_AUTO_START, Boolean.class);
- if (autoStart == null)
- autoStart = Boolean.TRUE;
+ Deployment dep = unit.getAttachment(Deployment.class);
+ boolean autoStart = dep.isAutoStart();
if (autoStart == true)
{
14 years, 5 months
JBoss-OSGI SVN: r97172 - in projects/jboss-osgi/projects/bundles/husky/trunk: .settings and 2 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-30 11:06:26 -0500 (Mon, 30 Nov 2009)
New Revision: 97172
Added:
projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiBundleImpl.java
Modified:
projects/jboss-osgi/projects/bundles/husky/trunk/.classpath
projects/jboss-osgi/projects/bundles/husky/trunk/.project
projects/jboss-osgi/projects/bundles/husky/trunk/.settings/org.eclipse.jdt.core.prefs
projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiBundle.java
projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java
projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java
Log:
Delegate OSGiBundle.uninstall() to DeployerService
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/.classpath
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/.classpath 2009-11-30 16:04:13 UTC (rev 97171)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/.classpath 2009-11-30 16:06:26 UTC (rev 97172)
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/.project
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/.project 2009-11-30 16:04:13 UTC (rev 97171)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/.project 2009-11-30 16:06:26 UTC (rev 97172)
@@ -6,13 +6,8 @@
</projects>
<buildSpec>
<buildCommand>
- <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
- <triggers>full,incremental,</triggers>
+ <name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
- <dictionary>
- <key>LaunchConfigHandle</key>
- <value><project>/.externalToolBuilders/org.eclipse.jdt.core.javabuilder.launch</value>
- </dictionary>
</arguments>
</buildCommand>
<buildCommand>
@@ -22,7 +17,7 @@
</buildCommand>
</buildSpec>
<natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/.settings/org.eclipse.jdt.core.prefs 2009-11-30 16:04:13 UTC (rev 97171)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/.settings/org.eclipse.jdt.core.prefs 2009-11-30 16:06:26 UTC (rev 97172)
@@ -1,5 +1,6 @@
-#Fri May 15 00:24:23 CEST 2009
+#Mon Nov 30 15:53:56 CET 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiBundle.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiBundle.java 2009-11-30 16:04:13 UTC (rev 97171)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiBundle.java 2009-11-30 16:06:26 UTC (rev 97172)
@@ -51,6 +51,11 @@
public abstract Version getVersion();
/**
+ * Returns this bundle's location.
+ */
+ public abstract String getLocation();
+
+ /**
* Returns this bundle's Manifest headers and values.
*/
public abstract Dictionary<String, String> getHeaders();
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2009-11-30 16:04:13 UTC (rev 97171)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2009-11-30 16:06:26 UTC (rev 97172)
@@ -174,7 +174,7 @@
throw new IllegalArgumentException("Cannot obtain '" + testArchiveDir + "/" + archive + "'.");
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({ "unchecked", "rawtypes" })
public InitialContext getInitialContext() throws NamingException
{
String port = System.getProperty("jndi.server.port", "1099");
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java 2009-11-30 16:04:13 UTC (rev 97171)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java 2009-11-30 16:06:26 UTC (rev 97172)
@@ -21,13 +21,18 @@
*/
package org.jboss.osgi.testing.internal;
+import java.net.URL;
import java.util.Dictionary;
+import org.jboss.osgi.deployment.deployer.DeployerService;
import org.jboss.osgi.spi.util.ExportedPackageHelper;
-import org.jboss.osgi.testing.OSGiBundle;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* An OSGi Test Case
@@ -35,14 +40,16 @@
* @author Thomas.Diesler(a)jboss.org
* @since 25-Sep-2008
*/
-public class EmbeddedBundle extends OSGiBundle
+public class EmbeddedBundle extends OSGiBundleImpl
{
- private OSGiRuntimeImpl runtime;
+ // Provide logging
+ private final Logger log = LoggerFactory.getLogger(EmbeddedBundle.class);
+
private Bundle bundle;
public EmbeddedBundle(OSGiRuntimeImpl runtime, Bundle bundle)
{
- this.runtime = runtime;
+ super(runtime);
this.bundle = bundle;
}
@@ -70,6 +77,12 @@
}
@Override
+ public String getLocation()
+ {
+ return bundle.getLocation();
+ }
+
+ @Override
@SuppressWarnings("unchecked")
public Dictionary<String, String> getHeaders()
{
@@ -106,7 +119,31 @@
@Override
public void uninstall() throws BundleException
{
- bundle.uninstall();
- runtime.unregisterBundle(this);
+ assertNotUninstalled();
+ try
+ {
+ BundleContext context = bundle.getBundleContext();
+ ServiceReference sref = context.getServiceReference(DeployerService.class.getName());
+ if (sref != null)
+ {
+ DeployerService service = (DeployerService)context.getService(sref);
+ service.undeploy(new URL(getLocation()));
+ }
+ else
+ {
+ bundle.uninstall();
+ }
+ getRuntime().unregisterBundle(this);
+ setUninstalled(true);
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ log.error("Cannot uninstall: " + getLocation(), ex);
+ }
}
+
}
Added: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiBundleImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiBundleImpl.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiBundleImpl.java 2009-11-30 16:06:26 UTC (rev 97172)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.testing.internal;
+
+// $Id$
+
+import org.jboss.osgi.testing.OSGiBundle;
+
+/**
+ * An abstract implementation of a {@link OSGiBundle}
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 25-Sep-2008
+ */
+public abstract class OSGiBundleImpl extends OSGiBundle
+{
+ private OSGiRuntimeImpl runtime;
+ private boolean uninstalled;
+
+ OSGiBundleImpl(OSGiRuntimeImpl runtime)
+ {
+ this.runtime = runtime;
+ }
+
+ OSGiRuntimeImpl getRuntime()
+ {
+ return runtime;
+ }
+
+ boolean isUninstalled()
+ {
+ return uninstalled;
+ }
+
+ void setUninstalled(boolean uninstalled)
+ {
+ this.uninstalled = uninstalled;
+ }
+
+ void assertNotUninstalled()
+ {
+ if (uninstalled == true)
+ throw new IllegalStateException("Bundle already uninstalled: " + getLocation());
+ }
+}
Property changes on: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiBundleImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java 2009-11-30 16:04:13 UTC (rev 97171)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java 2009-11-30 16:06:26 UTC (rev 97172)
@@ -165,16 +165,14 @@
log.debug("End Shutdown");
}
- protected void deploy(String location) throws Exception
+ protected void deploy(URL archiveURL) throws Exception
{
- URL archiveURL = getTestHelper().getTestArchiveURL(location);
DeployerServiceClient deployer = new DeployerServiceClient(DeployerService.MBEAN_DEPLOYER_SERVICE);
deployer.deploy(archiveURL);
}
- protected void undeploy(String location) throws Exception
+ protected void undeploy(URL archiveURL) throws Exception
{
- URL archiveURL = getTestHelper().getTestArchiveURL(location);
DeployerServiceClient deployer = new DeployerServiceClient(DeployerService.MBEAN_DEPLOYER_SERVICE);
deployer.undeploy(archiveURL);
}
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java 2009-11-30 16:04:13 UTC (rev 97171)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java 2009-11-30 16:06:26 UTC (rev 97172)
@@ -23,6 +23,7 @@
// $Id$
+import java.net.URL;
import java.util.Dictionary;
import org.jboss.osgi.spi.management.ManagedBundleMBean;
@@ -40,14 +41,12 @@
* @author Thomas.Diesler(a)jboss.org
* @since 25-Sep-2008
*/
-public class RemoteBundle extends OSGiBundle
+public class RemoteBundle extends OSGiBundleImpl
{
// Provide logging
private final Logger log = LoggerFactory.getLogger(RemoteBundle.class);
- private OSGiRuntimeImpl runtime;
private ManagedBundleMBean bundle;
- private boolean uninstalled;
private String location;
private long bundleId;
@@ -56,7 +55,7 @@
public RemoteBundle(OSGiRuntimeImpl runtime, ManagedBundleMBean bundle, String location)
{
- this.runtime = runtime;
+ super(runtime);
this.bundle = bundle;
this.location = location;
@@ -70,7 +69,7 @@
@Override
public int getState()
{
- return (uninstalled == true ? Bundle.UNINSTALLED : bundle.getState());
+ return (isUninstalled() ? Bundle.UNINSTALLED : bundle.getState());
}
@Override
@@ -92,6 +91,12 @@
}
@Override
+ public String getLocation()
+ {
+ return location;
+ }
+
+ @Override
public Dictionary<String, String> getHeaders()
{
assertNotUninstalled();
@@ -125,9 +130,9 @@
assertNotUninstalled();
try
{
- runtime.undeploy(location);
- runtime.unregisterBundle(this);
- uninstalled = true;
+ getRuntime().undeploy(new URL(getLocation()));
+ getRuntime().unregisterBundle(this);
+ setUninstalled(true);
}
catch (RuntimeException rte)
{
@@ -135,13 +140,7 @@
}
catch (Exception ex)
{
- log.error("Cannot uninstall: " + location, ex);
+ log.error("Cannot uninstall: " + getLocation(), ex);
}
}
-
- private void assertNotUninstalled()
- {
- if (uninstalled == true)
- throw new IllegalStateException("Bundle already uninstalled: " + location);
- }
}
14 years, 5 months
JBoss-OSGI SVN: r97171 - in projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi: management and 1 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-30 11:04:13 -0500 (Mon, 30 Nov 2009)
New Revision: 97171
Modified:
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/OSGiConstants.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/MicrocontainerService.java
Log:
Remove dependency on TCCL in MBeanProxy.
Remove redundant OSGi constants.
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/OSGiConstants.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/OSGiConstants.java 2009-11-30 16:01:02 UTC (rev 97170)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/OSGiConstants.java 2009-11-30 16:04:13 UTC (rev 97171)
@@ -43,20 +43,6 @@
String PROPERTY_DEFERRED_START = "org.jboss.osgi.deferred.start";
/**
- * If set to 'true' bundles are started automatically.
- *
- * The default is 'false'
- */
- String PROPERTY_AUTO_START = "org.jboss.osgi.auto.start";
-
- /**
- * Specifies the start level for a bundle.
- *
- * The default is '0'
- */
- String PROPERTY_START_LEVEL = "org.jboss.osgi.start.level";
-
- /**
* The JBossOSGi runtime system property that denotes the path to the runtime
*/
String OSGI_HOME = "osgi.home";
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java 2009-11-30 16:01:02 UTC (rev 97170)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java 2009-11-30 16:04:13 UTC (rev 97171)
@@ -42,7 +42,6 @@
import javax.management.RuntimeMBeanException;
import javax.management.RuntimeOperationsException;
-
/**
* A simple MBeanProxy
*
@@ -51,345 +50,350 @@
*/
public class MBeanProxy
{
- @SuppressWarnings( { "unchecked" })
- public static <T> T get(Class<T> interf, ObjectName name, MBeanServerConnection server) throws MBeanProxyException
- {
- return (T)get(new Class[] { interf }, name, server);
- }
+ @SuppressWarnings({ "unchecked" })
+ public static <T> T get(Class<T> interf, ObjectName name, MBeanServerConnection server) throws MBeanProxyException
+ {
+ return (T)get(new Class[] { interf }, name, server);
+ }
- @SuppressWarnings( { "rawtypes" })
- public static Object get(Class[] interfaces, ObjectName name, MBeanServerConnection server) throws MBeanProxyException
- {
- return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, new JMXInvocationHandler(server, name));
- }
+ @SuppressWarnings({ "rawtypes" })
+ public static Object get(Class[] interfaces, ObjectName name, MBeanServerConnection server) throws MBeanProxyException
+ {
+ if (interfaces == null || interfaces.length == 0)
+ throw new IllegalArgumentException("Null interfaces");
- /**
- * Invocation handler for MBean proxies.
- *
- * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>
- * @author Thomas.Diesler(a)jboss.com
- * @since 24-Feb-2009
- */
- static class JMXInvocationHandler implements InvocationHandler, Serializable
- {
- private static final long serialVersionUID = 3714728148040623702L;
+ ClassLoader classLoader = interfaces[0].getClassLoader();
+ return Proxy.newProxyInstance(classLoader, interfaces, new JMXInvocationHandler(server, name));
+ }
- // Attributes -------------------------------------------------
+ /**
+ * Invocation handler for MBean proxies.
+ *
+ * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 24-Feb-2009
+ */
+ static class JMXInvocationHandler implements InvocationHandler, Serializable
+ {
+ private static final long serialVersionUID = 3714728148040623702L;
- /*
- * Reference to the MBean server this proxy connects to.
- */
- protected MBeanServerConnection server = null;
+ // Attributes -------------------------------------------------
- /*
- * The object name of the MBean this proxy represents.
- */
- protected ObjectName objectName = null;
+ /*
+ * Reference to the MBean server this proxy connects to.
+ */
+ protected MBeanServerConnection server = null;
- /*
- * MBean attribute meta data.
- */
- private HashMap<String, MBeanAttributeInfo> attributeMap = new HashMap<String, MBeanAttributeInfo>();
+ /*
+ * The object name of the MBean this proxy represents.
+ */
+ protected ObjectName objectName = null;
- /*
- * Indicates whether Object.toString() should be delegated to the resource or handled by the proxy.
- */
- private boolean delegateToStringToResource = false;
+ /*
+ * MBean attribute meta data.
+ */
+ private HashMap<String, MBeanAttributeInfo> attributeMap = new HashMap<String, MBeanAttributeInfo>();
- /*
- * Indicates whether Object.equals() should be delegated to the resource or handled by the proxy.
- */
- private boolean delegateEqualsToResource = false;
+ /*
+ * Indicates whether Object.toString() should be delegated to the resource or handled by the proxy.
+ */
+ private boolean delegateToStringToResource = false;
- /*
- * Indicates whether Object.hashCode() should be delegated to the resource or handled by the proxy.
- */
- private boolean delegateHashCodeToResource = false;
+ /*
+ * Indicates whether Object.equals() should be delegated to the resource or handled by the proxy.
+ */
+ private boolean delegateEqualsToResource = false;
- // Constructors -----------------------------------------------
+ /*
+ * Indicates whether Object.hashCode() should be delegated to the resource or handled by the proxy.
+ */
+ private boolean delegateHashCodeToResource = false;
- /*
- * Constructs a new JMX MBean Proxy invocation handler.
- * @param server reference to the MBean server this proxy connects to
- * @param name object name of the MBean this proxy represents
- * @throws MBeanProxyCreationException wraps underlying JMX exceptions in case the proxy creation fails
- */
- public JMXInvocationHandler(MBeanServerConnection server, ObjectName name) throws MBeanProxyException
- {
- try
+ // Constructors -----------------------------------------------
+
+ /*
+ * Constructs a new JMX MBean Proxy invocation handler.
+ * @param server reference to the MBean server this proxy connects to
+ * @param name object name of the MBean this proxy represents
+ * @throws MBeanProxyCreationException wraps underlying JMX exceptions in case the proxy creation fails
+ */
+ public JMXInvocationHandler(MBeanServerConnection server, ObjectName name) throws MBeanProxyException
{
- if (server == null)
- throw new MBeanProxyException("null agent reference");
+ try
+ {
+ if (server == null)
+ throw new MBeanProxyException("null agent reference");
- if (name == null)
- throw new MBeanProxyException("null object name");
+ if (name == null)
+ throw new MBeanProxyException("null object name");
- this.server = server;
- this.objectName = name;
+ this.server = server;
+ this.objectName = name;
- MBeanInfo info = server.getMBeanInfo(objectName);
- MBeanAttributeInfo[] attributes = info.getAttributes();
- MBeanOperationInfo[] operations = info.getOperations();
+ MBeanInfo info = server.getMBeanInfo(objectName);
+ MBeanAttributeInfo[] attributes = info.getAttributes();
+ MBeanOperationInfo[] operations = info.getOperations();
- // collect the MBean attribute metadata for standard mbean proxies
- for (int i = 0; i < attributes.length; ++i)
- attributeMap.put(attributes[i].getName(), attributes[i]);
+ // collect the MBean attribute metadata for standard mbean proxies
+ for (int i = 0; i < attributes.length; ++i)
+ attributeMap.put(attributes[i].getName(), attributes[i]);
- // Check whether the target resource exposes the common object methods.
- // Dynamic Proxy will delegate these methods automatically to the
- // invoke() implementation.
- for (int i = 0; i < operations.length; ++i)
- {
- if (operations[i].getName().equals("toString") && operations[i].getReturnType().equals("java.lang.String") && operations[i].getSignature().length == 0)
- {
- delegateToStringToResource = true;
- }
+ // Check whether the target resource exposes the common object methods.
+ // Dynamic Proxy will delegate these methods automatically to the
+ // invoke() implementation.
+ for (int i = 0; i < operations.length; ++i)
+ {
+ if (operations[i].getName().equals("toString") && operations[i].getReturnType().equals("java.lang.String")
+ && operations[i].getSignature().length == 0)
+ {
+ delegateToStringToResource = true;
+ }
- else if (operations[i].getName().equals("equals") && operations[i].getReturnType().equals(Boolean.TYPE.getName())
- && operations[i].getSignature().length == 1 && operations[i].getSignature()[0].getType().equals("java.lang.Object"))
- {
- delegateEqualsToResource = true;
- }
+ else if (operations[i].getName().equals("equals") && operations[i].getReturnType().equals(Boolean.TYPE.getName())
+ && operations[i].getSignature().length == 1 && operations[i].getSignature()[0].getType().equals("java.lang.Object"))
+ {
+ delegateEqualsToResource = true;
+ }
- else if (operations[i].getName().equals("hashCode") && operations[i].getReturnType().equals(Integer.TYPE.getName())
- && operations[i].getSignature().length == 0)
- {
- delegateHashCodeToResource = true;
- }
- }
+ else if (operations[i].getName().equals("hashCode") && operations[i].getReturnType().equals(Integer.TYPE.getName())
+ && operations[i].getSignature().length == 0)
+ {
+ delegateHashCodeToResource = true;
+ }
+ }
+ }
+ catch (InstanceNotFoundException e)
+ {
+ throw new MBeanProxyException("Object name " + name + " not found: " + e.toString());
+ }
+ catch (Exception ex)
+ {
+ throw new MBeanProxyException(ex.toString());
+ }
}
- catch (InstanceNotFoundException e)
- {
- throw new MBeanProxyException("Object name " + name + " not found: " + e.toString());
- }
- catch (Exception ex)
- {
- throw new MBeanProxyException(ex.toString());
- }
- }
- // InvocationHandler implementation ---------------------------
+ // InvocationHandler implementation ---------------------------
- @SuppressWarnings("rawtypes")
- public Object invoke(Object proxy, Method method, Object[] args) throws Exception
- {
- Class<?> declaringClass = method.getDeclaringClass();
+ @SuppressWarnings("rawtypes")
+ public Object invoke(Object proxy, Method method, Object[] args) throws Exception
+ {
+ Class<?> declaringClass = method.getDeclaringClass();
- // Handle methods from Object class. If the target resource exposes
- // operation metadata with same signature then the invocations will be
- // delegated to the target. Otherwise this instance of invocation handler
- // will execute them.
- if (declaringClass == Object.class)
- return handleObjectMethods(method, args);
+ // Handle methods from Object class. If the target resource exposes
+ // operation metadata with same signature then the invocations will be
+ // delegated to the target. Otherwise this instance of invocation handler
+ // will execute them.
+ if (declaringClass == Object.class)
+ return handleObjectMethods(method, args);
- try
- {
- String methodName = method.getName();
+ try
+ {
+ String methodName = method.getName();
- // Assume a get/setAttribute convention on the typed proxy interface.
- // If the MBean metadata exposes a matching attribute then use the
- // MBeanServer attribute accessors to read/modify the value. If not,
- // fallback to MBeanServer.invoke() assuming this is an operation
- // invocation despite the accessor naming convention.
+ // Assume a get/setAttribute convention on the typed proxy interface.
+ // If the MBean metadata exposes a matching attribute then use the
+ // MBeanServer attribute accessors to read/modify the value. If not,
+ // fallback to MBeanServer.invoke() assuming this is an operation
+ // invocation despite the accessor naming convention.
- // getter
- if (methodName.startsWith("get") && args == null)
- {
- String attrName = methodName.substring(3, methodName.length());
+ // getter
+ if (methodName.startsWith("get") && args == null)
+ {
+ String attrName = methodName.substring(3, methodName.length());
- // check that the metadata exists
- MBeanAttributeInfo info = (MBeanAttributeInfo)attributeMap.get(attrName);
- if (info != null)
- {
- String retType = method.getReturnType().getName();
+ // check that the metadata exists
+ MBeanAttributeInfo info = (MBeanAttributeInfo)attributeMap.get(attrName);
+ if (info != null)
+ {
+ String retType = method.getReturnType().getName();
- // check for correct return type on the getter
- if (retType.equals(info.getType()))
- {
- return server.getAttribute(objectName, attrName);
+ // check for correct return type on the getter
+ if (retType.equals(info.getType()))
+ {
+ return server.getAttribute(objectName, attrName);
+ }
+ }
}
- }
- }
- // boolean getter
- else if (methodName.startsWith("is") && args == null)
- {
- String attrName = methodName.substring(2, methodName.length());
+ // boolean getter
+ else if (methodName.startsWith("is") && args == null)
+ {
+ String attrName = methodName.substring(2, methodName.length());
- // check that the metadata exists
- MBeanAttributeInfo info = (MBeanAttributeInfo)attributeMap.get(attrName);
- if (info != null && info.isIs())
- {
- Class<?> retType = method.getReturnType();
+ // check that the metadata exists
+ MBeanAttributeInfo info = (MBeanAttributeInfo)attributeMap.get(attrName);
+ if (info != null && info.isIs())
+ {
+ Class<?> retType = method.getReturnType();
- // check for correct return type on the getter
- if (retType.equals(Boolean.class) || retType.equals(Boolean.TYPE))
- {
- return server.getAttribute(objectName, attrName);
+ // check for correct return type on the getter
+ if (retType.equals(Boolean.class) || retType.equals(Boolean.TYPE))
+ {
+ return server.getAttribute(objectName, attrName);
+ }
+ }
}
- }
- }
- // setter
- else if (methodName.startsWith("set") && args != null && args.length == 1)
- {
- String attrName = methodName.substring(3, methodName.length());
+ // setter
+ else if (methodName.startsWith("set") && args != null && args.length == 1)
+ {
+ String attrName = methodName.substring(3, methodName.length());
- // check that the metadata exists
- MBeanAttributeInfo info = (MBeanAttributeInfo)attributeMap.get(attrName);
- if (info != null && method.getReturnType().equals(Void.TYPE))
- {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ // check that the metadata exists
+ MBeanAttributeInfo info = (MBeanAttributeInfo)attributeMap.get(attrName);
+ if (info != null && method.getReturnType().equals(Void.TYPE))
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
- Class<?> signatureClass = null;
- String classType = info.getType();
+ Class<?> signatureClass = null;
+ String classType = info.getType();
- if (isPrimitive(classType))
- signatureClass = getPrimitiveClass(classType);
- else
- signatureClass = cl.loadClass(info.getType());
+ if (isPrimitive(classType))
+ signatureClass = getPrimitiveClass(classType);
+ else
+ signatureClass = cl.loadClass(info.getType());
- if (signatureClass.isAssignableFrom(args[0].getClass()))
- {
- server.setAttribute(objectName, new Attribute(attrName, args[0]));
- return null;
+ if (signatureClass.isAssignableFrom(args[0].getClass()))
+ {
+ server.setAttribute(objectName, new Attribute(attrName, args[0]));
+ return null;
+ }
+ }
}
- }
- }
- String[] signature = null;
+ String[] signature = null;
- if (args != null)
- {
- signature = new String[args.length];
- Class[] sign = method.getParameterTypes();
+ if (args != null)
+ {
+ signature = new String[args.length];
+ Class[] sign = method.getParameterTypes();
- for (int i = 0; i < sign.length; ++i)
- signature[i] = sign[i].getName();
- }
+ for (int i = 0; i < sign.length; ++i)
+ signature[i] = sign[i].getName();
+ }
- return server.invoke(objectName, methodName, args, signature);
+ return server.invoke(objectName, methodName, args, signature);
+ }
+ catch (Exception ex)
+ {
+ throw (Exception)decodeJMXException(ex);
+ }
}
- catch (Exception ex)
+
+ /*
+ * Attempt to decode the given Throwable.
+ * If it is a container JMX exception, then the target is returned.
+ * Otherwise the argument is returned.
+ */
+ private Throwable decodeJMXException(final Exception ex)
{
- throw (Exception)decodeJMXException(ex);
- }
- }
+ Throwable result = ex;
- /*
- * Attempt to decode the given Throwable.
- * If it is a container JMX exception, then the target is returned.
- * Otherwise the argument is returned.
- */
- private Throwable decodeJMXException(final Exception ex)
- {
- Throwable result = ex;
+ while (true)
+ {
+ if (result instanceof MBeanException)
+ result = ((MBeanException)result).getTargetException();
+ else if (result instanceof ReflectionException)
+ result = ((ReflectionException)result).getTargetException();
+ else if (result instanceof RuntimeOperationsException)
+ result = ((RuntimeOperationsException)result).getTargetException();
+ else if (result instanceof RuntimeMBeanException)
+ result = ((RuntimeMBeanException)result).getTargetException();
+ else if (result instanceof RuntimeErrorException)
+ result = ((RuntimeErrorException)result).getTargetError();
+ else
+ // can't decode
+ break;
+ }
- while (true)
- {
- if (result instanceof MBeanException)
- result = ((MBeanException)result).getTargetException();
- else if (result instanceof ReflectionException)
- result = ((ReflectionException)result).getTargetException();
- else if (result instanceof RuntimeOperationsException)
- result = ((RuntimeOperationsException)result).getTargetException();
- else if (result instanceof RuntimeMBeanException)
- result = ((RuntimeMBeanException)result).getTargetException();
- else if (result instanceof RuntimeErrorException)
- result = ((RuntimeErrorException)result).getTargetError();
- else
- // can't decode
- break;
+ return result;
}
- return result;
- }
+ private Object handleObjectMethods(Method method, Object[] args) throws Exception
+ {
+ if (method.getName().equals("toString"))
+ {
+ if (delegateToStringToResource)
+ return server.invoke(objectName, "toString", null, null);
+ else
+ return toString();
+ }
- private Object handleObjectMethods(Method method, Object[] args) throws Exception
- {
- if (method.getName().equals("toString"))
- {
- if (delegateToStringToResource)
- return server.invoke(objectName, "toString", null, null);
- else
- return toString();
+ else if (method.getName().equals("equals"))
+ {
+ if (delegateEqualsToResource)
+ {
+ return server.invoke(objectName, "equals", new Object[] { args[0] }, new String[] { "java.lang.Object" });
+ }
+ else if (Proxy.isProxyClass(args[0].getClass()))
+ {
+ Proxy prxy = (Proxy)args[0];
+ return new Boolean(this.equals(Proxy.getInvocationHandler(prxy)));
+ }
+ else
+ {
+ return new Boolean(this.equals(args[0]));
+ }
+ }
+
+ else if (method.getName().equals("hashCode"))
+ {
+ if (delegateHashCodeToResource)
+ return server.invoke(objectName, "hashCode", null, null);
+ else
+ return new Integer(this.hashCode());
+ }
+
+ else
+ throw new Error("Unexpected method invocation!");
}
- else if (method.getName().equals("equals"))
+ private boolean isPrimitive(String type)
{
- if (delegateEqualsToResource)
- {
- return server.invoke(objectName, "equals", new Object[] { args[0] }, new String[] { "java.lang.Object" });
- }
- else if (Proxy.isProxyClass(args[0].getClass()))
- {
- Proxy prxy = (Proxy)args[0];
- return new Boolean(this.equals(Proxy.getInvocationHandler(prxy)));
- }
- else
- {
- return new Boolean(this.equals(args[0]));
- }
+ if (type.equals(Integer.TYPE.getName()))
+ return true;
+ if (type.equals(Long.TYPE.getName()))
+ return true;
+ if (type.equals(Boolean.TYPE.getName()))
+ return true;
+ if (type.equals(Byte.TYPE.getName()))
+ return true;
+ if (type.equals(Character.TYPE.getName()))
+ return true;
+ if (type.equals(Short.TYPE.getName()))
+ return true;
+ if (type.equals(Float.TYPE.getName()))
+ return true;
+ if (type.equals(Double.TYPE.getName()))
+ return true;
+ if (type.equals(Void.TYPE.getName()))
+ return true;
+
+ return false;
}
- else if (method.getName().equals("hashCode"))
+ private Class<?> getPrimitiveClass(String type)
{
- if (delegateHashCodeToResource)
- return server.invoke(objectName, "hashCode", null, null);
- else
- return new Integer(this.hashCode());
+ if (type.equals(Integer.TYPE.getName()))
+ return Integer.TYPE;
+ if (type.equals(Long.TYPE.getName()))
+ return Long.TYPE;
+ if (type.equals(Boolean.TYPE.getName()))
+ return Boolean.TYPE;
+ if (type.equals(Byte.TYPE.getName()))
+ return Byte.TYPE;
+ if (type.equals(Character.TYPE.getName()))
+ return Character.TYPE;
+ if (type.equals(Short.TYPE.getName()))
+ return Short.TYPE;
+ if (type.equals(Float.TYPE.getName()))
+ return Float.TYPE;
+ if (type.equals(Double.TYPE.getName()))
+ return Double.TYPE;
+ if (type.equals(Void.TYPE.getName()))
+ return Void.TYPE;
+
+ return null;
}
-
- else
- throw new Error("Unexpected method invocation!");
- }
-
- private boolean isPrimitive(String type)
- {
- if (type.equals(Integer.TYPE.getName()))
- return true;
- if (type.equals(Long.TYPE.getName()))
- return true;
- if (type.equals(Boolean.TYPE.getName()))
- return true;
- if (type.equals(Byte.TYPE.getName()))
- return true;
- if (type.equals(Character.TYPE.getName()))
- return true;
- if (type.equals(Short.TYPE.getName()))
- return true;
- if (type.equals(Float.TYPE.getName()))
- return true;
- if (type.equals(Double.TYPE.getName()))
- return true;
- if (type.equals(Void.TYPE.getName()))
- return true;
-
- return false;
- }
-
- private Class<?> getPrimitiveClass(String type)
- {
- if (type.equals(Integer.TYPE.getName()))
- return Integer.TYPE;
- if (type.equals(Long.TYPE.getName()))
- return Long.TYPE;
- if (type.equals(Boolean.TYPE.getName()))
- return Boolean.TYPE;
- if (type.equals(Byte.TYPE.getName()))
- return Byte.TYPE;
- if (type.equals(Character.TYPE.getName()))
- return Character.TYPE;
- if (type.equals(Short.TYPE.getName()))
- return Short.TYPE;
- if (type.equals(Float.TYPE.getName()))
- return Float.TYPE;
- if (type.equals(Double.TYPE.getName()))
- return Double.TYPE;
- if (type.equals(Void.TYPE.getName()))
- return Void.TYPE;
-
- return null;
- }
- }
+ }
}
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/MicrocontainerService.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/MicrocontainerService.java 2009-11-30 16:01:02 UTC (rev 97170)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/MicrocontainerService.java 2009-11-30 16:04:13 UTC (rev 97171)
@@ -36,7 +36,7 @@
/**
* The name under which the system bundle context is registered: 'jboss.osgi:service=BundleContext'
*/
- String BEAN_SYSTEM_BUNDLE_CONTEXT = "jboss.osgi:service=BundleContext";
+ String BEAN_BUNDLE_CONTEXT = "jboss.osgi:service=BundleContext";
/**
* The name under which the MBeanServer is registered: 'jboss.osgi:service=MBeanServer'
14 years, 5 months