JBoss-OSGI SVN: r92858 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src: test/resources/bootstrap and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-27 06:58:32 -0400 (Thu, 27 Aug 2009)
New Revision: 92858
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
Log:
Trim configured system packages
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java 2009-08-27 10:20:06 UTC (rev 92857)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java 2009-08-27 10:58:32 UTC (rev 92858)
@@ -126,7 +126,7 @@
List<String> result = new ArrayList<String>();
for (String name : sysPackages.split(","))
{
- result.add(name);
+ result.add(name.trim());
}
return result;
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml 2009-08-27 10:20:06 UTC (rev 92857)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml 2009-08-27 10:58:32 UTC (rev 92858)
@@ -14,16 +14,13 @@
<map keyClass="java.lang.String" valueClass="java.lang.String">
<entry><key>org.osgi.framework.storage</key><value>${log4j.output.dir}/osgi-store</value></entry>
<entry><key>org.osgi.framework.storage.clean</key><value>onFirstInit</value></entry>
- <entry>
- <key>org.osgi.framework.system.packages.extra</key>
- <value>
+ <entry><key>org.osgi.framework.system.packages.extra</key><value>
org.jboss.logging;version=2.0,
org.jboss.osgi.spi.logging;version=1.0,
org.jboss.osgi.spi.management;version=1.0,
org.jboss.osgi.spi.service;version=1.0,
org.jboss.osgi.spi.util;version=1.0
- </value>
- </entry>
+ </value></entry>
</map>
</property>
<incallback method="addPlugin" />
16 years, 3 months
JBoss-OSGI SVN: r92857 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src: main/java/org/jboss/osgi/plugins/facade/classloading and 4 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-27 06:20:06 -0400 (Thu, 27 Aug 2009)
New Revision: 92857
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/metadata/AbstractOSGiMetaData.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
Log:
Added framework properties handling.
Removed ISE on metaData.getBundleSymbolicName()
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java 2009-08-27 09:12:02 UTC (rev 92856)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java 2009-08-27 10:20:06 UTC (rev 92857)
@@ -45,6 +45,7 @@
import org.jboss.osgi.plugins.filter.NoFilter;
import org.jboss.osgi.spi.NotImplementedException;
import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.jboss.osgi.spi.util.ConstantsHelper;
import org.jboss.util.collection.ConcurrentSet;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
@@ -52,6 +53,7 @@
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleException;
import org.osgi.framework.BundleListener;
+import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
@@ -134,7 +136,10 @@
public String getSymbolicName()
{
- return osgiMetaData.getBundleSymbolicName();
+ String symbolicName = osgiMetaData.getBundleSymbolicName();
+ if (symbolicName == null)
+ throw new IllegalStateException("Cannot obtain " + Constants.BUNDLE_SYMBOLICNAME);
+ return symbolicName;
}
public Version getVersion()
@@ -732,7 +737,7 @@
throw new IllegalArgumentException("Unknown bundle state: " + state);
}
this.state.set(state);
- log.debug(this + " change state=" + toHumanReadableStateString(state));
+ log.debug(this + " change state=" + ConstantsHelper.bundleState(state));
BundleEvent event = new BundleEvent(type, getBundleInternal());
fireBundleEvent(event);
}
@@ -915,32 +920,6 @@
}
/**
- * Get a human readable version of the state
- *
- * @param state the state
- * @return the human readable form
- */
- private static String toHumanReadableStateString(int state)
- {
- switch (state)
- {
- case Bundle.INSTALLED:
- return "INSTALLED";
- case Bundle.RESOLVED:
- return "RESOLVED";
- case Bundle.STARTING:
- return "STARTING";
- case Bundle.ACTIVE:
- return "ACTIVE";
- case Bundle.STOPPING:
- return "STOPPING";
- case Bundle.UNINSTALLED:
- return "UNINSTALLED";
- }
- return "???" + state;
- }
-
- /**
* ServiceListenerRegistration.
*/
private static class ServiceListenerRegistration
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-27 09:12:02 UTC (rev 92856)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-27 10:20:06 UTC (rev 92857)
@@ -75,38 +75,38 @@
public class OSGiBundleManager
{
/** The log */
- private static final Logger log = Logger.getLogger(OSGiBundleManager.class);
+ private static final Logger log = Logger.getLogger(OSGiBundleManager.class);
/** The bundle manager's bean name: OSGiBundleManager */
public static final String BEAN_BUNDLE_MANAGER = "OSGiBundleManager";
-
+
/** The framework version */
private static String OSGi_FRAMEWORK_VERSION = "r4v42"; // [TODO] externalise
-
+
/** The framework vendor */
private static String OSGi_FRAMEWORK_VENDOR = "jboss.org"; // [TODO] externalise
-
+
/** The framework language */
private static String OSGi_FRAMEWORK_LANGUAGE = Locale.getDefault().getISO3Language(); // REVIEW correct?
-
+
/** The os name */
private static String OSGi_FRAMEWORK_OS_NAME;
-
+
/** The os version */
private static String OSGi_FRAMEWORK_OS_VERSION;
-
+
/** The os version */
private static String OSGi_FRAMEWORK_PROCESSOR;
-
+
/** The bundles by id */
private Map<Long, AbstractBundleState> bundlesById = new ConcurrentHashMap<Long, AbstractBundleState>();
/** The registered services */
private Set<OSGiServiceState> registeredServices = new ConcurrentSet<OSGiServiceState>();
-
+
/** The main deployer */
private DeployerClient deployerClient;
-
+
/** The deployment structure */
private MainDeployerStructure deployerStructure;
@@ -115,30 +115,29 @@
/** The system bundle */
private OSGiSystemState systemBundle;
-
+
/** The registered manager plugins */
private Map<Class<?>, AbstractPlugin> plugins = new HashMap<Class<?>, AbstractPlugin>();
-
+
/** The frame work properties */
- @SuppressWarnings("unused") // [TODO] ????
private Map<String, Object> properties = new HashMap<String, Object>();
-
+
static
{
AccessController.doPrivileged(new PrivilegedAction<Object>()
{
public Object run()
{
- OSGi_FRAMEWORK_OS_NAME=System.getProperty("os.name");
- OSGi_FRAMEWORK_OS_VERSION=System.getProperty("os.version");
- OSGi_FRAMEWORK_PROCESSOR=System.getProperty("os.arch");
-
+ OSGi_FRAMEWORK_OS_NAME = System.getProperty("os.name");
+ OSGi_FRAMEWORK_OS_VERSION = System.getProperty("os.version");
+ OSGi_FRAMEWORK_PROCESSOR = System.getProperty("os.arch");
+
System.setProperty("org.osgi.vendor.framework", "org.jboss.osgi.plugins.framework");
return null;
}
});
}
-
+
/**
* Create a new OSGiBundleManager.
*
@@ -149,7 +148,7 @@
{
this(deployerClient, null);
}
-
+
/**
* Create a new OSGiBundleManager.
*
@@ -163,16 +162,16 @@
throw new IllegalArgumentException("Null deployerClient");
if (deployerClient instanceof MainDeployerStructure == false)
throw new IllegalArgumentException("Deployer client does not implement " + MainDeployerStructure.class.getName());
-
+
this.deployerClient = deployerClient;
this.deployerStructure = (MainDeployerStructure)deployerClient;
-
+
// TODO thread factory
if (executor == null)
executor = Executors.newFixedThreadPool(10);
-
+
this.executor = executor;
-
+
// Create the system bundle
createSystemBundle();
}
@@ -196,9 +195,51 @@
public void setProperties(Map<String, Object> properties)
{
this.properties = properties;
+
+ // Init default framework properties
+ if (getProperty(Constants.FRAMEWORK_VERSION) == null)
+ setProperty(Constants.FRAMEWORK_VERSION, OSGi_FRAMEWORK_VERSION);
+ if (getProperty(Constants.FRAMEWORK_VENDOR) == null)
+ setProperty(Constants.FRAMEWORK_VENDOR, OSGi_FRAMEWORK_VENDOR);
+ if (getProperty(Constants.FRAMEWORK_LANGUAGE) == null)
+ setProperty(Constants.FRAMEWORK_LANGUAGE, OSGi_FRAMEWORK_LANGUAGE);
+ if (getProperty(Constants.FRAMEWORK_OS_NAME) == null)
+ setProperty(Constants.FRAMEWORK_OS_NAME, OSGi_FRAMEWORK_OS_NAME);
+ if (getProperty(Constants.FRAMEWORK_OS_VERSION) == null)
+ setProperty(Constants.FRAMEWORK_OS_VERSION, OSGi_FRAMEWORK_OS_VERSION);
+ if (getProperty(Constants.FRAMEWORK_PROCESSOR) == null)
+ setProperty(Constants.FRAMEWORK_PROCESSOR, OSGi_FRAMEWORK_PROCESSOR);
}
/**
+ * Get a property
+ *
+ * @param key the property key
+ * @return the property
+ * @throws SecurityException if the caller doesn't have the relevant property permission
+ */
+ public String getProperty(String key)
+ {
+ Object value = properties.get(key);
+ if (value == null)
+ value = System.getProperty(key);
+
+ if (value instanceof String == false)
+ return null;
+
+ return (String)value;
+ }
+
+ /**
+ * Set a property.
+ * This is used at the frame work init state.
+ */
+ public void setProperty(String key, String value)
+ {
+ properties.put(key, value);
+ }
+
+ /**
* Get a plugin that is registered with the bundle manager.
*
* @param <T> the pluging type
@@ -227,7 +268,7 @@
{
return (T)plugins.get(clazz);
}
-
+
/**
* Add a plugin
*
@@ -245,7 +286,7 @@
}
}
}
-
+
/**
* Remove a plugin
*
@@ -263,7 +304,7 @@
}
}
}
-
+
/**
* Are we active
*
@@ -275,7 +316,7 @@
AbstractBundleState bundleState = getSystemBundle();
return bundleState.getState() >= Bundle.STARTING;
}
-
+
/**
* Install a bundle
*
@@ -287,7 +328,7 @@
{
if (url == null)
throw new BundleException("Null url");
-
+
try
{
VirtualFile root = VFS.getRoot(url);
@@ -312,7 +353,7 @@
throw new BundleException("Error installing bundle from location=" + url, e);
}
}
-
+
/**
* Install a bundle
*
@@ -324,7 +365,7 @@
{
if (file == null)
throw new BundleException("Null file");
-
+
try
{
VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(file);
@@ -348,7 +389,7 @@
throw new BundleException("Error installing bundle from location=" + file, e);
}
}
-
+
/**
* Uninstall a bundle
*
@@ -360,14 +401,14 @@
long id = bundle.getBundleId();
if (id == 0)
throw new IllegalArgumentException("Cannot uninstall system bundle");
-
+
OSGiBundleState state = (OSGiBundleState)getBundle(id);
if (state == null)
throw new BundleException(bundle + " not installed");
-
+
uninstall(state);
}
-
+
/**
* Uninstall a bundle
*
@@ -387,7 +428,7 @@
throw new BundleException("Unable to uninstall " + bundleState, e);
}
}
-
+
/**
* Add a deployment
*
@@ -423,7 +464,7 @@
addBundle(bundleState);
return bundleState;
}
-
+
/**
* Generate a name for the deployment unit
*
@@ -445,7 +486,7 @@
}
return result.toString();
}
-
+
/**
* Add a bundle
*
@@ -469,12 +510,12 @@
throw new IllegalStateException("Cannot install singleton " + bundleState + " another singleton is already installed: " + bundle);
}
}
-
+
bundleState.setBundleManager(this);
bundlesById.put(bundleState.getBundleId(), bundleState);
log.debug("Added " + bundleState.getCanonicalName() + " id=" + bundleState.getBundleId());
}
-
+
/**
* Remove a bundle
*
@@ -523,11 +564,11 @@
{
if (id == 0)
throw new IllegalArgumentException("Cannot get deployment from system bundle");
-
+
OSGiBundleState bundleState = (OSGiBundleState)getBundle(id);
if (bundleState == null)
return null;
-
+
return bundleState.getDeploymentUnit();
}
@@ -542,33 +583,6 @@
}
/**
- * Get a property
- *
- * @param key the property key
- * @return the property
- * @throws SecurityException if the caller doesn't have the relevant property permission
- */
- public String getProperty(String key)
- {
- if (key == null)
- return null;
- if (Constants.FRAMEWORK_VERSION.equals(key))
- return OSGi_FRAMEWORK_VERSION;
- if (Constants.FRAMEWORK_VENDOR.equals(key))
- return OSGi_FRAMEWORK_VENDOR;
- if (Constants.FRAMEWORK_LANGUAGE.equals(key))
- return OSGi_FRAMEWORK_LANGUAGE;
- if (Constants.FRAMEWORK_OS_NAME.equals(key))
- return OSGi_FRAMEWORK_OS_NAME;
- if (Constants.FRAMEWORK_OS_VERSION.equals(key))
- return OSGi_FRAMEWORK_OS_VERSION;
- if (Constants.FRAMEWORK_PROCESSOR.equals(key))
- return OSGi_FRAMEWORK_PROCESSOR;
-
- return System.getProperty(key);
- }
-
- /**
* Resolve a bundle
*
* @param bundleState the bundle state
@@ -586,7 +600,7 @@
catch (DeploymentException e)
{
if (errorOnFail)
- throw new IllegalStateException("Error resolving bundle: " + bundleState, e);
+ throw new IllegalStateException("Error resolving bundle: " + bundleState, e);
return false;
}
}
@@ -609,7 +623,7 @@
{
Throwable t = e.getCause();
if (t instanceof BundleException)
- throw (BundleException) t;
+ throw (BundleException)t;
throw new BundleException("Error starting " + bundleState, e);
}
}
@@ -624,13 +638,13 @@
{
try
{
- deployerClient.change(bundleState.getDeploymentUnit().getName(), DeploymentStages.CLASSLOADER);
+ deployerClient.change(bundleState.getDeploymentUnit().getName(), DeploymentStages.CLASSLOADER);
}
catch (DeploymentException e)
{
Throwable t = e.getCause();
if (t instanceof BundleException)
- throw (BundleException) t;
+ throw (BundleException)t;
throw new BundleException("Error stopping " + bundleState, e);
}
}
@@ -644,17 +658,17 @@
* @param checkAssignable whether to check isAssignable
* @return the services
*/
- Collection<OSGiServiceState> getServices(AbstractBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
+ Collection<OSGiServiceState> getServices(AbstractBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
{
if (filter == null)
filter = NoFilter.INSTANCE;
-
+
if (registeredServices.isEmpty())
return null;
// review: optimise this, e.g. index by class
// Use a sorted set to order services according to spec
- Set<OSGiServiceState> result = new TreeSet<OSGiServiceState>(ServiceComparator.INSTANCE);
+ Set<OSGiServiceState> result = new TreeSet<OSGiServiceState>(ServiceComparator.INSTANCE);
for (OSGiServiceState service : registeredServices)
{
// Check the state, filter and permission
@@ -679,15 +693,15 @@
* @param clazz any class
* @return the reference
*/
- ServiceReference getServiceReference(AbstractBundleState bundleState, String clazz)
+ ServiceReference getServiceReference(AbstractBundleState bundleState, String clazz)
{
// Ignore isAssignable for the system context
boolean checkAssignable = (bundleState.getBundleId() != 0);
-
+
Collection<OSGiServiceState> services = getServices(bundleState, clazz, null, checkAssignable);
if (services == null || services.isEmpty())
return null;
-
+
OSGiServiceState service = services.iterator().next();
return service.getReferenceInternal();
}
@@ -701,7 +715,7 @@
* @param checkAssignable whether to check isAssignable
* @return the services
*/
- ServiceReference[] getServiceReferences(AbstractBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
+ ServiceReference[] getServiceReferences(AbstractBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
{
Collection<OSGiServiceState> services = getServices(bundleState, clazz, filter, checkAssignable);
if (services == null || services.isEmpty())
@@ -763,7 +777,7 @@
registeredServices.remove(serviceState);
serviceState.internalUnregister();
}
-
+
/**
* Get a service
*
@@ -773,14 +787,14 @@
*/
Object getService(AbstractBundleState bundleState, ServiceReference reference)
{
- OSGiServiceReferenceWrapper serviceReference = (OSGiServiceReferenceWrapper) reference;
+ OSGiServiceReferenceWrapper serviceReference = (OSGiServiceReferenceWrapper)reference;
OSGiServiceState serviceState = serviceReference.getServiceState();
Object result = serviceState.getService();
if (result != null)
bundleState.addServiceInUse(serviceState);
return result;
}
-
+
/**
* Unget a service
*
@@ -792,11 +806,11 @@
{
if (reference == null)
throw new IllegalArgumentException("Null reference");
- OSGiServiceReferenceWrapper serviceReference = (OSGiServiceReferenceWrapper) reference;
+ OSGiServiceReferenceWrapper serviceReference = (OSGiServiceReferenceWrapper)reference;
OSGiServiceState serviceState = serviceReference.getServiceState();
return ungetService(bundleState, serviceState);
}
-
+
/**
* Unget a service
*
@@ -808,7 +822,7 @@
{
return bundleState.removeServiceInUse(service);
}
-
+
/**
* Get the executor.
*
@@ -818,14 +832,14 @@
{
return executor;
}
-
+
/**
* Init the Framework
*/
public void initFramework()
{
int state = systemBundle.getState();
-
+
// This method does nothing if called when this Framework is in the STARTING, ACTIVE or STOPPING state
if (state == Bundle.STARTING || state == Bundle.ACTIVE || state == Bundle.STOPPING)
return;
@@ -854,10 +868,10 @@
// If this Framework is not in the STARTING state, initialize this Framework
if (systemBundle.getState() != Bundle.STARTING)
initFramework();
-
+
// Create the system bundl context
systemBundle.createBundleContext();
-
+
// All installed bundles must be started
AutoInstallPlugin autoInstall = getOptionalPlugin(AutoInstallPlugin.class);
if (autoInstall != null)
@@ -868,11 +882,11 @@
// This Framework's state is set to ACTIVE
systemBundle.changeState(Bundle.ACTIVE);
-
+
// A framework event of type STARTED is fired
systemBundle.fireFrameworkEvent(FrameworkEvent.STARTED, null);
}
-
+
/**
* Stop the framework
*/
@@ -881,7 +895,7 @@
AbstractBundleState systemBundle = getSystemBundle();
if (systemBundle.getState() != Bundle.ACTIVE)
return;
-
+
systemBundle.changeState(Bundle.STOPPING);
for (AbstractBundleState bundle : getBundles())
{
@@ -900,7 +914,7 @@
}
systemBundle.changeState(Bundle.RESOLVED);
}
-
+
/**
* Stop the framework
*/
@@ -947,7 +961,7 @@
systemBundle.fireFrameworkEvent(FrameworkEvent.ERROR, t);
else if (bundleState != null)
systemBundle.fireFrameworkEvent(FrameworkEvent.ERROR, new BundleException("Error " + context + " bundle: " + bundleState.getCanonicalName(), t));
- else
+ else
systemBundle.fireFrameworkEvent(FrameworkEvent.ERROR, new BundleException("Error " + context, t));
}
@@ -963,17 +977,17 @@
systemBundle.fireFrameworkEvent(FrameworkEvent.WARNING, t);
else if (bundleState != null)
systemBundle.fireFrameworkEvent(FrameworkEvent.WARNING, new BundleException("Error " + context + " bundle: " + bundleState.getCanonicalName(), t));
- else
+ else
systemBundle.fireFrameworkEvent(FrameworkEvent.WARNING, new BundleException("Error " + context, t));
}
-
+
/**
* ServiceComparator, reverses the order of compareTo
*/
static class ServiceComparator implements Comparator<OSGiServiceState>
{
public static ServiceComparator INSTANCE = new ServiceComparator();
-
+
public int compare(OSGiServiceState o1, OSGiServiceState o2)
{
return -o1.compareTo(o2);
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java 2009-08-27 09:12:02 UTC (rev 92856)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java 2009-08-27 10:20:06 UTC (rev 92857)
@@ -21,7 +21,6 @@
*/
package org.jboss.osgi.plugins.facade.classloading;
-import java.util.ArrayList;
import java.util.List;
import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java 2009-08-27 09:12:02 UTC (rev 92856)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java 2009-08-27 10:20:06 UTC (rev 92857)
@@ -30,6 +30,7 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.plugins.facade.api.SystemPackagesPlugin;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+import org.osgi.framework.Constants;
/**
* A plugin that installs/starts bundles on framework startup.
@@ -42,11 +43,6 @@
// Provide logging
final Logger log = Logger.getLogger(SystemPackagesPluginImpl.class);
- /** The configured system packages */
- private List<String> systemPackages = new ArrayList<String>();
- /** The configured extra system packages */
- private List<String> extraPackages = new ArrayList<String>();
-
/** The derived combination of all system packages */
private List<String> allPackages = new ArrayList<String>();
/** The derived combination of all system packages without version specifier */
@@ -57,28 +53,31 @@
super(bundleManager);
}
- public void setSystemPackages(List<String> systemPackages)
- {
- this.systemPackages = systemPackages;
- }
- public void setExtraPackages(List<String> extraPackages)
- {
- this.extraPackages = extraPackages;
- }
-
public void start()
{
- if (systemPackages.size() == 0)
+ String systemPackages = bundleManager.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
+ if (systemPackages != null)
{
- systemPackages.add("javax.management");
- systemPackages.add("org.osgi.framework");
- systemPackages.add("org.osgi.service.startlevel");
- systemPackages.add("org.osgi.service.packageadmin");
- systemPackages.add("org.osgi.util.tracker");
+ allPackages.addAll(packagesAsList(systemPackages));
}
+ else
+ {
+ // The default system packages
+ allPackages.add("javax.management");
+ allPackages.add("org.osgi.framework");
+ allPackages.add("org.osgi.service.startlevel");
+ allPackages.add("org.osgi.service.packageadmin");
+ allPackages.add("org.osgi.util.tracker");
+
+ String asString = packagesAsString(allPackages);
+ bundleManager.setProperty(Constants.FRAMEWORK_SYSTEMPACKAGES, asString);
+ }
- allPackages.addAll(systemPackages);
- allPackages.addAll(extraPackages);
+ String extraPackages = bundleManager.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
+ if (extraPackages != null)
+ {
+ allPackages.addAll(packagesAsList(extraPackages));
+ }
Collections.sort(allPackages);
@@ -109,4 +108,26 @@
return allPackageNames.contains(name);
}
+
+ private String packagesAsString(List<String> sysPackages)
+ {
+ StringBuffer result = new StringBuffer();
+ for (int i = 0; i < sysPackages.size(); i++)
+ {
+ if (i > 0)
+ result.append(",");
+ result.append(sysPackages.get(i));
+ }
+ return result.toString();
+ }
+
+ private List<String> packagesAsList(String sysPackages)
+ {
+ List<String> result = new ArrayList<String>();
+ for (String name : sysPackages.split(","))
+ {
+ result.add(name);
+ }
+ return result;
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/metadata/AbstractOSGiMetaData.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/metadata/AbstractOSGiMetaData.java 2009-08-27 09:12:02 UTC (rev 92856)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/metadata/AbstractOSGiMetaData.java 2009-08-27 10:20:06 UTC (rev 92857)
@@ -181,9 +181,6 @@
if (symbolicName == null)
symbolicName = getMainAttribute(Constants.BUNDLE_SYMBOLICNAME);
- if (symbolicName == null)
- throw new IllegalStateException("Cannot obtain " + Constants.BUNDLE_SYMBOLICNAME);
-
return symbolicName;
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java 2009-08-27 09:12:02 UTC (rev 92856)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java 2009-08-27 10:20:06 UTC (rev 92857)
@@ -181,8 +181,8 @@
bundle.start();
BundleContext bundleContext = bundle.getBundleContext();
assertNotNull(bundleContext);
- assertEquals("r4v42", bundleContext.getProperty(Constants.FRAMEWORK_VERSION)); // TODO externalise
- assertEquals("jboss.org", bundleContext.getProperty(Constants.FRAMEWORK_VENDOR)); // TODO externalise
+ assertEquals("r4v42", bundleContext.getProperty(Constants.FRAMEWORK_VERSION));
+ assertEquals("jboss.org", bundleContext.getProperty(Constants.FRAMEWORK_VENDOR));
assertEquals(Locale.getDefault().getISO3Language(), bundleContext.getProperty(Constants.FRAMEWORK_LANGUAGE));
assertSystemProperty(bundleContext, "os.name", Constants.FRAMEWORK_OS_NAME);
assertSystemProperty(bundleContext, "os.version", Constants.FRAMEWORK_OS_VERSION);
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml 2009-08-27 09:12:02 UTC (rev 92856)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml 2009-08-27 10:20:06 UTC (rev 92857)
@@ -14,6 +14,16 @@
<map keyClass="java.lang.String" valueClass="java.lang.String">
<entry><key>org.osgi.framework.storage</key><value>${log4j.output.dir}/osgi-store</value></entry>
<entry><key>org.osgi.framework.storage.clean</key><value>onFirstInit</value></entry>
+ <entry>
+ <key>org.osgi.framework.system.packages.extra</key>
+ <value>
+ org.jboss.logging;version=2.0,
+ org.jboss.osgi.spi.logging;version=1.0,
+ org.jboss.osgi.spi.management;version=1.0,
+ org.jboss.osgi.spi.service;version=1.0,
+ org.jboss.osgi.spi.util;version=1.0
+ </value>
+ </entry>
</map>
</property>
<incallback method="addPlugin" />
@@ -22,17 +32,7 @@
<bean name="OSGiSystemPackages" class="org.jboss.osgi.plugins.facade.plugins.SystemPackagesPluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
- <property name="extraPackages">
- <list elementClass="java.lang.String">
- <value>org.jboss.logging;version=2.0</value>
- <value>org.jboss.osgi.spi.logging;version=1.0</value>
- <value>org.jboss.osgi.spi.management;version=1.0</value>
- <value>org.jboss.osgi.spi.service;version=1.0</value>
- <value>org.jboss.osgi.spi.util;version=1.0</value>
- </list>
- </property>
</bean>
-
<bean name="OSGiStoragePlugin" class="org.jboss.osgi.plugins.facade.plugins.BundleStoragePluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
</bean>
16 years, 3 months
JBoss-OSGI SVN: r92849 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src: main/java/org/jboss/osgi/plugins/facade/classloading and 2 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-27 04:38:59 -0400 (Thu, 27 Aug 2009)
New Revision: 92849
Added:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemState.java
Removed:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
Log:
[JBOSGI-138] Proper system BundleContext implementation
Add better abstraction for the bundle states
Copied: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java (from rev 92848, projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -0,0 +1,967 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.facade.bundle;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.Permission;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.api.BundleStoragePlugin;
+import org.jboss.osgi.plugins.filter.NoFilter;
+import org.jboss.osgi.spi.NotImplementedException;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.jboss.util.collection.ConcurrentSet;
+import org.osgi.framework.AdminPermission;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.SynchronousBundleListener;
+import org.osgi.framework.Version;
+
+/**
+ * BundleState.
+ *
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler(a)jboss.com
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractBundleState implements Bundle, BundleContext
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(AbstractBundleState.class);
+
+ /** The last modified time stamp */
+ private long lastModified = System.currentTimeMillis();
+
+ /** The bundle manager */
+ private OSGiBundleManager bundleManager;
+
+ /** The osgi metadata */
+ private OSGiMetaData osgiMetaData;
+
+ /** The bundle context */
+ private BundleContext bundleContext;
+
+ /** The bundle */
+ private Bundle bundle;
+
+ /** The bundle state */
+ private AtomicInteger state = new AtomicInteger(Bundle.UNINSTALLED);
+
+ /** The registered services in use */
+ protected Set<OSGiServiceState> registeredServices = new ConcurrentSet<OSGiServiceState>();
+
+ /** The services in use */
+ protected Map<OSGiServiceState, Integer> servicesInUse = new ConcurrentHashMap<OSGiServiceState, Integer>();
+
+ /** The bundle listeners */
+ private List<BundleListener> bundleListeners = new CopyOnWriteArrayList<BundleListener>();
+
+ /** The framework listeners */
+ private List<FrameworkListener> frameworkListeners = new CopyOnWriteArrayList<FrameworkListener>();
+
+ /** The service listeners */
+ private Map<ServiceListener, ServiceListenerRegistration> serviceListeners = new ConcurrentHashMap<ServiceListener, ServiceListenerRegistration>();
+
+ /**
+ * Create a new BundleState for the system bundle.
+ *
+ * @param osgiMetaData the osgi metadata
+ * @throws IllegalArgumentException for a null parameter
+ */
+ AbstractBundleState(OSGiMetaData osgiMetaData)
+ {
+ if (osgiMetaData == null)
+ throw new IllegalArgumentException("Null osgi metadata");
+ this.osgiMetaData = osgiMetaData;
+ }
+
+ /**
+ * Get the bundleManager.
+ *
+ * @return the bundleManager.
+ */
+ public OSGiBundleManager getBundleManager()
+ {
+ return bundleManager;
+ }
+
+ public String getSymbolicName()
+ {
+ return osgiMetaData.getBundleSymbolicName();
+ }
+
+ public Version getVersion()
+ {
+ return osgiMetaData.getBundleVersion();
+ }
+
+ public int getState()
+ {
+ return state.get();
+ }
+
+ public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType)
+ {
+ throw new NotImplementedException();
+ }
+
+ public synchronized BundleContext getBundleContext()
+ {
+ checkAdminPermission(AdminPermission.CONTEXT);
+ return bundleContext;
+ }
+
+ public synchronized BundleContext createBundleContext()
+ {
+ if (bundleContext == null)
+ bundleContext = new OSGiBundleContextWrapper(this);
+ return bundleContext;
+ }
+
+ public synchronized void destroyBundleContext()
+ {
+ bundleContext = null;
+ }
+
+ public synchronized Bundle getBundle()
+ {
+ checkValidBundleContext();
+ return getBundleInternal();
+ }
+
+ public synchronized Bundle getBundleInternal()
+ {
+ if (bundle == null)
+ bundle = new OSGiBundleWrapper(this);
+ return bundle;
+ }
+
+ public Bundle getBundle(long id)
+ {
+ checkValidBundleContext();
+ OSGiBundleManager bundleManager = getBundleManager();
+ if (bundleManager == null)
+ return null;
+
+ AbstractBundleState bundleState = bundleManager.getBundle(id);
+ if (bundleState == null)
+ return null;
+ return bundleState.getBundleInternal();
+ }
+
+ public Bundle[] getBundles()
+ {
+ checkValidBundleContext();
+ OSGiBundleManager bundleManager = getBundleManager();
+ if (bundleManager == null)
+ return null;
+
+ Collection<AbstractBundleState> bundleStates = bundleManager.getBundles();
+ if (bundleStates.isEmpty())
+ return new Bundle[0];
+
+ List<Bundle> bundles = new ArrayList<Bundle>(bundleStates.size());
+ for (AbstractBundleState bundleState : bundleStates)
+ bundles.add(bundleState.getBundleInternal());
+ return bundles.toArray(new Bundle[bundles.size()]);
+ }
+
+ public long getLastModified()
+ {
+ return lastModified;
+ }
+
+ public void modified()
+ {
+ lastModified = System.currentTimeMillis();
+ }
+
+ /**
+ * Get the osgiMetaData.
+ *
+ * @return the osgiMetaData.
+ */
+ public OSGiMetaData getOSGiMetaData()
+ {
+ return osgiMetaData;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Dictionary getHeaders()
+ {
+ return getHeaders(null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Dictionary getHeaders(String locale)
+ {
+ checkAdminPermission(AdminPermission.METADATA);
+ return getOSGiMetaData().getHeaders(locale);
+ }
+
+ public String getProperty(String key)
+ {
+ checkValidBundleContext();
+ return bundleManager.getProperty(key);
+ }
+
+ public File getDataFile(String filename)
+ {
+ checkValidBundleContext();
+ BundleStoragePlugin storagePlugin = bundleManager.getOptionalPlugin(BundleStoragePlugin.class);
+ return storagePlugin != null ? storagePlugin.getDataFile(this, filename) : null;
+ }
+
+ public boolean hasPermission(Object permission)
+ {
+ if (permission == null || permission instanceof Permission == false)
+ return false;
+
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ return true;
+
+ // [TODO] hasPermission
+ return true;
+ }
+
+ public Filter createFilter(String filter) throws InvalidSyntaxException
+ {
+ checkValidBundleContext();
+ return FrameworkUtil.createFilter(filter);
+ }
+
+ public void addServiceListener(ServiceListener listener)
+ {
+ addServiceListenerInternal(listener, null);
+ }
+
+ public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException
+ {
+ Filter theFilter = null;
+ if (filter != null)
+ theFilter = createFilter(filter);
+ addServiceListenerInternal(listener, theFilter);
+ }
+
+ public void addServiceListenerInternal(ServiceListener listener, Filter filter)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+ if (filter == null)
+ filter = NoFilter.INSTANCE;
+ checkValidBundleContext();
+
+ serviceListeners.put(listener, new ServiceListenerRegistration(filter));
+ }
+
+ public void removeServiceListener(ServiceListener listener)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+
+ checkValidBundleContext();
+
+ serviceListeners.remove(listener);
+ }
+
+ /**
+ * Add a registered service
+ *
+ * @param serviceState the service
+ */
+ void addRegisteredService(OSGiServiceState serviceState)
+ {
+ registeredServices.add(serviceState);
+ }
+
+ /**
+ * Remove a registered service
+ *
+ * @param serviceState the service
+ */
+ void removeRegisteredService(OSGiServiceState serviceState)
+ {
+ registeredServices.remove(serviceState);
+ }
+
+ public ServiceReference[] getRegisteredServices()
+ {
+ checkInstalled();
+
+ if (registeredServices.isEmpty())
+ return null;
+
+ Set<ServiceReference> result = new HashSet<ServiceReference>(registeredServices.size());
+ for (OSGiServiceState service : registeredServices)
+ {
+ if (service.hasPermission())
+ result.add(service.getReferenceInternal());
+ }
+ if (result.isEmpty())
+ return null;
+ return result.toArray(new ServiceReference[result.size()]);
+ }
+
+ /**
+ * Increment the use count of a service for this bundle
+ *
+ * @param serviceState the service
+ */
+ void addServiceInUse(OSGiServiceState serviceState)
+ {
+ synchronized (servicesInUse)
+ {
+ Integer count = servicesInUse.get(serviceState);
+ if (count == null)
+ servicesInUse.put(serviceState, 1);
+ else
+ servicesInUse.put(serviceState, ++count);
+ }
+ serviceState.addUsingBundle(this);
+ }
+
+ /**
+ * Decrement the use count of a service for this bundle
+ *
+ * @param serviceState the service
+ * @return true when the service is still in use by the bundle
+ */
+ boolean removeServiceInUse(OSGiServiceState serviceState)
+ {
+ synchronized (servicesInUse)
+ {
+ Integer count = servicesInUse.get(serviceState);
+ if (count == null)
+ {
+ return false;
+ }
+ else if (count == 1)
+ {
+ servicesInUse.remove(serviceState);
+ serviceState.removeUsingBundle(this);
+ return false;
+ }
+ else
+ {
+ servicesInUse.put(serviceState, --count);
+ }
+ }
+ return true;
+ }
+
+ public ServiceReference[] getServicesInUse()
+ {
+ checkInstalled();
+
+ synchronized (servicesInUse)
+ {
+ Collection<OSGiServiceState> inUse = servicesInUse.keySet();
+ if (inUse.isEmpty())
+ return null;
+
+ Set<ServiceReference> result = new HashSet<ServiceReference>(inUse.size());
+ for (OSGiServiceState service : inUse)
+ {
+ if (service.hasPermission())
+ result.add(service.getReferenceInternal());
+ }
+ if (result.isEmpty())
+ return null;
+ return result.toArray(new ServiceReference[result.size()]);
+ }
+ }
+
+ public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException
+ {
+ checkValidBundleContext();
+ return getBundleManager().getServiceReferences(this, clazz, filter, false);
+ }
+
+ public Object getService(ServiceReference reference)
+ {
+ checkValidBundleContext();
+
+ if (reference == null)
+ throw new IllegalArgumentException("Null reference");
+
+ return getBundleManager().getService(this, reference);
+ }
+
+ public ServiceReference getServiceReference(String clazz)
+ {
+ checkValidBundleContext();
+ if (clazz == null)
+ throw new IllegalArgumentException("Null clazz");
+ return getBundleManager().getServiceReference(this, clazz);
+ }
+
+ public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
+ {
+ checkValidBundleContext();
+ return getBundleManager().getServiceReferences(this, clazz, filter, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
+ {
+ if (clazz == null)
+ throw new IllegalArgumentException("Null class");
+ return registerService(new String[] { clazz }, service, properties);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
+ {
+ checkValidBundleContext();
+
+ OSGiServiceState serviceState = getBundleManager().registerService(this, clazzes, service, properties);
+ return serviceState.getRegistration();
+ }
+
+ /**
+ * Unregister a service
+ *
+ * @param serviceState the service state
+ */
+ void unregisterService(OSGiServiceState serviceState)
+ {
+ getBundleManager().unregisterService(serviceState);
+ }
+
+ public boolean ungetService(ServiceReference reference)
+ {
+ checkValidBundleContext();
+
+ return getBundleManager().ungetService(this, reference);
+ }
+
+ boolean ungetService(OSGiServiceState state)
+ {
+ return getBundleManager().ungetService(this, state);
+ }
+
+ public void addBundleListener(BundleListener listener)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+
+ checkValidBundleContext();
+
+ if (listener instanceof SynchronousBundleListener)
+ checkAdminPermission(AdminPermission.LISTENER);
+
+ if (bundleListeners.contains(listener))
+ return;
+
+ bundleListeners.add(listener);
+ }
+
+ public void removeBundleListener(BundleListener listener)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+
+ checkValidBundleContext();
+
+ if (listener instanceof SynchronousBundleListener)
+ checkAdminPermission(AdminPermission.LISTENER);
+
+ bundleListeners.remove(listener);
+ }
+
+ public void start() throws BundleException
+ {
+ start(0);
+ }
+
+ public void stop() throws BundleException
+ {
+ stop(0);
+ }
+
+ public void update() throws BundleException
+ {
+ checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
+ // [TODO] update
+ throw new UnsupportedOperationException("update");
+ }
+
+ public void update(InputStream in) throws BundleException
+ {
+ checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
+ // [TODO] update
+ throw new UnsupportedOperationException("update");
+ }
+
+ public void uninstall() throws BundleException
+ {
+ checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
+
+ OSGiBundleManager bundleManager = getBundleManager();
+ if (bundleManager == null)
+ return;
+
+ bundleManager.uninstall(this);
+ }
+
+ void uninstallInternal()
+ {
+ changeState(Bundle.UNINSTALLED);
+
+ frameworkListeners.clear();
+ bundleListeners.clear();
+ serviceListeners.clear();
+ }
+
+ public void addFrameworkListener(FrameworkListener listener)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+
+ checkValidBundleContext();
+
+ if (frameworkListeners.contains(listener))
+ return;
+
+ frameworkListeners.add(listener);
+ }
+
+ public void removeFrameworkListener(FrameworkListener listener)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+
+ checkValidBundleContext();
+
+ frameworkListeners.remove(listener);
+ }
+
+ public Bundle installBundle(String location, InputStream input) throws BundleException
+ {
+ checkValidBundleContext();
+ checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
+ // [TODO] installBundle
+ throw new UnsupportedOperationException("installBundle");
+ }
+
+ public Bundle installBundle(String location) throws BundleException
+ {
+ checkValidBundleContext();
+ checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
+
+ OSGiBundleManager bundleManager = getBundleManager();
+ if (bundleManager == null)
+ throw new IllegalStateException("Bundle " + getCanonicalName() + " is not valid");
+
+ URL url = getLocationURL(location);
+ AbstractBundleState bundleState = bundleManager.install(url);
+ return bundleState.getBundleInternal();
+ }
+
+ private URL getLocationURL(String location) throws BundleException
+ {
+ // Try location as URL
+ URL url = null;
+ try
+ {
+ url = new URL(location);
+ }
+ catch (MalformedURLException e)
+ {
+ // ignore
+ }
+
+ // Try location as File
+ if (url == null)
+ {
+ try
+ {
+ File file = new File(location);
+ if (file.exists())
+ url = file.toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ // ignore
+ }
+ }
+
+ if (url == null)
+ throw new BundleException("Unable to handle location=" + location);
+
+ return url;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Bundle{" + getCanonicalName() + "}";
+ }
+
+ /**
+ * Get the canonical name of the bundle
+ *
+ * @return the canonical name
+ */
+ String getCanonicalName()
+ {
+ return getSymbolicName() + ":" + osgiMetaData.getBundleVersion();
+ }
+
+ /**
+ * Set the bundle manager
+ *
+ * @param bundleManager the bundle manager or null to uninstall the bundle
+ */
+ void setBundleManager(OSGiBundleManager bundleManager)
+ {
+ if (bundleManager != null && this.bundleManager != null)
+ throw new IllegalStateException("Bundle " + this + " is already installed");
+ this.bundleManager = bundleManager;
+ if (bundleManager == null)
+ changeState(Bundle.UNINSTALLED);
+ }
+
+ /**
+ * Get the source of a class for ServiceReference.isAssignable()
+ *
+ * @param className the class name
+ * @return the source or null if no source
+ */
+ Object getSource(String className)
+ {
+ // [TODO] some more efficient way than using the class?
+ try
+ {
+ return loadClass(className);
+ }
+ catch (ClassNotFoundException e)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Change the state of the bundle
+ *
+ * @param state the new state
+ */
+ public void changeState(int state)
+ {
+ int previous = getState();
+ int type = 0;
+ switch (state)
+ {
+ case Bundle.STARTING:
+ type = BundleEvent.STARTING;
+ break;
+ case Bundle.ACTIVE:
+ type = BundleEvent.STARTED;
+ break;
+ case Bundle.STOPPING:
+ type = BundleEvent.STOPPING;
+ break;
+ case Bundle.UNINSTALLED:
+ type = BundleEvent.UNINSTALLED;
+ break;
+ case Bundle.INSTALLED:
+ {
+ if (previous == Bundle.RESOLVED)
+ type = BundleEvent.UNRESOLVED;
+ else
+ type = BundleEvent.INSTALLED;
+ break;
+ }
+ case Bundle.RESOLVED:
+ {
+ if (previous == Bundle.STOPPING)
+ type = BundleEvent.STOPPED;
+ else
+ type = BundleEvent.RESOLVED;
+ break;
+ }
+ default:
+ throw new IllegalArgumentException("Unknown bundle state: " + state);
+ }
+ this.state.set(state);
+ log.debug(this + " change state=" + toHumanReadableStateString(state));
+ BundleEvent event = new BundleEvent(type, getBundleInternal());
+ fireBundleEvent(event);
+ }
+
+ /**
+ * Fire a bundle event
+ *
+ * @param event the event
+ */
+ void fireBundleEvent(BundleEvent event)
+ {
+ // Nobody is interested
+ if (bundleListeners.isEmpty())
+ return;
+
+ // Are we active?
+ if (getBundleManager().isActive() == false)
+ return;
+
+ // Synchronous listeners first
+ for (BundleListener listener : bundleListeners)
+ {
+ try
+ {
+ if (listener instanceof SynchronousBundleListener)
+ listener.bundleChanged(event);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + getCanonicalName(), t);
+ }
+ }
+ // Normal listeners after, if required
+ int type = event.getType();
+ if (type != BundleEvent.STARTING && type != BundleEvent.STOPPING && type != BundleEvent.LAZY_ACTIVATION)
+ {
+ for (BundleListener listener : bundleListeners)
+ {
+ try
+ {
+ if (listener instanceof SynchronousBundleListener == false)
+ listener.bundleChanged(event);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + this, t);
+ }
+ }
+ }
+ }
+
+ /**
+ * Fire a framework event
+ *
+ * @param type the type of event
+ * @param throwable any throwable
+ */
+ void fireFrameworkEvent(int type, Throwable throwable)
+ {
+ // Nobody is interested
+ if (frameworkListeners.isEmpty())
+ return;
+
+ // Are we active?
+ if (getBundleManager().isActive() == false)
+ return;
+
+ // Call the listeners
+ FrameworkEvent event = new FrameworkEvent(type, getBundleInternal(), throwable);
+ for (FrameworkListener listener : frameworkListeners)
+ {
+ try
+ {
+ listener.frameworkEvent(event);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing framework event: " + event.getType() + " for bundle " + getCanonicalName(), t);
+ }
+ }
+ }
+
+ /**
+ * Fire a service event
+ *
+ * @param type the type
+ * @param service the service
+ */
+ void fireServiceEvent(int type, OSGiServiceState service)
+ {
+ if (service == null)
+ throw new IllegalArgumentException("No serviceReference");
+
+ // Nobody is interested
+ if (serviceListeners.isEmpty())
+ return;
+
+ // Are we active?
+ if (getBundleManager().isActive() == false)
+ return;
+
+ ServiceEvent event = new ServiceEvent(type, service.getReferenceInternal());
+
+ // Call the listeners
+ for (Map.Entry<ServiceListener, ServiceListenerRegistration> entry : serviceListeners.entrySet())
+ {
+ ServiceListener listener = entry.getKey();
+ ServiceListenerRegistration registration = entry.getValue();
+ try
+ {
+ if (registration.filter.match(service))
+ {
+ AccessControlContext accessControlContext = registration.accessControlContext;
+ if (accessControlContext == null || service.hasPermission(accessControlContext))
+ listener.serviceChanged(event);
+ }
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing service event: " + type + " for service " + service, t);
+ }
+ }
+ }
+
+ /**
+ * Check the bundle is installed
+ *
+ * @throws IllegalStateException when the bundle is not installed
+ */
+ protected void checkInstalled()
+ {
+ if ((getState() & Bundle.UNINSTALLED) != 0)
+ throw new IllegalStateException("Bundle " + getCanonicalName() + " is not installed");
+ }
+
+ /**
+ * Check a bundle context is still valid
+ *
+ * @return the bundle context
+ * @throws IllegalArgumentException when the context is no longer valid
+ */
+ protected synchronized BundleContext checkValidBundleContext()
+ {
+ BundleContext result = this.bundleContext;
+ if (result == null)
+ throw new IllegalStateException("Bundle context is no longer valid");
+ return result;
+ }
+
+ /**
+ * Check the admin permission
+ *
+ * @param what what permission to check
+ * @throws SecurityException when the caller does not have the AdminPermission and a security manager is installed
+ */
+ protected void checkAdminPermission(String what)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new AdminPermission(this, what));
+ }
+
+ /**
+ * Checks if we have the admin permission
+ *
+ * @param what the permission to check
+ * @return true if the caller doesn't have the permission
+ */
+ protected boolean noAdminPermission(String what)
+ {
+ try
+ {
+ checkAdminPermission(what);
+ return false;
+ }
+ catch (SecurityException e)
+ {
+ return true;
+ }
+ }
+
+ /**
+ * Get a human readable version of the state
+ *
+ * @param state the state
+ * @return the human readable form
+ */
+ private static String toHumanReadableStateString(int state)
+ {
+ switch (state)
+ {
+ case Bundle.INSTALLED:
+ return "INSTALLED";
+ case Bundle.RESOLVED:
+ return "RESOLVED";
+ case Bundle.STARTING:
+ return "STARTING";
+ case Bundle.ACTIVE:
+ return "ACTIVE";
+ case Bundle.STOPPING:
+ return "STOPPING";
+ case Bundle.UNINSTALLED:
+ return "UNINSTALLED";
+ }
+ return "???" + state;
+ }
+
+ /**
+ * ServiceListenerRegistration.
+ */
+ private static class ServiceListenerRegistration
+ {
+ // Any filter
+ Filter filter;
+
+ // Any access control context
+ AccessControlContext accessControlContext;
+
+ /**
+ * Create a new ServiceListenerRegistration.
+ *
+ * @param filter the filter
+ */
+ public ServiceListenerRegistration(Filter filter)
+ {
+ this.filter = filter;
+
+ if (System.getSecurityManager() != null)
+ accessControlContext = AccessController.getContext();
+ }
+ }
+}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java 2009-08-27 00:39:26 UTC (rev 92848)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -45,7 +45,7 @@
public class OSGiBundleContextWrapper implements BundleContext
{
/** The bundle state */
- private OSGiBundleState bundleState;
+ private AbstractBundleState bundleState;
/**
* Create a new OSGiBundleContextWrapper.
@@ -53,7 +53,7 @@
* @param bundleState the bundle state
* @throws IllegalArgumentException for a null parameter
*/
- public OSGiBundleContextWrapper(OSGiBundleState bundleState)
+ public OSGiBundleContextWrapper(AbstractBundleState bundleState)
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-27 00:39:26 UTC (rev 92848)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -99,7 +99,7 @@
private static String OSGi_FRAMEWORK_PROCESSOR;
/** The bundles by id */
- private Map<Long, OSGiBundleState> bundlesById = new ConcurrentHashMap<Long, OSGiBundleState>();
+ private Map<Long, AbstractBundleState> bundlesById = new ConcurrentHashMap<Long, AbstractBundleState>();
/** The registered services */
private Set<OSGiServiceState> registeredServices = new ConcurrentSet<OSGiServiceState>();
@@ -114,7 +114,7 @@
private Executor executor;
/** The system bundle */
- private OSGiSystemBundle systemBundle;
+ private OSGiSystemState systemBundle;
/** The registered manager plugins */
private Map<Class<?>, AbstractPlugin> plugins = new HashMap<Class<?>, AbstractPlugin>();
@@ -184,7 +184,7 @@
attributes.put(new Name(Constants.BUNDLE_NAME), Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
attributes.put(new Name(Constants.BUNDLE_SYMBOLICNAME), Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
OSGiMetaData systemMetaData = new AbstractOSGiMetaData(manifest);
- this.systemBundle = new OSGiSystemBundle(systemMetaData);
+ this.systemBundle = new OSGiSystemState(systemMetaData);
addBundle(systemBundle);
}
@@ -272,7 +272,7 @@
public boolean isActive()
{
// We are active if the system bundle is at least in the starting/stopping state
- OSGiBundleState bundleState = getSystemBundle();
+ AbstractBundleState bundleState = getSystemBundle();
return bundleState.getState() >= Bundle.STARTING;
}
@@ -283,7 +283,7 @@
* @return the bundle state
* @throws BundleException for any error
*/
- public OSGiBundleState install(URL url) throws BundleException
+ public AbstractBundleState install(URL url) throws BundleException
{
if (url == null)
throw new BundleException("Null url");
@@ -296,7 +296,7 @@
try
{
DeploymentUnit unit = deployerStructure.getDeploymentUnit(deployment.getName());
- OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+ AbstractBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
if (bundleState == null)
throw new IllegalStateException("Unable to determine bundle state for " + deployment.getName());
return bundleState;
@@ -320,7 +320,7 @@
* @return the bundle state
* @throws BundleException for any error
*/
- public OSGiBundleState install(VirtualFile file) throws BundleException
+ public AbstractBundleState install(VirtualFile file) throws BundleException
{
if (file == null)
throw new BundleException("Null file");
@@ -332,7 +332,7 @@
try
{
DeploymentUnit unit = deployerStructure.getDeploymentUnit(deployment.getName());
- OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+ AbstractBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
if (bundleState == null)
throw new IllegalStateException("Unable to determine bundle state for " + deployment.getName());
return bundleState;
@@ -358,9 +358,13 @@
public void uninstall(Bundle bundle) throws BundleException
{
long id = bundle.getBundleId();
- OSGiBundleState state = getBundle(id);
+ if (id == 0)
+ throw new IllegalArgumentException("Cannot uninstall system bundle");
+
+ OSGiBundleState state = (OSGiBundleState)getBundle(id);
if (state == null)
throw new BundleException(bundle + " not installed");
+
uninstall(state);
}
@@ -448,7 +452,7 @@
* @param bundleState the bundle state
* @throws IllegalArgumentException for a null bundle state
*/
- public void addBundle(OSGiBundleState bundleState)
+ public void addBundle(AbstractBundleState bundleState)
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
@@ -458,7 +462,7 @@
if (metaData.isSingleton())
{
String symbolicName = metaData.getBundleSymbolicName();
- for (OSGiBundleState bundle : getBundles())
+ for (AbstractBundleState bundle : getBundles())
{
OSGiMetaData other = bundle.getOSGiMetaData();
if (other.isSingleton() && symbolicName.equals(other.getBundleSymbolicName()))
@@ -477,7 +481,7 @@
* @param bundleState the bundle state
* @throws IllegalArgumentException for a null bundle state
*/
- public void removeBundle(OSGiBundleState bundleState)
+ public void removeBundle(AbstractBundleState bundleState)
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
@@ -494,7 +498,7 @@
* @param id the id of the bundle
* @return the bundle or null if there is no bundle with that id
*/
- public OSGiBundleState getBundle(long id)
+ public AbstractBundleState getBundle(long id)
{
return bundlesById.get(id);
}
@@ -504,7 +508,7 @@
*
* @return the system bundle
*/
- public OSGiSystemBundle getSystemBundle()
+ public OSGiSystemState getSystemBundle()
{
return systemBundle;
}
@@ -517,9 +521,13 @@
*/
public DeploymentUnit getDeployment(long id)
{
- OSGiBundleState bundleState = getBundle(id);
+ if (id == 0)
+ throw new IllegalArgumentException("Cannot get deployment from system bundle");
+
+ OSGiBundleState bundleState = (OSGiBundleState)getBundle(id);
if (bundleState == null)
return null;
+
return bundleState.getDeploymentUnit();
}
@@ -528,7 +536,7 @@
*
* @return the bundles
*/
- public Collection<OSGiBundleState> getBundles()
+ public Collection<AbstractBundleState> getBundles()
{
return bundlesById.values();
}
@@ -636,7 +644,7 @@
* @param checkAssignable whether to check isAssignable
* @return the services
*/
- Collection<OSGiServiceState> getServices(OSGiBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
+ Collection<OSGiServiceState> getServices(AbstractBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
{
if (filter == null)
filter = NoFilter.INSTANCE;
@@ -671,7 +679,7 @@
* @param clazz any class
* @return the reference
*/
- ServiceReference getServiceReference(OSGiBundleState bundleState, String clazz)
+ ServiceReference getServiceReference(AbstractBundleState bundleState, String clazz)
{
// Ignore isAssignable for the system context
boolean checkAssignable = (bundleState.getBundleId() != 0);
@@ -693,7 +701,7 @@
* @param checkAssignable whether to check isAssignable
* @return the services
*/
- ServiceReference[] getServiceReferences(OSGiBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
+ ServiceReference[] getServiceReferences(AbstractBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
{
Collection<OSGiServiceState> services = getServices(bundleState, clazz, filter, checkAssignable);
if (services == null || services.isEmpty())
@@ -715,7 +723,7 @@
* @return the services
* @throws InvalidSyntaxException when the filter is invalid
*/
- ServiceReference[] getServiceReferences(OSGiBundleState bundleState, String clazz, String filter, boolean checkAssignable) throws InvalidSyntaxException
+ ServiceReference[] getServiceReferences(AbstractBundleState bundleState, String clazz, String filter, boolean checkAssignable) throws InvalidSyntaxException
{
Filter f = NoFilter.INSTANCE;
if (filter != null)
@@ -733,7 +741,7 @@
* @return the service state
*/
@SuppressWarnings("unchecked")
- OSGiServiceState registerService(OSGiBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
+ OSGiServiceState registerService(AbstractBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
{
OSGiServiceState result = new OSGiServiceState(bundleState, clazzes, service, properties);
result.internalRegister();
@@ -763,7 +771,7 @@
* @param reference the service reference
* @return the service
*/
- Object getService(OSGiBundleState bundleState, ServiceReference reference)
+ Object getService(AbstractBundleState bundleState, ServiceReference reference)
{
OSGiServiceReferenceWrapper serviceReference = (OSGiServiceReferenceWrapper) reference;
OSGiServiceState serviceState = serviceReference.getServiceState();
@@ -780,7 +788,7 @@
* @param reference the service reference
* @return true when the service is still in use by the bundle
*/
- boolean ungetService(OSGiBundleState bundleState, ServiceReference reference)
+ boolean ungetService(AbstractBundleState bundleState, ServiceReference reference)
{
if (reference == null)
throw new IllegalArgumentException("Null reference");
@@ -796,7 +804,7 @@
* @param service the service
* @return true when the service is still in use by the bundle
*/
- boolean ungetService(OSGiBundleState bundleState, OSGiServiceState service)
+ boolean ungetService(AbstractBundleState bundleState, OSGiServiceState service)
{
return bundleState.removeServiceInUse(service);
}
@@ -870,12 +878,12 @@
*/
public void stopFramework()
{
- OSGiBundleState systemBundle = getSystemBundle();
+ AbstractBundleState systemBundle = getSystemBundle();
if (systemBundle.getState() != Bundle.ACTIVE)
return;
systemBundle.changeState(Bundle.STOPPING);
- for (OSGiBundleState bundle : getBundles())
+ for (AbstractBundleState bundle : getBundles())
{
if (bundle != systemBundle)
{
@@ -898,11 +906,11 @@
*/
public void restartFramework()
{
- OSGiBundleState systemBundle = getSystemBundle();
+ AbstractBundleState systemBundle = getSystemBundle();
if (systemBundle.getState() != Bundle.ACTIVE)
return;
- for (OSGiBundleState bundle : getBundles())
+ for (AbstractBundleState bundle : getBundles())
{
if (bundle != systemBundle && bundle.getState() == Bundle.ACTIVE)
{
@@ -932,9 +940,9 @@
*
* @param t the throwable
*/
- void fireError(OSGiBundleState bundleState, String context, Throwable t)
+ void fireError(AbstractBundleState bundleState, String context, Throwable t)
{
- OSGiSystemBundle systemBundle = getSystemBundle();
+ OSGiSystemState systemBundle = getSystemBundle();
if (t instanceof BundleException)
systemBundle.fireFrameworkEvent(FrameworkEvent.ERROR, t);
else if (bundleState != null)
@@ -948,9 +956,9 @@
*
* @param t the throwable
*/
- void fireWarning(OSGiBundleState bundleState, String context, Throwable t)
+ void fireWarning(AbstractBundleState bundleState, String context, Throwable t)
{
- OSGiSystemBundle systemBundle = getSystemBundle();
+ OSGiSystemState systemBundle = getSystemBundle();
if (t instanceof BundleException)
systemBundle.fireFrameworkEvent(FrameworkEvent.WARNING, t);
else if (bundleState != null)
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java 2009-08-27 00:39:26 UTC (rev 92848)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -21,26 +21,10 @@
*/
package org.jboss.osgi.plugins.facade.bundle;
-import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
import java.net.URL;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.Permission;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Dictionary;
import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.jboss.beans.info.spi.BeanInfo;
@@ -50,84 +34,35 @@
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.logging.Logger;
-import org.jboss.osgi.plugins.facade.api.BundleStoragePlugin;
-import org.jboss.osgi.plugins.filter.NoFilter;
-import org.jboss.osgi.spi.NotImplementedException;
import org.jboss.osgi.spi.metadata.OSGiMetaData;
-import org.jboss.util.collection.ConcurrentSet;
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleException;
-import org.osgi.framework.BundleListener;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkEvent;
-import org.osgi.framework.FrameworkListener;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.SynchronousBundleListener;
-import org.osgi.framework.Version;
/**
* BundleState.
*
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class OSGiBundleState implements Bundle, BundleContext
+public class OSGiBundleState extends AbstractBundleState
{
/** The log */
private static final Logger log = Logger.getLogger(OSGiBundleState.class);
-
+
/** Used to generate a unique id */
private static final AtomicLong bundleIDGenerator = new AtomicLong();
/** The bundle id */
private long bundleId;
- /** The last modified time stamp */
- private long lastModified = System.currentTimeMillis();
-
- /** The bundle manager */
- private OSGiBundleManager bundleManager;
-
- /** The osgi metadata */
- private OSGiMetaData osgiMetaData;
-
/** The deployment unit */
private DeploymentUnit unit;
- /** The bundle context */
- private BundleContext bundleContext;
-
- /** The bundle */
- private Bundle bundle;
-
- /** The bundle state */
- private AtomicInteger state = new AtomicInteger(Bundle.UNINSTALLED);
-
- /** The registered services in use */
- private Set<OSGiServiceState> registeredServices = new ConcurrentSet<OSGiServiceState>();
-
- /** The services in use */
- private Map<OSGiServiceState, Integer> servicesInUse = new ConcurrentHashMap<OSGiServiceState, Integer>();
-
- /** The bundle listeners */
- private List<BundleListener> bundleListeners = new CopyOnWriteArrayList<BundleListener>();
-
- /** The framework listeners */
- private List<FrameworkListener> frameworkListeners = new CopyOnWriteArrayList<FrameworkListener>();
-
- /** The service listeners */
- private Map<ServiceListener, ServiceListenerRegistration> serviceListeners = new ConcurrentHashMap<ServiceListener, ServiceListenerRegistration>();
-
/**
* Create a new BundleState.
*
@@ -137,133 +72,30 @@
*/
public OSGiBundleState(OSGiMetaData osgiMetaData, DeploymentUnit unit)
{
- if (osgiMetaData == null)
- throw new IllegalArgumentException("Null osgi metadata");
+ super(osgiMetaData);
if (unit == null)
throw new IllegalArgumentException("Null deployment unit");
- this.osgiMetaData = osgiMetaData;
this.unit = unit;
this.bundleId = bundleIDGenerator.incrementAndGet();
unit.getMutableMetaData().addMetaData(unit, DeploymentUnit.class);
changeState(Bundle.INSTALLED);
}
- /**
- * Create a new BundleState for the system bundle.
- *
- * @param osgiMetaData the osgi metadata
- * @throws IllegalArgumentException for a null parameter
- */
- OSGiBundleState(OSGiMetaData osgiMetaData)
+ public long getBundleId()
{
- if (osgiMetaData == null)
- throw new IllegalArgumentException("Null osgi metadata");
- this.osgiMetaData = osgiMetaData;
- this.bundleId = 0;
- changeState(Bundle.INSTALLED);
+ return bundleId;
}
/**
- * Get the bundleManager.
+ * Get the unit.
*
- * @return the bundleManager.
+ * @return the unit.
*/
- public OSGiBundleManager getBundleManager()
+ DeploymentUnit getDeploymentUnit()
{
- return bundleManager;
+ return unit;
}
- public long getBundleId()
- {
- return bundleId;
- }
-
- public String getSymbolicName()
- {
- return osgiMetaData.getBundleSymbolicName();
- }
-
- public Version getVersion()
- {
- return osgiMetaData.getBundleVersion();
- }
-
- public int getState()
- {
- return state.get();
- }
-
- public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType)
- {
- throw new NotImplementedException();
- }
-
- public synchronized BundleContext getBundleContext()
- {
- checkAdminPermission(AdminPermission.CONTEXT);
- return bundleContext;
- }
-
- public synchronized BundleContext createBundleContext()
- {
- if (bundleContext == null)
- bundleContext = new OSGiBundleContextWrapper(this);
- return bundleContext;
- }
-
- public synchronized Bundle getBundle()
- {
- checkValidBundleContext();
- return getBundleInternal();
- }
-
- public synchronized Bundle getBundleInternal()
- {
- if (bundle == null)
- bundle = new OSGiBundleWrapper(this);
- return bundle;
- }
-
- public Bundle getBundle(long id)
- {
- checkValidBundleContext();
- OSGiBundleManager bundleManager = getBundleManager();
- if (bundleManager == null)
- return null;
-
- OSGiBundleState bundleState = bundleManager.getBundle(id);
- if (bundleState == null)
- return null;
- return bundleState.getBundleInternal();
- }
-
- public Bundle[] getBundles()
- {
- checkValidBundleContext();
- OSGiBundleManager bundleManager = getBundleManager();
- if (bundleManager == null)
- return null;
-
- Collection<OSGiBundleState> bundleStates = bundleManager.getBundles();
- if (bundleStates.isEmpty())
- return new Bundle[0];
-
- List<Bundle> bundles = new ArrayList<Bundle>(bundleStates.size());
- for (OSGiBundleState bundleState : bundleStates)
- bundles.add(bundleState.getBundleInternal());
- return bundles.toArray(new Bundle[bundles.size()]);
- }
-
- public long getLastModified()
- {
- return lastModified;
- }
-
- public void modified()
- {
- lastModified = System.currentTimeMillis();
- }
-
public String getLocation()
{
checkAdminPermission(AdminPermission.METADATA);
@@ -283,42 +115,6 @@
return null;
}
- /**
- * Get the osgiMetaData.
- *
- * @return the osgiMetaData.
- */
- public OSGiMetaData getOSGiMetaData()
- {
- return osgiMetaData;
- }
-
- @SuppressWarnings("unchecked")
- public Dictionary getHeaders()
- {
- return getHeaders(null);
- }
-
- @SuppressWarnings("unchecked")
- public Dictionary getHeaders(String locale)
- {
- checkAdminPermission(AdminPermission.METADATA);
- return getOSGiMetaData().getHeaders(locale);
- }
-
- public String getProperty(String key)
- {
- checkValidBundleContext();
- return bundleManager.getProperty(key);
- }
-
- public File getDataFile(String filename)
- {
- checkValidBundleContext();
- BundleStoragePlugin storagePlugin = bundleManager.getOptionalPlugin(BundleStoragePlugin.class);
- return storagePlugin != null ? storagePlugin.getDataFile(this, filename) : null;
- }
-
public URL getEntry(String path)
{
checkInstalled();
@@ -423,6 +219,20 @@
return classLoader.loadClass(name);
}
+ /**
+ * Try to resolve the bundle
+ *
+ * @param errorOnFail whether to throw an error when not installed
+ * @return true when resolved
+ */
+ boolean resolve(boolean errorOnFail)
+ {
+ if (getState() != INSTALLED)
+ return true;
+
+ return getBundleManager().resolve(this, errorOnFail);
+ }
+
public URL getResource(String name)
{
checkInstalled();
@@ -448,293 +258,28 @@
return getDeploymentUnit().getClassLoader().getResources(name);
}
- public boolean hasPermission(Object permission)
+ // [TODO] options
+ public void start(int options) throws BundleException
{
- if (permission == null || permission instanceof Permission == false)
- return false;
-
- SecurityManager sm = System.getSecurityManager();
- if (sm == null)
- return true;
-
- // [TODO] hasPermission
- return true;
- }
-
- public Filter createFilter(String filter) throws InvalidSyntaxException
- {
- checkValidBundleContext();
- return FrameworkUtil.createFilter(filter);
- }
-
- public void addServiceListener(ServiceListener listener)
- {
- addServiceListenerInternal(listener, null);
- }
-
- public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException
- {
- Filter theFilter = null;
- if (filter != null)
- theFilter = createFilter(filter);
- addServiceListenerInternal(listener, theFilter);
- }
-
- public void addServiceListenerInternal(ServiceListener listener, Filter filter)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
- if (filter == null)
- filter = NoFilter.INSTANCE;
- checkValidBundleContext();
-
- serviceListeners.put(listener, new ServiceListenerRegistration(filter));
- }
-
- public void removeServiceListener(ServiceListener listener)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
-
- checkValidBundleContext();
-
- serviceListeners.remove(listener);
- }
-
- /**
- * Add a registered service
- *
- * @param serviceState the service
- */
- void addRegisteredService(OSGiServiceState serviceState)
- {
- registeredServices.add(serviceState);
- }
-
- /**
- * Remove a registered service
- *
- * @param serviceState the service
- */
- void removeRegisteredService(OSGiServiceState serviceState)
- {
- registeredServices.remove(serviceState);
- }
-
- public ServiceReference[] getRegisteredServices()
- {
checkInstalled();
+ checkAdminPermission(AdminPermission.EXECUTE);
- if (registeredServices.isEmpty())
- return null;
-
- Set<ServiceReference> result = new HashSet<ServiceReference>(registeredServices.size());
- for (OSGiServiceState service : registeredServices)
- {
- if (service.hasPermission())
- result.add(service.getReferenceInternal());
- }
- if (result.isEmpty())
- return null;
- return result.toArray(new ServiceReference[result.size()]);
- }
-
- /**
- * Increment the use count of a service for this bundle
- *
- * @param serviceState the service
- */
- void addServiceInUse(OSGiServiceState serviceState)
- {
- synchronized (servicesInUse)
- {
- Integer count = servicesInUse.get(serviceState);
- if (count == null)
- servicesInUse.put(serviceState, 1);
- else
- servicesInUse.put(serviceState, ++count);
- }
- serviceState.addUsingBundle(this);
- }
-
- /**
- * Decrement the use count of a service for this bundle
- *
- * @param serviceState the service
- * @return true when the service is still in use by the bundle
- */
- boolean removeServiceInUse(OSGiServiceState serviceState)
- {
- synchronized (servicesInUse)
- {
- Integer count = servicesInUse.get(serviceState);
- if (count == null)
- {
- return false;
- }
- else if (count == 1)
- {
- servicesInUse.remove(serviceState);
- serviceState.removeUsingBundle(this);
- return false;
- }
- else
- {
- servicesInUse.put(serviceState, --count);
- }
- }
- return true;
- }
-
- public ServiceReference[] getServicesInUse()
- {
- checkInstalled();
-
- synchronized (servicesInUse)
- {
- Collection<OSGiServiceState> inUse = servicesInUse.keySet();
- if (inUse.isEmpty())
- return null;
-
- Set<ServiceReference> result = new HashSet<ServiceReference>(inUse.size());
- for (OSGiServiceState service : inUse)
- {
- if (service.hasPermission())
- result.add(service.getReferenceInternal());
- }
- if (result.isEmpty())
- return null;
- return result.toArray(new ServiceReference[result.size()]);
- }
- }
-
- public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException
- {
- checkValidBundleContext();
- return getBundleManager().getServiceReferences(this, clazz, filter, false);
- }
-
- public Object getService(ServiceReference reference)
- {
- checkValidBundleContext();
-
- if (reference == null)
- throw new IllegalArgumentException("Null reference");
-
- return getBundleManager().getService(this, reference);
- }
-
- public ServiceReference getServiceReference(String clazz)
- {
- checkValidBundleContext();
- if (clazz == null)
- throw new IllegalArgumentException("Null clazz");
- return getBundleManager().getServiceReference(this, clazz);
- }
-
- public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
- {
- checkValidBundleContext();
- return getBundleManager().getServiceReferences(this, clazz, filter, true);
- }
-
- @SuppressWarnings("unchecked")
- public ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
- {
- if (clazz == null)
- throw new IllegalArgumentException("Null class");
- return registerService(new String[] { clazz }, service, properties);
- }
-
- @SuppressWarnings("unchecked")
- public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
- {
- checkValidBundleContext();
-
- OSGiServiceState serviceState = getBundleManager().registerService(this, clazzes, service, properties);
- return serviceState.getRegistration();
- }
-
- /**
- * Unregister a service
- *
- * @param serviceState the service state
- */
- void unregisterService(OSGiServiceState serviceState)
- {
- getBundleManager().unregisterService(serviceState);
- }
-
- public boolean ungetService(ServiceReference reference)
- {
- checkValidBundleContext();
-
- return getBundleManager().ungetService(this, reference);
- }
-
- boolean ungetService(OSGiServiceState state)
- {
- return getBundleManager().ungetService(this, state);
- }
-
- public void addBundleListener(BundleListener listener)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
-
- checkValidBundleContext();
-
- if (listener instanceof SynchronousBundleListener)
- checkAdminPermission(AdminPermission.LISTENER);
-
- if (bundleListeners.contains(listener))
+ if (getState() == ACTIVE)
return;
- bundleListeners.add(listener);
+ getBundleManager().start(this);
}
- public void removeBundleListener(BundleListener listener)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
-
- checkValidBundleContext();
-
- if (listener instanceof SynchronousBundleListener)
- checkAdminPermission(AdminPermission.LISTENER);
-
- bundleListeners.remove(listener);
- }
-
- /**
- * Try to resolve the bundle
- *
- * @param errorOnFail whether to throw an error when not installed
- * @return true when resolved
- */
- boolean resolve(boolean errorOnFail)
- {
- if (getState() != INSTALLED)
- return true;
-
- return getBundleManager().resolve(this, errorOnFail);
- }
-
- public void start() throws BundleException
- {
- start(0);
- }
-
// [TODO] options
- public void start(int options) throws BundleException
+ public void stop(int options) throws BundleException
{
checkInstalled();
checkAdminPermission(AdminPermission.EXECUTE);
- if (getState() == ACTIVE)
+ if (getState() != ACTIVE)
return;
- getBundleManager().start(this);
+ getBundleManager().stop(this);
}
/**
@@ -747,7 +292,7 @@
public void startInternal() throws Throwable
{
changeState(STARTING);
- bundleContext = createBundleContext();
+ createBundleContext();
try
{
OSGiMetaData metaData = getOSGiMetaData();
@@ -772,12 +317,12 @@
BundleActivator bundleActivator = (BundleActivator)result;
getDeploymentUnit().addAttachment(BundleActivator.class, bundleActivator);
- bundleActivator.start(bundleContext);
+ bundleActivator.start(getBundleContext());
}
}
if (getState() != STARTING)
- throw new BundleException("Bundle has been uninstalled: " + bundle);
+ throw new BundleException("Bundle has been uninstalled: " + this);
changeState(ACTIVE);
}
@@ -785,29 +330,12 @@
{
changeState(STOPPING);
// TODO stop the bundle
- this.bundleContext = null;
+ destroyBundleContext();
changeState(RESOLVED);
throw t;
}
}
- public void stop() throws BundleException
- {
- stop(0);
- }
-
- // [TODO] options
- public void stop(int options) throws BundleException
- {
- checkInstalled();
- checkAdminPermission(AdminPermission.EXECUTE);
-
- if (getState() != ACTIVE)
- return;
-
- getBundleManager().stop(this);
- }
-
/**
* Stop Internal
*
@@ -823,7 +351,7 @@
try
{
BundleActivator bundleActivator = getDeploymentUnit().getAttachment(BundleActivator.class);
- BundleContext bundleContext = this.bundleContext;
+ BundleContext bundleContext = getBundleContext();
if (bundleActivator != null && bundleContext != null)
{
try
@@ -872,459 +400,11 @@
{
if (getState() == STOPPING)
changeState(RESOLVED);
- bundleContext = null;
+ destroyBundleContext();
getDeploymentUnit().removeAttachment(BundleActivator.class);
}
if (rethrow != null)
throw rethrow;
}
-
- public void update() throws BundleException
- {
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
- // [TODO] update
- throw new UnsupportedOperationException("update");
- }
-
- public void update(InputStream in) throws BundleException
- {
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
- // [TODO] update
- throw new UnsupportedOperationException("update");
- }
-
- public void uninstall() throws BundleException
- {
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
-
- OSGiBundleManager bundleManager = getBundleManager();
- if (bundleManager == null)
- return;
-
- bundleManager.uninstall(this);
- }
-
- void uninstallInternal()
- {
- changeState(Bundle.UNINSTALLED);
-
- frameworkListeners.clear();
- bundleListeners.clear();
- serviceListeners.clear();
- }
-
- public void addFrameworkListener(FrameworkListener listener)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
-
- checkValidBundleContext();
-
- if (frameworkListeners.contains(listener))
- return;
-
- frameworkListeners.add(listener);
- }
-
- public void removeFrameworkListener(FrameworkListener listener)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
-
- checkValidBundleContext();
-
- frameworkListeners.remove(listener);
- }
-
- public Bundle installBundle(String location, InputStream input) throws BundleException
- {
- checkValidBundleContext();
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
- // [TODO] installBundle
- throw new UnsupportedOperationException("installBundle");
- }
-
- public Bundle installBundle(String location) throws BundleException
- {
- checkValidBundleContext();
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
-
- OSGiBundleManager bundleManager = getBundleManager();
- if (bundleManager == null)
- throw new IllegalStateException("Bundle " + getCanonicalName() + " is not valid");
-
- URL url = getLocationURL(location);
- OSGiBundleState bundleState = bundleManager.install(url);
- return bundleState.getBundleInternal();
- }
-
- private URL getLocationURL(String location) throws BundleException
- {
- // Try location as URL
- URL url = null;
- try
- {
- url = new URL(location);
- }
- catch (MalformedURLException e)
- {
- // ignore
- }
-
- // Try location as File
- if (url == null)
- {
- try
- {
- File file = new File(location);
- if (file.exists())
- url = file.toURL();
- }
- catch (MalformedURLException e)
- {
- // ignore
- }
- }
-
- if (url == null)
- throw new BundleException("Unable to handle location=" + location);
-
- return url;
- }
-
- @Override
- public String toString()
- {
- return "Bundle{" + getCanonicalName() + "}";
- }
-
- /**
- * Get the canonical name of the bundle
- *
- * @return the canonical name
- */
- String getCanonicalName()
- {
- return getSymbolicName() + ":" + osgiMetaData.getBundleVersion();
- }
-
- /**
- * Set the bundle manager
- *
- * @param bundleManager the bundle manager or null to uninstall the bundle
- */
- void setBundleManager(OSGiBundleManager bundleManager)
- {
- if (bundleManager != null && this.bundleManager != null)
- throw new IllegalStateException("Bundle " + this + " is already installed");
- this.bundleManager = bundleManager;
- if (bundleManager == null)
- changeState(Bundle.UNINSTALLED);
- }
-
- /**
- * Get the unit.
- *
- * @return the unit.
- */
- DeploymentUnit getDeploymentUnit()
- {
- return unit;
- }
-
- /**
- * Get the source of a class for ServiceReference.isAssignable()
- *
- * @param className the class name
- * @return the source or null if no source
- */
- Object getSource(String className)
- {
- // [TODO] some more efficient way than using the class?
- try
- {
- return loadClass(className);
- }
- catch (ClassNotFoundException e)
- {
- return null;
- }
- }
-
- /**
- * Change the state of the bundle
- *
- * @param state the new state
- */
- public void changeState(int state)
- {
- int previous = getState();
- int type = 0;
- switch (state)
- {
- case Bundle.STARTING:
- type = BundleEvent.STARTING;
- break;
- case Bundle.ACTIVE:
- type = BundleEvent.STARTED;
- break;
- case Bundle.STOPPING:
- type = BundleEvent.STOPPING;
- break;
- case Bundle.UNINSTALLED:
- type = BundleEvent.UNINSTALLED;
- break;
- case Bundle.INSTALLED:
- {
- if (previous == Bundle.RESOLVED)
- type = BundleEvent.UNRESOLVED;
- else
- type = BundleEvent.INSTALLED;
- break;
- }
- case Bundle.RESOLVED:
- {
- if (previous == Bundle.STOPPING)
- type = BundleEvent.STOPPED;
- else
- type = BundleEvent.RESOLVED;
- break;
- }
- default:
- throw new IllegalArgumentException("Unknown bundle state: " + state);
- }
- this.state.set(state);
- log.debug(this + " change state=" + toHumanReadableStateString(state));
- BundleEvent event = new BundleEvent(type, getBundleInternal());
- fireBundleEvent(event);
- }
-
- /**
- * Fire a bundle event
- *
- * @param event the event
- */
- void fireBundleEvent(BundleEvent event)
- {
- // Nobody is interested
- if (bundleListeners.isEmpty())
- return;
-
- // Are we active?
- if (getBundleManager().isActive() == false)
- return;
-
- // Synchronous listeners first
- for (BundleListener listener : bundleListeners)
- {
- try
- {
- if (listener instanceof SynchronousBundleListener)
- listener.bundleChanged(event);
- }
- catch (Throwable t)
- {
- log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + getCanonicalName(), t);
- }
- }
- // Normal listeners after, if required
- int type = event.getType();
- if (type != BundleEvent.STARTING && type != BundleEvent.STOPPING && type != BundleEvent.LAZY_ACTIVATION)
- {
- for (BundleListener listener : bundleListeners)
- {
- try
- {
- if (listener instanceof SynchronousBundleListener == false)
- listener.bundleChanged(event);
- }
- catch (Throwable t)
- {
- log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + this, t);
- }
- }
- }
- }
-
- /**
- * Fire a framework event
- *
- * @param type the type of event
- * @param throwable any throwable
- */
- void fireFrameworkEvent(int type, Throwable throwable)
- {
- // Nobody is interested
- if (frameworkListeners.isEmpty())
- return;
-
- // Are we active?
- if (getBundleManager().isActive() == false)
- return;
-
- // Call the listeners
- FrameworkEvent event = new FrameworkEvent(type, getBundleInternal(), throwable);
- for (FrameworkListener listener : frameworkListeners)
- {
- try
- {
- listener.frameworkEvent(event);
- }
- catch (Throwable t)
- {
- log.warn("Error while firing framework event: " + event.getType() + " for bundle " + getCanonicalName(), t);
- }
- }
- }
-
- /**
- * Fire a service event
- *
- * @param type the type
- * @param service the service
- */
- void fireServiceEvent(int type, OSGiServiceState service)
- {
- if (service == null)
- throw new IllegalArgumentException("No serviceReference");
-
- // Nobody is interested
- if (serviceListeners.isEmpty())
- return;
-
- // Are we active?
- if (getBundleManager().isActive() == false)
- return;
-
- ServiceEvent event = new ServiceEvent(type, service.getReferenceInternal());
-
- // Call the listeners
- for (Map.Entry<ServiceListener, ServiceListenerRegistration> entry : serviceListeners.entrySet())
- {
- ServiceListener listener = entry.getKey();
- ServiceListenerRegistration registration = entry.getValue();
- try
- {
- if (registration.filter.match(service))
- {
- AccessControlContext accessControlContext = registration.accessControlContext;
- if (accessControlContext == null || service.hasPermission(accessControlContext))
- listener.serviceChanged(event);
- }
- }
- catch (Throwable t)
- {
- log.warn("Error while firing service event: " + type + " for service " + service, t);
- }
- }
- }
-
- /**
- * Check the bundle is installed
- *
- * @throws IllegalStateException when the bundle is not installed
- */
- protected void checkInstalled()
- {
- if ((getState() & Bundle.UNINSTALLED) != 0)
- throw new IllegalStateException("Bundle " + getCanonicalName() + " is not installed");
- }
-
- /**
- * Check a bundle context is still valid
- *
- * @return the bundle context
- * @throws IllegalArgumentException when the context is no longer valid
- */
- protected synchronized BundleContext checkValidBundleContext()
- {
- BundleContext result = this.bundleContext;
- if (result == null)
- throw new IllegalStateException("Bundle context is no longer valid");
- return result;
- }
-
- /**
- * Check the admin permission
- *
- * @param what what permission to check
- * @throws SecurityException when the caller does not have the AdminPermission and a security manager is installed
- */
- protected void checkAdminPermission(String what)
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- sm.checkPermission(new AdminPermission(this, what));
- }
-
- /**
- * Checks if we have the admin permission
- *
- * @param what the permission to check
- * @return true if the caller doesn't have the permission
- */
- private boolean noAdminPermission(String what)
- {
- try
- {
- checkAdminPermission(what);
- return false;
- }
- catch (SecurityException e)
- {
- return true;
- }
- }
-
- /**
- * Get a human readable version of the state
- *
- * @param state the state
- * @return the human readable form
- */
- private static String toHumanReadableStateString(int state)
- {
- switch (state)
- {
- case Bundle.INSTALLED:
- return "INSTALLED";
- case Bundle.RESOLVED:
- return "RESOLVED";
- case Bundle.STARTING:
- return "STARTING";
- case Bundle.ACTIVE:
- return "ACTIVE";
- case Bundle.STOPPING:
- return "STOPPING";
- case Bundle.UNINSTALLED:
- return "UNINSTALLED";
- }
- return "???" + state;
- }
-
- /**
- * ServiceListenerRegistration.
- */
- private static class ServiceListenerRegistration
- {
- // Any filter
- Filter filter;
-
- // Any access control context
- AccessControlContext accessControlContext;
-
- /**
- * Create a new ServiceListenerRegistration.
- *
- * @param filter the filter
- */
- public ServiceListenerRegistration(Filter filter)
- {
- this.filter = filter;
-
- if (System.getSecurityManager() != null)
- accessControlContext = AccessController.getContext();
- }
- }
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java 2009-08-27 00:39:26 UTC (rev 92848)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -45,7 +45,7 @@
public class OSGiBundleWrapper implements Bundle
{
/** The bundle state */
- private OSGiBundleState bundleState;
+ private AbstractBundleState bundleState;
/**
* Create a new OSGiBundleImpl.
@@ -53,7 +53,7 @@
* @param bundleState the bundle state
* @throws IllegalArgumentException for a null parameter
*/
- public OSGiBundleWrapper(OSGiBundleState bundleState)
+ public OSGiBundleWrapper(AbstractBundleState bundleState)
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
@@ -65,7 +65,7 @@
*
* @return the bundle state
*/
- OSGiBundleState getBundleState()
+ AbstractBundleState getBundleState()
{
return bundleState;
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-27 00:39:26 UTC (rev 92848)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -58,7 +58,7 @@
private static final AtomicLong serviceIDGenerator = new AtomicLong();
/** The bundle state */
- private OSGiBundleState bundleState;
+ private AbstractBundleState bundleState;
/** The service reference */
private OSGiServiceReferenceWrapper serviceReference;
@@ -82,7 +82,7 @@
private CaseInsensitiveDictionary properties;
/** The using bundles */
- private Set<OSGiBundleState> usingBundles = new ConcurrentSet<OSGiBundleState>();
+ private Set<AbstractBundleState> usingBundles = new ConcurrentSet<AbstractBundleState>();
/**
* Create a new OSGiServiceState.
@@ -94,7 +94,7 @@
* @throws IllegalArgumentException for a null parameter
*/
@SuppressWarnings("unchecked")
- public OSGiServiceState(OSGiBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
+ public OSGiServiceState(AbstractBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
@@ -226,7 +226,7 @@
*
* @return the bundleState.
*/
- public OSGiBundleState getBundleState()
+ public AbstractBundleState getBundleState()
{
return bundleState;
}
@@ -275,7 +275,7 @@
*
* @param bundleState the bundle
*/
- void addUsingBundle(OSGiBundleState bundleState)
+ void addUsingBundle(AbstractBundleState bundleState)
{
usingBundles.add(bundleState);
}
@@ -285,7 +285,7 @@
*
* @param bundleState the bundle
*/
- void removeUsingBundle(OSGiBundleState bundleState)
+ void removeUsingBundle(AbstractBundleState bundleState)
{
usingBundles.remove(bundleState);
}
@@ -296,7 +296,7 @@
return null;
Set<Bundle> result = new HashSet<Bundle>();
- for (OSGiBundleState bundleState : usingBundles)
+ for (AbstractBundleState bundleState : usingBundles)
result.add(bundleState.getBundleInternal());
return result.toArray(new Bundle[result.size()]);
}
@@ -311,7 +311,7 @@
throw new IllegalArgumentException("Unknown bundle: " + bundle);
OSGiBundleWrapper wrapper = (OSGiBundleWrapper) bundle;
- OSGiBundleState other = wrapper.getBundleState();
+ AbstractBundleState other = wrapper.getBundleState();
return isAssignableTo(other, className);
}
@@ -322,7 +322,7 @@
* @param className the class name
* @return true when assignable
*/
- boolean isAssignableTo(OSGiBundleState other, String className)
+ boolean isAssignableTo(AbstractBundleState other, String className)
{
if (className == null)
throw new IllegalArgumentException("Null class name");
@@ -360,7 +360,7 @@
* @param other the bundle state
* @return true when assignable
*/
- boolean isAssignable(OSGiBundleState other)
+ boolean isAssignable(AbstractBundleState other)
{
if (other == bundleState)
return true;
@@ -382,7 +382,7 @@
* @param className the class name
* @return true when the class name matches
*/
- boolean matchClass(OSGiBundleState other, String className)
+ boolean matchClass(AbstractBundleState other, String className)
{
if (clazzes == null || clazzes.length == 0)
return false;
@@ -511,7 +511,7 @@
{
if (usingBundles.isEmpty() == false)
{
- for (OSGiBundleState using : usingBundles)
+ for (AbstractBundleState using : usingBundles)
using.ungetService(this);
}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java 2009-08-27 00:39:26 UTC (rev 92848)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -1,99 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.osgi.plugins.facade.bundle;
-
-import java.io.InputStream;
-
-import org.jboss.osgi.spi.NotImplementedException;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
-import org.osgi.framework.AdminPermission;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
-
-/**
- * OSGiSystemBundle.
- *
- * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-class OSGiSystemBundle extends OSGiBundleState
-{
- /**
- * Create a new OSGiSystemBundle.
- *
- * @param osgiMetaData the metadata for the system bundle
- */
- public OSGiSystemBundle(OSGiMetaData osgiMetaData)
- {
- super(osgiMetaData);
- }
-
- @Override
- public String getLocation()
- {
- return Constants.SYSTEM_BUNDLE_LOCATION;
- }
-
- public Class<?> loadClass(String name) throws ClassNotFoundException
- {
- // [JBOSGI-138] Proper system BundleContext implementation
- throw new NotImplementedException();
- }
-
- @Override
- public void stop(int options) throws BundleException
- {
- final OSGiBundleManager bundleManager = getBundleManager();
- getBundleManager().getExecutor().execute(new Runnable()
- {
- public void run()
- {
- bundleManager.stopFramework();
- }
- });
- }
-
- @Override
- public void update() throws BundleException
- {
- final OSGiBundleManager bundleManager = getBundleManager();
- getBundleManager().getExecutor().execute(new Runnable()
- {
- public void run()
- {
- bundleManager.restartFramework();
- }
- });
- }
-
- @Override
- public void update(InputStream in) throws BundleException
- {
- throw new BundleException("The system bundle cannot be updated from a stream");
- }
-
- @Override
- public void uninstall() throws BundleException
- {
- throw new BundleException("The system bundle cannot be uninstalled");
- }
-}
Copied: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemState.java (from rev 92848, projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemState.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemState.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -0,0 +1,155 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.facade.bundle;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+
+import org.jboss.osgi.spi.NotImplementedException;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+/**
+ * OSGiSystemBundle.
+ *
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler(a)jboss.com
+ * @version $Revision: 1.1 $
+ */
+public class OSGiSystemState extends AbstractBundleState
+{
+ /**
+ * Create a new OSGiSystemBundle.
+ *
+ * @param osgiMetaData the metadata for the system bundle
+ */
+ public OSGiSystemState(OSGiMetaData osgiMetaData)
+ {
+ super(osgiMetaData);
+ changeState(Bundle.INSTALLED);
+ }
+
+ @Override
+ public long getBundleId()
+ {
+ return 0;
+ }
+
+ @Override
+ public String getLocation()
+ {
+ return Constants.SYSTEM_BUNDLE_LOCATION;
+ }
+
+ public Class<?> loadClass(String name) throws ClassNotFoundException
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Enumeration findEntries(String path, String filePattern, boolean recurse)
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public URL getEntry(String path)
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Enumeration getEntryPaths(String path)
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public URL getResource(String name)
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Enumeration getResources(String name) throws IOException
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void start(int options) throws BundleException
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void stop(int options) throws BundleException
+ {
+ final OSGiBundleManager bundleManager = getBundleManager();
+ getBundleManager().getExecutor().execute(new Runnable()
+ {
+ public void run()
+ {
+ bundleManager.stopFramework();
+ }
+ });
+ }
+
+ @Override
+ public void update() throws BundleException
+ {
+ final OSGiBundleManager bundleManager = getBundleManager();
+ getBundleManager().getExecutor().execute(new Runnable()
+ {
+ public void run()
+ {
+ bundleManager.restartFramework();
+ }
+ });
+ }
+
+ @Override
+ public void update(InputStream in) throws BundleException
+ {
+ throw new BundleException("The system bundle cannot be updated from a stream");
+ }
+
+ @Override
+ public void uninstall() throws BundleException
+ {
+ throw new BundleException("The system bundle cannot be uninstalled");
+ }
+}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java 2009-08-27 00:39:26 UTC (rev 92848)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -33,6 +33,7 @@
import org.jboss.classloader.spi.filter.ClassFilter;
import org.jboss.classloader.spi.filter.PackageClassFilter;
import org.jboss.osgi.plugins.facade.api.SystemPackagesPlugin;
+import org.jboss.osgi.plugins.facade.bundle.AbstractBundleState;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
@@ -63,6 +64,7 @@
filter.setIncludeJava(true);
domain.setParentPolicy(new ParentPolicy(filter, ClassFilter.NOTHING));
+ AbstractJDKChecker.getExcluded().add(AbstractBundleState.class);
AbstractJDKChecker.getExcluded().add(OSGiBundleState.class);
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java 2009-08-27 00:39:26 UTC (rev 92848)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -28,8 +28,8 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
-import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleWrapper;
+import org.jboss.osgi.plugins.facade.bundle.OSGiSystemState;
import org.osgi.framework.BundleException;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.launch.Framework;
@@ -47,7 +47,7 @@
private OSGiBundleManager bundleManager;
- public OSGiFramework(OSGiBundleManager bundleManager, OSGiBundleState bundleState)
+ public OSGiFramework(OSGiBundleManager bundleManager, OSGiSystemState bundleState)
{
super(bundleState);
this.bundleManager = bundleManager;
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java 2009-08-27 00:39:26 UTC (rev 92848)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -35,7 +35,8 @@
import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
import org.jboss.logging.Logger;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
-import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+import org.jboss.osgi.plugins.facade.bundle.AbstractBundleState;
+import org.jboss.osgi.plugins.facade.bundle.OSGiSystemState;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
@@ -86,7 +87,7 @@
throw new IllegalStateException("Cannot obtain installed bean: " + OSGiBundleManager.BEAN_BUNDLE_MANAGER);
OSGiBundleManager manager = (OSGiBundleManager)managerContext.getTarget();
- OSGiBundleState sysBundle = manager.getBundle(0);
+ OSGiSystemState sysBundle = (OSGiSystemState)manager.getBundle(0);
return new OSGiFramework(manager, sysBundle);
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java 2009-08-27 00:39:26 UTC (rev 92848)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java 2009-08-27 08:38:59 UTC (rev 92849)
@@ -33,7 +33,7 @@
import org.jboss.deployers.plugins.main.MainDeployerImpl;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
-import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+import org.jboss.osgi.plugins.facade.bundle.AbstractBundleState;
import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
import org.jboss.virtual.AssembledDirectory;
import org.jboss.virtual.VFS;
@@ -125,8 +125,8 @@
protected void undeployBundles()
{
OSGiBundleManager bundleManager = getBundleManager();
- Collection<OSGiBundleState> bundles = bundleManager.getBundles();
- for (OSGiBundleState bundleState : bundles)
+ Collection<AbstractBundleState> bundles = bundleManager.getBundles();
+ for (AbstractBundleState bundleState : bundles)
{
try
{
@@ -189,7 +189,7 @@
if (resourceRoot == null)
throw new AssertionFailedError("Resource not found: " + root);
URL childResource = new URL(resourceRoot, child);
- OSGiBundleState bundleState = getBundleManager().install(childResource);
+ AbstractBundleState bundleState = getBundleManager().install(childResource);
return bundleState.getBundleInternal();
}
@@ -202,7 +202,7 @@
*/
public Bundle addBundle(VirtualFile file) throws Exception
{
- OSGiBundleState bundleState = getBundleManager().install(file);
+ AbstractBundleState bundleState = getBundleManager().install(file);
return bundleState.getBundleInternal();
}
16 years, 3 months
JBoss-OSGI SVN: r92839 - in projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src: main/java/org/jboss/osgi/plugins/facade/launch and 1 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-26 11:27:23 -0400 (Wed, 26 Aug 2009)
New Revision: 92839
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
Log:
WIP
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java 2009-08-26 15:26:13 UTC (rev 92838)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java 2009-08-26 15:27:23 UTC (rev 92839)
@@ -45,7 +45,7 @@
public class OSGiBundleContextWrapper implements BundleContext
{
/** The bundle state */
- private OSGiBundleState bundleState;
+ private AbstractBundleState bundleState;
/**
* Create a new OSGiBundleContextWrapper.
@@ -53,7 +53,7 @@
* @param bundleState the bundle state
* @throws IllegalArgumentException for a null parameter
*/
- public OSGiBundleContextWrapper(OSGiBundleState bundleState)
+ public OSGiBundleContextWrapper(AbstractBundleState bundleState)
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-26 15:26:13 UTC (rev 92838)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-26 15:27:23 UTC (rev 92839)
@@ -99,7 +99,7 @@
private static String OSGi_FRAMEWORK_PROCESSOR;
/** The bundles by id */
- private Map<Long, OSGiBundleState> bundlesById = new ConcurrentHashMap<Long, OSGiBundleState>();
+ private Map<Long, AbstractBundleState> bundlesById = new ConcurrentHashMap<Long, AbstractBundleState>();
/** The registered services */
private Set<OSGiServiceState> registeredServices = new ConcurrentSet<OSGiServiceState>();
@@ -272,7 +272,7 @@
public boolean isActive()
{
// We are active if the system bundle is at least in the starting/stopping state
- OSGiBundleState bundleState = getSystemBundle();
+ AbstractBundleState bundleState = getSystemBundle();
return bundleState.getState() >= Bundle.STARTING;
}
@@ -358,7 +358,7 @@
public void uninstall(Bundle bundle) throws BundleException
{
long id = bundle.getBundleId();
- OSGiBundleState state = getBundle(id);
+ OSGiBundleState state = (OSGiBundleState)getBundle(id);
if (state == null)
throw new BundleException(bundle + " not installed");
uninstall(state);
@@ -448,7 +448,7 @@
* @param bundleState the bundle state
* @throws IllegalArgumentException for a null bundle state
*/
- public void addBundle(OSGiBundleState bundleState)
+ public void addBundle(AbstractBundleState bundleState)
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
@@ -458,7 +458,7 @@
if (metaData.isSingleton())
{
String symbolicName = metaData.getBundleSymbolicName();
- for (OSGiBundleState bundle : getBundles())
+ for (AbstractBundleState bundle : getBundles())
{
OSGiMetaData other = bundle.getOSGiMetaData();
if (other.isSingleton() && symbolicName.equals(other.getBundleSymbolicName()))
@@ -494,7 +494,7 @@
* @param id the id of the bundle
* @return the bundle or null if there is no bundle with that id
*/
- public OSGiBundleState getBundle(long id)
+ public AbstractBundleState getBundle(long id)
{
return bundlesById.get(id);
}
@@ -517,9 +517,13 @@
*/
public DeploymentUnit getDeployment(long id)
{
- OSGiBundleState bundleState = getBundle(id);
+ if (id == 0)
+ throw new IllegalArgumentException("Cannot get deployment unit for system bundle");
+
+ OSGiBundleState bundleState = (OSGiBundleState)getBundle(id);
if (bundleState == null)
return null;
+
return bundleState.getDeploymentUnit();
}
@@ -528,7 +532,7 @@
*
* @return the bundles
*/
- public Collection<OSGiBundleState> getBundles()
+ public Collection<AbstractBundleState> getBundles()
{
return bundlesById.values();
}
@@ -567,12 +571,13 @@
* @param errorOnFail whether to throw an error if it cannot be resolved
* @return true when resolved
*/
- public boolean resolve(OSGiBundleState bundleState, boolean errorOnFail)
+ public boolean resolve(AbstractBundleState bundleState, boolean errorOnFail)
{
try
{
// [TODO] check actually changed state
- deployerClient.change(bundleState.getDeploymentUnit().getName(), DeploymentStages.CLASSLOADER);
+ DeploymentUnit unit = getDeployment(bundleState.getBundleId());
+ deployerClient.change(unit.getName(), DeploymentStages.CLASSLOADER);
return true;
}
catch (DeploymentException e)
@@ -589,11 +594,11 @@
* @param bundleState the bundle state
* @throws BundleException the bundle exception
*/
- public void start(OSGiBundleState bundleState) throws BundleException
+ public void start(AbstractBundleState bundleState) throws BundleException
{
try
{
- String name = bundleState.getDeploymentUnit().getName();
+ String name = getDeployment(bundleState.getBundleId()).getName();
deployerClient.change(name, DeploymentStages.INSTALLED);
deployerClient.checkComplete(name);
}
@@ -612,11 +617,12 @@
* @param bundleState the bundle state
* @throws BundleException the bundle exception
*/
- public void stop(OSGiBundleState bundleState) throws BundleException
+ public void stop(AbstractBundleState bundleState) throws BundleException
{
try
{
- deployerClient.change(bundleState.getDeploymentUnit().getName(), DeploymentStages.CLASSLOADER);
+ DeploymentUnit unit = getDeployment(bundleState.getBundleId());
+ deployerClient.change(unit.getName(), DeploymentStages.CLASSLOADER);
}
catch (DeploymentException e)
{
@@ -636,7 +642,7 @@
* @param checkAssignable whether to check isAssignable
* @return the services
*/
- Collection<OSGiServiceState> getServices(OSGiBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
+ Collection<OSGiServiceState> getServices(AbstractBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
{
if (filter == null)
filter = NoFilter.INSTANCE;
@@ -671,7 +677,7 @@
* @param clazz any class
* @return the reference
*/
- ServiceReference getServiceReference(OSGiBundleState bundleState, String clazz)
+ ServiceReference getServiceReference(AbstractBundleState bundleState, String clazz)
{
// Ignore isAssignable for the system context
boolean checkAssignable = (bundleState.getBundleId() != 0);
@@ -693,7 +699,7 @@
* @param checkAssignable whether to check isAssignable
* @return the services
*/
- ServiceReference[] getServiceReferences(OSGiBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
+ ServiceReference[] getServiceReferences(AbstractBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
{
Collection<OSGiServiceState> services = getServices(bundleState, clazz, filter, checkAssignable);
if (services == null || services.isEmpty())
@@ -715,7 +721,7 @@
* @return the services
* @throws InvalidSyntaxException when the filter is invalid
*/
- ServiceReference[] getServiceReferences(OSGiBundleState bundleState, String clazz, String filter, boolean checkAssignable) throws InvalidSyntaxException
+ ServiceReference[] getServiceReferences(AbstractBundleState bundleState, String clazz, String filter, boolean checkAssignable) throws InvalidSyntaxException
{
Filter f = NoFilter.INSTANCE;
if (filter != null)
@@ -733,7 +739,7 @@
* @return the service state
*/
@SuppressWarnings("unchecked")
- OSGiServiceState registerService(OSGiBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
+ OSGiServiceState registerService(AbstractBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
{
OSGiServiceState result = new OSGiServiceState(bundleState, clazzes, service, properties);
result.internalRegister();
@@ -763,7 +769,7 @@
* @param reference the service reference
* @return the service
*/
- Object getService(OSGiBundleState bundleState, ServiceReference reference)
+ Object getService(AbstractBundleState bundleState, ServiceReference reference)
{
OSGiServiceReferenceWrapper serviceReference = (OSGiServiceReferenceWrapper) reference;
OSGiServiceState serviceState = serviceReference.getServiceState();
@@ -780,7 +786,7 @@
* @param reference the service reference
* @return true when the service is still in use by the bundle
*/
- boolean ungetService(OSGiBundleState bundleState, ServiceReference reference)
+ boolean ungetService(AbstractBundleState bundleState, ServiceReference reference)
{
if (reference == null)
throw new IllegalArgumentException("Null reference");
@@ -870,12 +876,12 @@
*/
public void stopFramework()
{
- OSGiBundleState systemBundle = getSystemBundle();
+ AbstractBundleState systemBundle = getSystemBundle();
if (systemBundle.getState() != Bundle.ACTIVE)
return;
systemBundle.changeState(Bundle.STOPPING);
- for (OSGiBundleState bundle : getBundles())
+ for (AbstractBundleState bundle : getBundles())
{
if (bundle != systemBundle)
{
@@ -898,11 +904,11 @@
*/
public void restartFramework()
{
- OSGiBundleState systemBundle = getSystemBundle();
+ AbstractBundleState systemBundle = getSystemBundle();
if (systemBundle.getState() != Bundle.ACTIVE)
return;
- for (OSGiBundleState bundle : getBundles())
+ for (AbstractBundleState bundle : getBundles())
{
if (bundle != systemBundle && bundle.getState() == Bundle.ACTIVE)
{
@@ -932,7 +938,7 @@
*
* @param t the throwable
*/
- void fireError(OSGiBundleState bundleState, String context, Throwable t)
+ void fireError(AbstractBundleState bundleState, String context, Throwable t)
{
OSGiSystemBundle systemBundle = getSystemBundle();
if (t instanceof BundleException)
@@ -948,7 +954,7 @@
*
* @param t the throwable
*/
- void fireWarning(OSGiBundleState bundleState, String context, Throwable t)
+ void fireWarning(AbstractBundleState bundleState, String context, Throwable t)
{
OSGiSystemBundle systemBundle = getSystemBundle();
if (t instanceof BundleException)
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java 2009-08-26 15:26:13 UTC (rev 92838)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java 2009-08-26 15:27:23 UTC (rev 92839)
@@ -21,26 +21,10 @@
*/
package org.jboss.osgi.plugins.facade.bundle;
-import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
import java.net.URL;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.Permission;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Dictionary;
import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.jboss.beans.info.spi.BeanInfo;
@@ -50,30 +34,13 @@
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.logging.Logger;
-import org.jboss.osgi.plugins.facade.api.BundleStoragePlugin;
-import org.jboss.osgi.plugins.filter.NoFilter;
-import org.jboss.osgi.spi.NotImplementedException;
import org.jboss.osgi.spi.metadata.OSGiMetaData;
-import org.jboss.util.collection.ConcurrentSet;
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleException;
-import org.osgi.framework.BundleListener;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkEvent;
-import org.osgi.framework.FrameworkListener;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.SynchronousBundleListener;
-import org.osgi.framework.Version;
/**
* BundleState.
@@ -81,189 +48,43 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class OSGiBundleState implements Bundle, BundleContext
+public class OSGiBundleState extends AbstractBundleState
{
/** The log */
private static final Logger log = Logger.getLogger(OSGiBundleState.class);
-
+
/** Used to generate a unique id */
private static final AtomicLong bundleIDGenerator = new AtomicLong();
/** The bundle id */
private long bundleId;
- /** The last modified time stamp */
- private long lastModified = System.currentTimeMillis();
-
- /** The bundle manager */
- private OSGiBundleManager bundleManager;
-
- /** The osgi metadata */
- private OSGiMetaData osgiMetaData;
-
/** The deployment unit */
private DeploymentUnit unit;
- /** The bundle context */
- private BundleContext bundleContext;
-
- /** The bundle */
- private Bundle bundle;
-
- /** The bundle state */
- private AtomicInteger state = new AtomicInteger(Bundle.UNINSTALLED);
-
- /** The registered services in use */
- private Set<OSGiServiceState> registeredServices = new ConcurrentSet<OSGiServiceState>();
-
- /** The services in use */
- private Map<OSGiServiceState, Integer> servicesInUse = new ConcurrentHashMap<OSGiServiceState, Integer>();
-
- /** The bundle listeners */
- private List<BundleListener> bundleListeners = new CopyOnWriteArrayList<BundleListener>();
-
- /** The framework listeners */
- private List<FrameworkListener> frameworkListeners = new CopyOnWriteArrayList<FrameworkListener>();
-
- /** The service listeners */
- private Map<ServiceListener, ServiceListenerRegistration> serviceListeners = new ConcurrentHashMap<ServiceListener, ServiceListenerRegistration>();
-
- /**
- * Create a new BundleState.
- *
- * @param osgiMetaData the osgi metadata
- * @param unit the deployment unit
- * @throws IllegalArgumentException for a null parameter
- */
public OSGiBundleState(OSGiMetaData osgiMetaData, DeploymentUnit unit)
{
- if (osgiMetaData == null)
- throw new IllegalArgumentException("Null osgi metadata");
- if (unit == null)
- throw new IllegalArgumentException("Null deployment unit");
- this.osgiMetaData = osgiMetaData;
+ super(osgiMetaData);
this.unit = unit;
this.bundleId = bundleIDGenerator.incrementAndGet();
unit.getMutableMetaData().addMetaData(unit, DeploymentUnit.class);
changeState(Bundle.INSTALLED);
}
- /**
- * Create a new BundleState for the system bundle.
- *
- * @param osgiMetaData the osgi metadata
- * @throws IllegalArgumentException for a null parameter
- */
- OSGiBundleState(OSGiMetaData osgiMetaData)
+ public long getBundleId()
{
- if (osgiMetaData == null)
- throw new IllegalArgumentException("Null osgi metadata");
- this.osgiMetaData = osgiMetaData;
- this.bundleId = 0;
- changeState(Bundle.INSTALLED);
+ return bundleId;
}
-
+
/**
- * Get the bundleManager.
- *
- * @return the bundleManager.
+ * Get the unit.
+ * @return the unit.
*/
- public OSGiBundleManager getBundleManager()
+ DeploymentUnit getDeploymentUnit()
{
- return bundleManager;
+ return unit;
}
- public long getBundleId()
- {
- return bundleId;
- }
-
- public String getSymbolicName()
- {
- return osgiMetaData.getBundleSymbolicName();
- }
-
- public Version getVersion()
- {
- return osgiMetaData.getBundleVersion();
- }
-
- public int getState()
- {
- return state.get();
- }
-
- public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType)
- {
- throw new NotImplementedException();
- }
-
- public synchronized BundleContext getBundleContext()
- {
- checkAdminPermission(AdminPermission.CONTEXT);
- return bundleContext;
- }
-
- public synchronized BundleContext createBundleContext()
- {
- if (bundleContext == null)
- bundleContext = new OSGiBundleContextWrapper(this);
- return bundleContext;
- }
-
- public synchronized Bundle getBundle()
- {
- checkValidBundleContext();
- return getBundleInternal();
- }
-
- public synchronized Bundle getBundleInternal()
- {
- if (bundle == null)
- bundle = new OSGiBundleWrapper(this);
- return bundle;
- }
-
- public Bundle getBundle(long id)
- {
- checkValidBundleContext();
- OSGiBundleManager bundleManager = getBundleManager();
- if (bundleManager == null)
- return null;
-
- OSGiBundleState bundleState = bundleManager.getBundle(id);
- if (bundleState == null)
- return null;
- return bundleState.getBundleInternal();
- }
-
- public Bundle[] getBundles()
- {
- checkValidBundleContext();
- OSGiBundleManager bundleManager = getBundleManager();
- if (bundleManager == null)
- return null;
-
- Collection<OSGiBundleState> bundleStates = bundleManager.getBundles();
- if (bundleStates.isEmpty())
- return new Bundle[0];
-
- List<Bundle> bundles = new ArrayList<Bundle>(bundleStates.size());
- for (OSGiBundleState bundleState : bundleStates)
- bundles.add(bundleState.getBundleInternal());
- return bundles.toArray(new Bundle[bundles.size()]);
- }
-
- public long getLastModified()
- {
- return lastModified;
- }
-
- public void modified()
- {
- lastModified = System.currentTimeMillis();
- }
-
public String getLocation()
{
checkAdminPermission(AdminPermission.METADATA);
@@ -282,43 +103,7 @@
return null;
}
-
- /**
- * Get the osgiMetaData.
- *
- * @return the osgiMetaData.
- */
- public OSGiMetaData getOSGiMetaData()
- {
- return osgiMetaData;
- }
-
- @SuppressWarnings("unchecked")
- public Dictionary getHeaders()
- {
- return getHeaders(null);
- }
-
- @SuppressWarnings("unchecked")
- public Dictionary getHeaders(String locale)
- {
- checkAdminPermission(AdminPermission.METADATA);
- return getOSGiMetaData().getHeaders(locale);
- }
-
- public String getProperty(String key)
- {
- checkValidBundleContext();
- return bundleManager.getProperty(key);
- }
-
- public File getDataFile(String filename)
- {
- checkValidBundleContext();
- BundleStoragePlugin storagePlugin = bundleManager.getOptionalPlugin(BundleStoragePlugin.class);
- return storagePlugin != null ? storagePlugin.getDataFile(this, filename) : null;
- }
-
+
public URL getEntry(String path)
{
checkInstalled();
@@ -448,296 +233,7 @@
return getDeploymentUnit().getClassLoader().getResources(name);
}
- public boolean hasPermission(Object permission)
- {
- if (permission == null || permission instanceof Permission == false)
- return false;
-
- SecurityManager sm = System.getSecurityManager();
- if (sm == null)
- return true;
-
- // [TODO] hasPermission
- return true;
- }
-
- public Filter createFilter(String filter) throws InvalidSyntaxException
- {
- checkValidBundleContext();
- return FrameworkUtil.createFilter(filter);
- }
-
- public void addServiceListener(ServiceListener listener)
- {
- addServiceListenerInternal(listener, null);
- }
-
- public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException
- {
- Filter theFilter = null;
- if (filter != null)
- theFilter = createFilter(filter);
- addServiceListenerInternal(listener, theFilter);
- }
-
- public void addServiceListenerInternal(ServiceListener listener, Filter filter)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
- if (filter == null)
- filter = NoFilter.INSTANCE;
- checkValidBundleContext();
-
- serviceListeners.put(listener, new ServiceListenerRegistration(filter));
- }
-
- public void removeServiceListener(ServiceListener listener)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
-
- checkValidBundleContext();
-
- serviceListeners.remove(listener);
- }
-
/**
- * Add a registered service
- *
- * @param serviceState the service
- */
- void addRegisteredService(OSGiServiceState serviceState)
- {
- registeredServices.add(serviceState);
- }
-
- /**
- * Remove a registered service
- *
- * @param serviceState the service
- */
- void removeRegisteredService(OSGiServiceState serviceState)
- {
- registeredServices.remove(serviceState);
- }
-
- public ServiceReference[] getRegisteredServices()
- {
- checkInstalled();
-
- if (registeredServices.isEmpty())
- return null;
-
- Set<ServiceReference> result = new HashSet<ServiceReference>(registeredServices.size());
- for (OSGiServiceState service : registeredServices)
- {
- if (service.hasPermission())
- result.add(service.getReferenceInternal());
- }
- if (result.isEmpty())
- return null;
- return result.toArray(new ServiceReference[result.size()]);
- }
-
- /**
- * Increment the use count of a service for this bundle
- *
- * @param serviceState the service
- */
- void addServiceInUse(OSGiServiceState serviceState)
- {
- synchronized (servicesInUse)
- {
- Integer count = servicesInUse.get(serviceState);
- if (count == null)
- servicesInUse.put(serviceState, 1);
- else
- servicesInUse.put(serviceState, ++count);
- }
- serviceState.addUsingBundle(this);
- }
-
- /**
- * Decrement the use count of a service for this bundle
- *
- * @param serviceState the service
- * @return true when the service is still in use by the bundle
- */
- boolean removeServiceInUse(OSGiServiceState serviceState)
- {
- synchronized (servicesInUse)
- {
- Integer count = servicesInUse.get(serviceState);
- if (count == null)
- {
- return false;
- }
- else if (count == 1)
- {
- servicesInUse.remove(serviceState);
- serviceState.removeUsingBundle(this);
- return false;
- }
- else
- {
- servicesInUse.put(serviceState, --count);
- }
- }
- return true;
- }
-
- public ServiceReference[] getServicesInUse()
- {
- checkInstalled();
-
- synchronized (servicesInUse)
- {
- Collection<OSGiServiceState> inUse = servicesInUse.keySet();
- if (inUse.isEmpty())
- return null;
-
- Set<ServiceReference> result = new HashSet<ServiceReference>(inUse.size());
- for (OSGiServiceState service : inUse)
- {
- if (service.hasPermission())
- result.add(service.getReferenceInternal());
- }
- if (result.isEmpty())
- return null;
- return result.toArray(new ServiceReference[result.size()]);
- }
- }
-
- public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException
- {
- checkValidBundleContext();
- return getBundleManager().getServiceReferences(this, clazz, filter, false);
- }
-
- public Object getService(ServiceReference reference)
- {
- checkValidBundleContext();
-
- if (reference == null)
- throw new IllegalArgumentException("Null reference");
-
- return getBundleManager().getService(this, reference);
- }
-
- public ServiceReference getServiceReference(String clazz)
- {
- checkValidBundleContext();
- if (clazz == null)
- throw new IllegalArgumentException("Null clazz");
- return getBundleManager().getServiceReference(this, clazz);
- }
-
- public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
- {
- checkValidBundleContext();
- return getBundleManager().getServiceReferences(this, clazz, filter, true);
- }
-
- @SuppressWarnings("unchecked")
- public ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
- {
- if (clazz == null)
- throw new IllegalArgumentException("Null class");
- return registerService(new String[] { clazz }, service, properties);
- }
-
- @SuppressWarnings("unchecked")
- public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
- {
- checkValidBundleContext();
-
- OSGiServiceState serviceState = getBundleManager().registerService(this, clazzes, service, properties);
- return serviceState.getRegistration();
- }
-
- /**
- * Unregister a service
- *
- * @param serviceState the service state
- */
- void unregisterService(OSGiServiceState serviceState)
- {
- getBundleManager().unregisterService(serviceState);
- }
-
- public boolean ungetService(ServiceReference reference)
- {
- checkValidBundleContext();
-
- return getBundleManager().ungetService(this, reference);
- }
-
- boolean ungetService(OSGiServiceState state)
- {
- return getBundleManager().ungetService(this, state);
- }
-
- public void addBundleListener(BundleListener listener)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
-
- checkValidBundleContext();
-
- if (listener instanceof SynchronousBundleListener)
- checkAdminPermission(AdminPermission.LISTENER);
-
- if (bundleListeners.contains(listener))
- return;
-
- bundleListeners.add(listener);
- }
-
- public void removeBundleListener(BundleListener listener)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
-
- checkValidBundleContext();
-
- if (listener instanceof SynchronousBundleListener)
- checkAdminPermission(AdminPermission.LISTENER);
-
- bundleListeners.remove(listener);
- }
-
- /**
- * Try to resolve the bundle
- *
- * @param errorOnFail whether to throw an error when not installed
- * @return true when resolved
- */
- boolean resolve(boolean errorOnFail)
- {
- if (getState() != INSTALLED)
- return true;
-
- return getBundleManager().resolve(this, errorOnFail);
- }
-
- public void start() throws BundleException
- {
- start(0);
- }
-
- // [TODO] options
- public void start(int options) throws BundleException
- {
- checkInstalled();
- checkAdminPermission(AdminPermission.EXECUTE);
-
- if (getState() == ACTIVE)
- return;
-
- getBundleManager().start(this);
- }
-
- /**
* Start internal
*
* [TODO] Start Level Service & START_TRANSIENT? [TODO] START_ACTIVATION_POLICY [TODO] LAZY_ACTIVATION [TODO] locks [TODO] options
@@ -747,7 +243,7 @@
public void startInternal() throws Throwable
{
changeState(STARTING);
- bundleContext = createBundleContext();
+ createBundleContext();
try
{
OSGiMetaData metaData = getOSGiMetaData();
@@ -772,12 +268,12 @@
BundleActivator bundleActivator = (BundleActivator)result;
getDeploymentUnit().addAttachment(BundleActivator.class, bundleActivator);
- bundleActivator.start(bundleContext);
+ bundleActivator.start(getBundleContext());
}
}
if (getState() != STARTING)
- throw new BundleException("Bundle has been uninstalled: " + bundle);
+ throw new BundleException("Bundle has been uninstalled: " + this);
changeState(ACTIVE);
}
@@ -785,29 +281,12 @@
{
changeState(STOPPING);
// TODO stop the bundle
- this.bundleContext = null;
+ destroyBundleContext();
changeState(RESOLVED);
throw t;
}
}
- public void stop() throws BundleException
- {
- stop(0);
- }
-
- // [TODO] options
- public void stop(int options) throws BundleException
- {
- checkInstalled();
- checkAdminPermission(AdminPermission.EXECUTE);
-
- if (getState() != ACTIVE)
- return;
-
- getBundleManager().stop(this);
- }
-
/**
* Stop Internal
*
@@ -823,7 +302,7 @@
try
{
BundleActivator bundleActivator = getDeploymentUnit().getAttachment(BundleActivator.class);
- BundleContext bundleContext = this.bundleContext;
+ BundleContext bundleContext = getBundleContext();
if (bundleActivator != null && bundleContext != null)
{
try
@@ -872,459 +351,11 @@
{
if (getState() == STOPPING)
changeState(RESOLVED);
- bundleContext = null;
+ destroyBundleContext();
getDeploymentUnit().removeAttachment(BundleActivator.class);
}
if (rethrow != null)
throw rethrow;
}
-
- public void update() throws BundleException
- {
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
- // [TODO] update
- throw new UnsupportedOperationException("update");
- }
-
- public void update(InputStream in) throws BundleException
- {
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
- // [TODO] update
- throw new UnsupportedOperationException("update");
- }
-
- public void uninstall() throws BundleException
- {
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
-
- OSGiBundleManager bundleManager = getBundleManager();
- if (bundleManager == null)
- return;
-
- bundleManager.uninstall(this);
- }
-
- void uninstallInternal()
- {
- changeState(Bundle.UNINSTALLED);
-
- frameworkListeners.clear();
- bundleListeners.clear();
- serviceListeners.clear();
- }
-
- public void addFrameworkListener(FrameworkListener listener)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
-
- checkValidBundleContext();
-
- if (frameworkListeners.contains(listener))
- return;
-
- frameworkListeners.add(listener);
- }
-
- public void removeFrameworkListener(FrameworkListener listener)
- {
- if (listener == null)
- throw new IllegalArgumentException("Null listener");
-
- checkValidBundleContext();
-
- frameworkListeners.remove(listener);
- }
-
- public Bundle installBundle(String location, InputStream input) throws BundleException
- {
- checkValidBundleContext();
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
- // [TODO] installBundle
- throw new UnsupportedOperationException("installBundle");
- }
-
- public Bundle installBundle(String location) throws BundleException
- {
- checkValidBundleContext();
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
-
- OSGiBundleManager bundleManager = getBundleManager();
- if (bundleManager == null)
- throw new IllegalStateException("Bundle " + getCanonicalName() + " is not valid");
-
- URL url = getLocationURL(location);
- OSGiBundleState bundleState = bundleManager.install(url);
- return bundleState.getBundleInternal();
- }
-
- private URL getLocationURL(String location) throws BundleException
- {
- // Try location as URL
- URL url = null;
- try
- {
- url = new URL(location);
- }
- catch (MalformedURLException e)
- {
- // ignore
- }
-
- // Try location as File
- if (url == null)
- {
- try
- {
- File file = new File(location);
- if (file.exists())
- url = file.toURL();
- }
- catch (MalformedURLException e)
- {
- // ignore
- }
- }
-
- if (url == null)
- throw new BundleException("Unable to handle location=" + location);
-
- return url;
- }
-
- @Override
- public String toString()
- {
- return "Bundle{" + getCanonicalName() + "}";
- }
-
- /**
- * Get the canonical name of the bundle
- *
- * @return the canonical name
- */
- String getCanonicalName()
- {
- return getSymbolicName() + ":" + osgiMetaData.getBundleVersion();
- }
-
- /**
- * Set the bundle manager
- *
- * @param bundleManager the bundle manager or null to uninstall the bundle
- */
- void setBundleManager(OSGiBundleManager bundleManager)
- {
- if (bundleManager != null && this.bundleManager != null)
- throw new IllegalStateException("Bundle " + this + " is already installed");
- this.bundleManager = bundleManager;
- if (bundleManager == null)
- changeState(Bundle.UNINSTALLED);
- }
-
- /**
- * Get the unit.
- *
- * @return the unit.
- */
- DeploymentUnit getDeploymentUnit()
- {
- return unit;
- }
-
- /**
- * Get the source of a class for ServiceReference.isAssignable()
- *
- * @param className the class name
- * @return the source or null if no source
- */
- Object getSource(String className)
- {
- // [TODO] some more efficient way than using the class?
- try
- {
- return loadClass(className);
- }
- catch (ClassNotFoundException e)
- {
- return null;
- }
- }
-
- /**
- * Change the state of the bundle
- *
- * @param state the new state
- */
- public void changeState(int state)
- {
- int previous = getState();
- int type = 0;
- switch (state)
- {
- case Bundle.STARTING:
- type = BundleEvent.STARTING;
- break;
- case Bundle.ACTIVE:
- type = BundleEvent.STARTED;
- break;
- case Bundle.STOPPING:
- type = BundleEvent.STOPPING;
- break;
- case Bundle.UNINSTALLED:
- type = BundleEvent.UNINSTALLED;
- break;
- case Bundle.INSTALLED:
- {
- if (previous == Bundle.RESOLVED)
- type = BundleEvent.UNRESOLVED;
- else
- type = BundleEvent.INSTALLED;
- break;
- }
- case Bundle.RESOLVED:
- {
- if (previous == Bundle.STOPPING)
- type = BundleEvent.STOPPED;
- else
- type = BundleEvent.RESOLVED;
- break;
- }
- default:
- throw new IllegalArgumentException("Unknown bundle state: " + state);
- }
- this.state.set(state);
- log.debug(this + " change state=" + toHumanReadableStateString(state));
- BundleEvent event = new BundleEvent(type, getBundleInternal());
- fireBundleEvent(event);
- }
-
- /**
- * Fire a bundle event
- *
- * @param event the event
- */
- void fireBundleEvent(BundleEvent event)
- {
- // Nobody is interested
- if (bundleListeners.isEmpty())
- return;
-
- // Are we active?
- if (getBundleManager().isActive() == false)
- return;
-
- // Synchronous listeners first
- for (BundleListener listener : bundleListeners)
- {
- try
- {
- if (listener instanceof SynchronousBundleListener)
- listener.bundleChanged(event);
- }
- catch (Throwable t)
- {
- log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + getCanonicalName(), t);
- }
- }
- // Normal listeners after, if required
- int type = event.getType();
- if (type != BundleEvent.STARTING && type != BundleEvent.STOPPING && type != BundleEvent.LAZY_ACTIVATION)
- {
- for (BundleListener listener : bundleListeners)
- {
- try
- {
- if (listener instanceof SynchronousBundleListener == false)
- listener.bundleChanged(event);
- }
- catch (Throwable t)
- {
- log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + this, t);
- }
- }
- }
- }
-
- /**
- * Fire a framework event
- *
- * @param type the type of event
- * @param throwable any throwable
- */
- void fireFrameworkEvent(int type, Throwable throwable)
- {
- // Nobody is interested
- if (frameworkListeners.isEmpty())
- return;
-
- // Are we active?
- if (getBundleManager().isActive() == false)
- return;
-
- // Call the listeners
- FrameworkEvent event = new FrameworkEvent(type, getBundleInternal(), throwable);
- for (FrameworkListener listener : frameworkListeners)
- {
- try
- {
- listener.frameworkEvent(event);
- }
- catch (Throwable t)
- {
- log.warn("Error while firing framework event: " + event.getType() + " for bundle " + getCanonicalName(), t);
- }
- }
- }
-
- /**
- * Fire a service event
- *
- * @param type the type
- * @param service the service
- */
- void fireServiceEvent(int type, OSGiServiceState service)
- {
- if (service == null)
- throw new IllegalArgumentException("No serviceReference");
-
- // Nobody is interested
- if (serviceListeners.isEmpty())
- return;
-
- // Are we active?
- if (getBundleManager().isActive() == false)
- return;
-
- ServiceEvent event = new ServiceEvent(type, service.getReferenceInternal());
-
- // Call the listeners
- for (Map.Entry<ServiceListener, ServiceListenerRegistration> entry : serviceListeners.entrySet())
- {
- ServiceListener listener = entry.getKey();
- ServiceListenerRegistration registration = entry.getValue();
- try
- {
- if (registration.filter.match(service))
- {
- AccessControlContext accessControlContext = registration.accessControlContext;
- if (accessControlContext == null || service.hasPermission(accessControlContext))
- listener.serviceChanged(event);
- }
- }
- catch (Throwable t)
- {
- log.warn("Error while firing service event: " + type + " for service " + service, t);
- }
- }
- }
-
- /**
- * Check the bundle is installed
- *
- * @throws IllegalStateException when the bundle is not installed
- */
- protected void checkInstalled()
- {
- if ((getState() & Bundle.UNINSTALLED) != 0)
- throw new IllegalStateException("Bundle " + getCanonicalName() + " is not installed");
- }
-
- /**
- * Check a bundle context is still valid
- *
- * @return the bundle context
- * @throws IllegalArgumentException when the context is no longer valid
- */
- protected synchronized BundleContext checkValidBundleContext()
- {
- BundleContext result = this.bundleContext;
- if (result == null)
- throw new IllegalStateException("Bundle context is no longer valid");
- return result;
- }
-
- /**
- * Check the admin permission
- *
- * @param what what permission to check
- * @throws SecurityException when the caller does not have the AdminPermission and a security manager is installed
- */
- protected void checkAdminPermission(String what)
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- sm.checkPermission(new AdminPermission(this, what));
- }
-
- /**
- * Checks if we have the admin permission
- *
- * @param what the permission to check
- * @return true if the caller doesn't have the permission
- */
- private boolean noAdminPermission(String what)
- {
- try
- {
- checkAdminPermission(what);
- return false;
- }
- catch (SecurityException e)
- {
- return true;
- }
- }
-
- /**
- * Get a human readable version of the state
- *
- * @param state the state
- * @return the human readable form
- */
- private static String toHumanReadableStateString(int state)
- {
- switch (state)
- {
- case Bundle.INSTALLED:
- return "INSTALLED";
- case Bundle.RESOLVED:
- return "RESOLVED";
- case Bundle.STARTING:
- return "STARTING";
- case Bundle.ACTIVE:
- return "ACTIVE";
- case Bundle.STOPPING:
- return "STOPPING";
- case Bundle.UNINSTALLED:
- return "UNINSTALLED";
- }
- return "???" + state;
- }
-
- /**
- * ServiceListenerRegistration.
- */
- private static class ServiceListenerRegistration
- {
- // Any filter
- Filter filter;
-
- // Any access control context
- AccessControlContext accessControlContext;
-
- /**
- * Create a new ServiceListenerRegistration.
- *
- * @param filter the filter
- */
- public ServiceListenerRegistration(Filter filter)
- {
- this.filter = filter;
-
- if (System.getSecurityManager() != null)
- accessControlContext = AccessController.getContext();
- }
- }
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java 2009-08-26 15:26:13 UTC (rev 92838)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java 2009-08-26 15:27:23 UTC (rev 92839)
@@ -45,7 +45,7 @@
public class OSGiBundleWrapper implements Bundle
{
/** The bundle state */
- private OSGiBundleState bundleState;
+ private AbstractBundleState bundleState;
/**
* Create a new OSGiBundleImpl.
@@ -53,7 +53,7 @@
* @param bundleState the bundle state
* @throws IllegalArgumentException for a null parameter
*/
- public OSGiBundleWrapper(OSGiBundleState bundleState)
+ public OSGiBundleWrapper(AbstractBundleState bundleState)
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
@@ -65,7 +65,7 @@
*
* @return the bundle state
*/
- OSGiBundleState getBundleState()
+ AbstractBundleState getBundleState()
{
return bundleState;
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-26 15:26:13 UTC (rev 92838)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-26 15:27:23 UTC (rev 92839)
@@ -58,7 +58,7 @@
private static final AtomicLong serviceIDGenerator = new AtomicLong();
/** The bundle state */
- private OSGiBundleState bundleState;
+ private AbstractBundleState bundleState;
/** The service reference */
private OSGiServiceReferenceWrapper serviceReference;
@@ -82,7 +82,7 @@
private CaseInsensitiveDictionary properties;
/** The using bundles */
- private Set<OSGiBundleState> usingBundles = new ConcurrentSet<OSGiBundleState>();
+ private Set<AbstractBundleState> usingBundles = new ConcurrentSet<AbstractBundleState>();
/**
* Create a new OSGiServiceState.
@@ -94,7 +94,7 @@
* @throws IllegalArgumentException for a null parameter
*/
@SuppressWarnings("unchecked")
- public OSGiServiceState(OSGiBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
+ public OSGiServiceState(AbstractBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
@@ -226,7 +226,7 @@
*
* @return the bundleState.
*/
- public OSGiBundleState getBundleState()
+ public AbstractBundleState getBundleState()
{
return bundleState;
}
@@ -275,7 +275,7 @@
*
* @param bundleState the bundle
*/
- void addUsingBundle(OSGiBundleState bundleState)
+ void addUsingBundle(AbstractBundleState bundleState)
{
usingBundles.add(bundleState);
}
@@ -285,7 +285,7 @@
*
* @param bundleState the bundle
*/
- void removeUsingBundle(OSGiBundleState bundleState)
+ void removeUsingBundle(AbstractBundleState bundleState)
{
usingBundles.remove(bundleState);
}
@@ -296,7 +296,7 @@
return null;
Set<Bundle> result = new HashSet<Bundle>();
- for (OSGiBundleState bundleState : usingBundles)
+ for (AbstractBundleState bundleState : usingBundles)
result.add(bundleState.getBundleInternal());
return result.toArray(new Bundle[result.size()]);
}
@@ -311,7 +311,7 @@
throw new IllegalArgumentException("Unknown bundle: " + bundle);
OSGiBundleWrapper wrapper = (OSGiBundleWrapper) bundle;
- OSGiBundleState other = wrapper.getBundleState();
+ AbstractBundleState other = wrapper.getBundleState();
return isAssignableTo(other, className);
}
@@ -360,7 +360,7 @@
* @param other the bundle state
* @return true when assignable
*/
- boolean isAssignable(OSGiBundleState other)
+ boolean isAssignable(AbstractBundleState other)
{
if (other == bundleState)
return true;
@@ -382,7 +382,7 @@
* @param className the class name
* @return true when the class name matches
*/
- boolean matchClass(OSGiBundleState other, String className)
+ boolean matchClass(AbstractBundleState other, String className)
{
if (clazzes == null || clazzes.length == 0)
return false;
@@ -511,7 +511,7 @@
{
if (usingBundles.isEmpty() == false)
{
- for (OSGiBundleState using : usingBundles)
+ for (AbstractBundleState using : usingBundles)
using.ungetService(this);
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java 2009-08-26 15:26:13 UTC (rev 92838)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java 2009-08-26 15:27:23 UTC (rev 92839)
@@ -21,11 +21,14 @@
*/
package org.jboss.osgi.plugins.facade.bundle;
+import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
import org.jboss.osgi.spi.NotImplementedException;
import org.jboss.osgi.spi.metadata.OSGiMetaData;
-import org.osgi.framework.AdminPermission;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
@@ -35,7 +38,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-class OSGiSystemBundle extends OSGiBundleState
+public class OSGiSystemBundle extends AbstractBundleState
{
/**
* Create a new OSGiSystemBundle.
@@ -45,20 +48,20 @@
public OSGiSystemBundle(OSGiMetaData osgiMetaData)
{
super(osgiMetaData);
+ changeState(Bundle.INSTALLED);
}
+ public long getBundleId()
+ {
+ return 0;
+ }
+
@Override
public String getLocation()
{
return Constants.SYSTEM_BUNDLE_LOCATION;
}
- public Class<?> loadClass(String name) throws ClassNotFoundException
- {
- // [JBOSGI-138] Proper system BundleContext implementation
- throw new NotImplementedException();
- }
-
@Override
public void stop(int options) throws BundleException
{
@@ -96,4 +99,48 @@
{
throw new BundleException("The system bundle cannot be uninstalled");
}
+
+ public Class<?> loadClass(String name) throws ClassNotFoundException
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Enumeration findEntries(String path, String filePattern, boolean recurse)
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public URL getEntry(String path)
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Enumeration getEntryPaths(String path)
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public URL getResource(String name)
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Enumeration getResources(String name) throws IOException
+ {
+ // [JBOSGI-138] Proper system BundleContext implementation
+ throw new NotImplementedException();
+ }
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java 2009-08-26 15:26:13 UTC (rev 92838)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java 2009-08-26 15:27:23 UTC (rev 92839)
@@ -28,8 +28,8 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
-import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleWrapper;
+import org.jboss.osgi.plugins.facade.bundle.OSGiSystemBundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.launch.Framework;
@@ -47,7 +47,7 @@
private OSGiBundleManager bundleManager;
- public OSGiFramework(OSGiBundleManager bundleManager, OSGiBundleState bundleState)
+ public OSGiFramework(OSGiBundleManager bundleManager, OSGiSystemBundle bundleState)
{
super(bundleState);
this.bundleManager = bundleManager;
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java 2009-08-26 15:26:13 UTC (rev 92838)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java 2009-08-26 15:27:23 UTC (rev 92839)
@@ -35,7 +35,7 @@
import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
import org.jboss.logging.Logger;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
-import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+import org.jboss.osgi.plugins.facade.bundle.OSGiSystemBundle;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
@@ -86,7 +86,7 @@
throw new IllegalStateException("Cannot obtain installed bean: " + OSGiBundleManager.BEAN_BUNDLE_MANAGER);
OSGiBundleManager manager = (OSGiBundleManager)managerContext.getTarget();
- OSGiBundleState sysBundle = manager.getBundle(0);
+ OSGiSystemBundle sysBundle = (OSGiSystemBundle)manager.getBundle(0);
return new OSGiFramework(manager, sysBundle);
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java 2009-08-26 15:26:13 UTC (rev 92838)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java 2009-08-26 15:27:23 UTC (rev 92839)
@@ -32,6 +32,7 @@
import org.jboss.dependency.spi.ControllerState;
import org.jboss.deployers.plugins.main.MainDeployerImpl;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.plugins.facade.bundle.AbstractBundleState;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
@@ -125,8 +126,8 @@
protected void undeployBundles()
{
OSGiBundleManager bundleManager = getBundleManager();
- Collection<OSGiBundleState> bundles = bundleManager.getBundles();
- for (OSGiBundleState bundleState : bundles)
+ Collection<AbstractBundleState> bundles = bundleManager.getBundles();
+ for (AbstractBundleState bundleState : bundles)
{
try
{
16 years, 4 months
JBoss-OSGI SVN: r92838 - projects/jboss-osgi/projects/runtime/microcontainer/branches.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-26 11:26:13 -0400 (Wed, 26 Aug 2009)
New Revision: 92838
Added:
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/
Log:
recreate userbranch
Copied: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler (from rev 92837, projects/jboss-osgi/projects/runtime/microcontainer/trunk)
16 years, 4 months
JBoss-OSGI SVN: r92835 - projects/jboss-osgi/trunk/testsuite/trailblazer.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-26 10:10:30 -0400 (Wed, 26 Aug 2009)
New Revision: 92835
Modified:
projects/jboss-osgi/trunk/testsuite/trailblazer/.project
Log:
fix eclipse .project
Modified: projects/jboss-osgi/trunk/testsuite/trailblazer/.project
===================================================================
--- projects/jboss-osgi/trunk/testsuite/trailblazer/.project 2009-08-26 14:07:05 UTC (rev 92834)
+++ projects/jboss-osgi/trunk/testsuite/trailblazer/.project 2009-08-26 14:10:30 UTC (rev 92835)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>jboss-osgi-testsuite</name>
+ <name>jboss-osgi-testsuite-trailblazer</name>
<comment></comment>
<projects>
</projects>
16 years, 4 months
JBoss-OSGI SVN: r92834 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src: test/resources/bootstrap and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-26 10:07:05 -0400 (Wed, 26 Aug 2009)
New Revision: 92834
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
Log:
Add SPI packages to system
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java 2009-08-26 14:04:47 UTC (rev 92833)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java 2009-08-26 14:07:05 UTC (rev 92834)
@@ -419,7 +419,8 @@
throw new ClassNotFoundException("Cannot load class: " + name, e);
}
- return getDeploymentUnit().getClassLoader().loadClass(name);
+ ClassLoader classLoader = getDeploymentUnit().getClassLoader();
+ return classLoader.loadClass(name);
}
public URL getResource(String name)
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml 2009-08-26 14:04:47 UTC (rev 92833)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml 2009-08-26 14:07:05 UTC (rev 92834)
@@ -24,7 +24,11 @@
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
<property name="extraPackages">
<list elementClass="java.lang.String">
- <value>org.jboss.logging;version=[2.0,3.0)</value>
+ <value>org.jboss.logging;version=2.0</value>
+ <value>org.jboss.osgi.spi.logging;version=1.0</value>
+ <value>org.jboss.osgi.spi.management;version=1.0</value>
+ <value>org.jboss.osgi.spi.service;version=1.0</value>
+ <value>org.jboss.osgi.spi.util;version=1.0</value>
</list>
</property>
</bean>
16 years, 4 months
JBoss-OSGI SVN: r92833 - projects/jboss-osgi/projects/spi/trunk.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-26 10:04:47 -0400 (Wed, 26 Aug 2009)
New Revision: 92833
Modified:
projects/jboss-osgi/projects/spi/trunk/pom.xml
Log:
Update to jboss-vfs-2.1.2.GA
Modified: projects/jboss-osgi/projects/spi/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/pom.xml 2009-08-26 14:03:35 UTC (rev 92832)
+++ projects/jboss-osgi/projects/spi/trunk/pom.xml 2009-08-26 14:04:47 UTC (rev 92833)
@@ -33,7 +33,7 @@
<properties>
<version.args4j>2.0.12</version.args4j>
<version.jboss.logging>2.0.5.GA</version.jboss.logging>
- <version.jboss.vfs>2.1.0.GA</version.jboss.vfs>
+ <version.jboss.vfs>2.1.2.GA</version.jboss.vfs>
<version.osgi>r4v42-20090728</version.osgi>
</properties>
16 years, 4 months
JBoss-OSGI SVN: r92832 - projects/jboss-osgi/projects/bundles/microcontainer/trunk.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-26 10:03:35 -0400 (Wed, 26 Aug 2009)
New Revision: 92832
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml
Log:
Update to jboss-microcontainer-2.0.9-SNAPSHOT
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml 2009-08-26 14:02:02 UTC (rev 92831)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml 2009-08-26 14:03:35 UTC (rev 92832)
@@ -21,7 +21,7 @@
<artifactId>jboss-osgi-microcontainer</artifactId>
<packaging>bundle</packaging>
- <version>1.0.0</version>
+ <version>1.0.1-SNAPSHOT</version>
<!-- Parent -->
<parent>
@@ -33,9 +33,9 @@
<!-- Properties -->
<properties>
<version.jboss.deployers>2.0.5.SP1</version.jboss.deployers>
- <version.jboss.microcontainer>2.0.5.GA</version.jboss.microcontainer>
+ <version.jboss.microcontainer>2.0.9-SNAPSHOT</version.jboss.microcontainer>
<version.jboss.osgi.jmx>1.0.0</version.jboss.osgi.jmx>
- <version.jboss.osgi.runtime.deployers>1.0.0</version.jboss.osgi.runtime.deployers>
+ <version.jboss.osgi.runtime.deployers>1.0.1-SNAPSHOT</version.jboss.osgi.runtime.deployers>
<version.jboss.osgi.xml.binding>2.0.1</version.jboss.osgi.xml.binding>
<version.osgi>r4v41</version.osgi>
</properties>
@@ -53,7 +53,7 @@
<version>${version.jboss.osgi.xml.binding}</version>
</dependency>
<dependency>
- <groupId>org.jboss.osgi</groupId>
+ <groupId>org.jboss.osgi.runtime</groupId>
<artifactId>jboss-osgi-deployers</artifactId>
<version>${version.jboss.osgi.runtime.deployers}</version>
</dependency>
16 years, 4 months