[jboss-cvs] JBossAS SVN: r92532 - in projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src: main/java/org/jboss/osgi/jbossmc/framework and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 18 11:22:46 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-08-18 11:22:46 -0400 (Tue, 18 Aug 2009)
New Revision: 92532
Added:
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/SystemContextTestCase.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/resources/tst.policy
Modified:
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleEventManager.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/FrameworkEventManager.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceEventManager.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceRegistry.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleEventManagerImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleFactoryImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleRegistryImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleResolverImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkEventManagerImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceEventManagerImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceRegistryImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/SystemBundleContext.java
Log:
Basic event manager impl
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleEventManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleEventManager.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleEventManager.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -22,6 +22,7 @@
package org.jboss.osgi.jbossmc.api;
import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
//$Id: SystemBundleContext.java 91789 2009-07-29 20:49:03Z thomas.diesler at jboss.com $
@@ -34,4 +35,6 @@
public interface BundleEventManager
{
void fireBundleEvent(BundleEvent event);
+
+ void addBundleListener(BundleListener listener);
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/FrameworkEventManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/FrameworkEventManager.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/FrameworkEventManager.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -22,6 +22,7 @@
package org.jboss.osgi.jbossmc.api;
import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
//$Id: SystemBundleContext.java 91789 2009-07-29 20:49:03Z thomas.diesler at jboss.com $
@@ -34,4 +35,6 @@
public interface FrameworkEventManager
{
void fireFrameworkEvent(FrameworkEvent event);
+
+ void addFrameworkListener(FrameworkListener listener);
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceEventManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceEventManager.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceEventManager.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -22,6 +22,7 @@
package org.jboss.osgi.jbossmc.api;
import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
//$Id: SystemBundleContext.java 91789 2009-07-29 20:49:03Z thomas.diesler at jboss.com $
@@ -34,4 +35,6 @@
public interface ServiceEventManager
{
void fireServiceEvent(ServiceEvent event);
+
+ void addServiceListener(ServiceListener listener);
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceRegistry.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceRegistry.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceRegistry.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -26,6 +26,7 @@
import java.util.Dictionary;
import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
/**
@@ -39,4 +40,8 @@
ServiceRegistration registerService(Bundle bundle, String[] clazzes, Object service, Dictionary properties);
ServiceRegistration registerService(Bundle bundle, String clazz, Object service, Dictionary properties);
+
+ ServiceReference getServiceReference(String clazz);
+
+ ServiceReference[] getServiceReferences(String clazz, String filter);
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -28,6 +28,11 @@
import java.util.Dictionary;
import org.jboss.logging.Logger;
+import org.jboss.osgi.jbossmc.api.BundleEventManager;
+import org.jboss.osgi.jbossmc.api.BundleFactory;
+import org.jboss.osgi.jbossmc.api.BundleRegistry;
+import org.jboss.osgi.jbossmc.api.FrameworkEventManager;
+import org.jboss.osgi.jbossmc.api.ServiceEventManager;
import org.jboss.osgi.jbossmc.api.ServiceRegistry;
import org.jboss.osgi.spi.NotImplementedException;
import org.osgi.framework.Bundle;
@@ -36,6 +41,7 @@
import org.osgi.framework.BundleListener;
import org.osgi.framework.Filter;
import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
@@ -52,33 +58,36 @@
// Provide logging
final Logger log = Logger.getLogger(BundleContextImpl.class);
- private SystemBundleContext sysContext;
+ private FrameworkImpl framework;
private Bundle bundle;
- public BundleContextImpl(SystemBundleContext sysContext, Bundle bundle)
+ public BundleContextImpl(FrameworkImpl framework, Bundle bundle)
{
- this.sysContext = sysContext;
+ this.framework = framework;
this.bundle = bundle;
}
- SystemBundleContext getSystemContext()
+ public FrameworkImpl getFramework()
{
- return sysContext;
+ return framework;
}
-
+
public void addBundleListener(BundleListener listener)
{
- throw new NotImplementedException();
+ BundleEventManager eventManager = getFramework().getBundleEventManager();
+ eventManager.addBundleListener(listener);
}
public void addFrameworkListener(FrameworkListener listener)
{
- throw new NotImplementedException();
+ FrameworkEventManager eventManager = getFramework().getFrameworkEventManager();
+ eventManager.addFrameworkListener(listener);
}
public void addServiceListener(ServiceListener listener)
{
- throw new NotImplementedException();
+ ServiceEventManager eventManager = getFramework().getServiceEventManager();
+ eventManager.addServiceListener(listener);
}
public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException
@@ -88,7 +97,7 @@
public Filter createFilter(String filter) throws InvalidSyntaxException
{
- throw new NotImplementedException();
+ return FrameworkUtil.createFilter(filter);
}
public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException
@@ -118,7 +127,11 @@
public String getProperty(String key)
{
- throw new NotImplementedException();
+ String property = getFramework().getProperty(key);
+ if (property == null)
+ property = System.getProperty(key);
+
+ return property;
}
public Object getService(ServiceReference reference)
@@ -128,25 +141,25 @@
public ServiceReference getServiceReference(String clazz)
{
- // [TODO] getServiceReference
- return null;
+ ServiceRegistry serviceRegistry = getFramework().getServiceRegistry();
+ return serviceRegistry.getServiceReference(clazz);
}
public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
{
- // [TODO] getServiceReferences
- return null;
+ ServiceRegistry serviceRegistry = getFramework().getServiceRegistry();
+ return serviceRegistry.getServiceReferences(clazz, filter);
}
public Bundle installBundle(String location) throws BundleException
{
- SystemBundleContext sysContext = getSystemContext();
-
// Create the bundle from the location
- Bundle bundle = sysContext.getBundleFactory().createBundle(location);
+ BundleFactory bundleFactory = getFramework().getBundleFactory();
+ Bundle bundle = bundleFactory.createBundle(location);
// Register the bundle
- sysContext.getBundleRegistry().installBundle(bundle);
+ BundleRegistry bundleRegistry = getFramework().getBundleRegistry();
+ bundleRegistry.installBundle(bundle);
return bundle;
}
@@ -158,13 +171,13 @@
public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
{
- ServiceRegistry registry = getSystemContext().getServiceRegistry();
+ ServiceRegistry registry = getFramework().getServiceRegistry();
return registry.registerService(getBundle(), clazzes, service, properties);
}
public ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
{
- ServiceRegistry registry = getSystemContext().getServiceRegistry();
+ ServiceRegistry registry = getFramework().getServiceRegistry();
return registry.registerService(getBundle(), clazz, service, properties);
}
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleEventManagerImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleEventManagerImpl.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleEventManagerImpl.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -23,12 +23,13 @@
//$Id: SystemBundleContext.java 91789 2009-07-29 20:49:03Z thomas.diesler at jboss.com $
+import java.util.ArrayList;
+import java.util.List;
+
import org.jboss.logging.Logger;
import org.jboss.osgi.jbossmc.api.BundleEventManager;
-import org.jboss.osgi.jbossmc.api.BundleResolver;
-import org.jboss.osgi.spi.NotImplementedException;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
/**
* A simple implementation of a BundleEventManager
@@ -41,15 +42,24 @@
// Provide logging
final Logger log = Logger.getLogger(BundleEventManagerImpl.class);
- private SystemBundleContext sysContext;
+ private FrameworkImpl framework;
+ private List<BundleListener> listeners = new ArrayList<BundleListener>();
- public BundleEventManagerImpl(SystemBundleContext sysContext)
+ public BundleEventManagerImpl(FrameworkImpl framework)
{
- this.sysContext = sysContext;
+ this.framework = framework;
}
public void fireBundleEvent(BundleEvent event)
{
- // [TODO] fire bundle event
+ // [TODO] When a BundleEvent is fired, it is asynchronously delivered to a BundleListener
+
+ for (BundleListener listener : listeners)
+ listener.bundleChanged(event);
}
+
+ public void addBundleListener(BundleListener listener)
+ {
+ listeners.add(listener);
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleFactoryImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleFactoryImpl.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleFactoryImpl.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -43,11 +43,11 @@
// Provide logging
final Logger log = Logger.getLogger(BundleFactoryImpl.class);
- private SystemBundleContext sysContext;
+ private FrameworkImpl framework;
- public BundleFactoryImpl(SystemBundleContext sysContext)
+ public BundleFactoryImpl(FrameworkImpl framework)
{
- this.sysContext = sysContext;
+ this.framework = framework;
}
public Bundle createBundle(String location)
@@ -64,7 +64,7 @@
}
BundleImpl bundle = new BundleImpl(vfsRoot);
- bundle.setBundleContext(new BundleContextImpl(sysContext, bundle));
+ bundle.setBundleContext(new BundleContextImpl(framework, bundle));
return bundle;
}
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleImpl.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleImpl.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -153,7 +153,7 @@
// If this bundle's state is not RESOLVED, an attempt is made to resolve this bundle.
if (state != Bundle.RESOLVED)
{
- BundleResolver resolver = getSystemContext().getBundleResolver();
+ BundleResolver resolver = getFramework().getBundleResolver();
resolver.resolveBundle(this);
}
@@ -163,7 +163,7 @@
state = Bundle.STARTING;
// A bundle event of type BundleEvent.STARTING is fired.
- BundleEventManager eventManager = getSystemContext().getBundleEventManager();
+ BundleEventManager eventManager = getFramework().getBundleEventManager();
eventManager.fireBundleEvent(new BundleEvent(BundleEvent.STARTING, this));
// The BundleActivator is called
@@ -341,7 +341,7 @@
// before attempting to load the class.
if (state == Bundle.INSTALLED)
{
- BundleResolver resolver = getSystemContext().getBundleResolver();
+ BundleResolver resolver = getFramework().getBundleResolver();
try
{
resolver.resolveBundle(this);
@@ -349,7 +349,7 @@
catch (BundleException ex)
{
// If this bundle cannot be resolved, a Framework event of type FrameworkEvent.ERROR is fired
- FrameworkEventManager eventManager = getSystemContext().getFrameworkEventManager();
+ FrameworkEventManager eventManager = getFramework().getFrameworkEventManager();
eventManager.fireFrameworkEvent(new FrameworkEvent(FrameworkEvent.ERROR, this, ex));
throw new ClassNotFoundException("Cannot load class: " + name, ex);
@@ -364,8 +364,8 @@
return (String)getHeaders().get(header);
}
- private SystemBundleContext getSystemContext()
+ private FrameworkImpl getFramework()
{
- return context.getSystemContext();
+ return context.getFramework();
}
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleRegistryImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleRegistryImpl.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleRegistryImpl.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -41,12 +41,12 @@
final Logger log = Logger.getLogger(BundleRegistryImpl.class);
private long bundleId;
- private SystemBundleContext sysContext;
+ private FrameworkImpl framework;
private HashMap<String, Bundle> registry = new HashMap<String, Bundle>();
- public BundleRegistryImpl(SystemBundleContext sysContext)
+ public BundleRegistryImpl(FrameworkImpl framework)
{
- this.sysContext = sysContext;
+ this.framework = framework;
}
public long installBundle(Bundle bundle)
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleResolverImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleResolverImpl.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleResolverImpl.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -40,8 +40,11 @@
// Provide logging
final Logger log = Logger.getLogger(BundleResolverImpl.class);
- public BundleResolverImpl(SystemBundleContext sysContext)
+ private FrameworkImpl framework;
+
+ public BundleResolverImpl(FrameworkImpl framework)
{
+ this.framework = framework;
}
public void resolveBundle(Bundle bundle) throws BundleException
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkEventManagerImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkEventManagerImpl.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkEventManagerImpl.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -23,9 +23,13 @@
//$Id: SystemBundleContext.java 91789 2009-07-29 20:49:03Z thomas.diesler at jboss.com $
+import java.util.ArrayList;
+import java.util.List;
+
import org.jboss.logging.Logger;
import org.jboss.osgi.jbossmc.api.FrameworkEventManager;
import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
/**
* A simple implementation of a FrameworkEventManager
@@ -38,12 +42,24 @@
// Provide logging
final Logger log = Logger.getLogger(FrameworkEventManagerImpl.class);
- public FrameworkEventManagerImpl(SystemBundleContext sysContext)
+ private FrameworkImpl framework;
+ private List<FrameworkListener> listeners = new ArrayList<FrameworkListener>();
+
+ public FrameworkEventManagerImpl(FrameworkImpl framework)
{
+ this.framework = framework;
}
public void fireFrameworkEvent(FrameworkEvent event)
{
- // [TODO] fire framework event
+ // [TODO] When a FrameworkEvent is fired, it is asynchronously delivered to a FrameworkListener.
+
+ for (FrameworkListener listener : listeners)
+ listener.frameworkEvent(event);
}
+
+ public void addFrameworkListener(FrameworkListener listener)
+ {
+ listeners.add(listener);
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -25,10 +25,17 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.HashMap;
import java.util.Map;
import org.jboss.logging.Logger;
-import org.osgi.framework.BundleContext;
+import org.jboss.osgi.jbossmc.api.BundleEventManager;
+import org.jboss.osgi.jbossmc.api.BundleFactory;
+import org.jboss.osgi.jbossmc.api.BundleRegistry;
+import org.jboss.osgi.jbossmc.api.BundleResolver;
+import org.jboss.osgi.jbossmc.api.FrameworkEventManager;
+import org.jboss.osgi.jbossmc.api.ServiceEventManager;
+import org.jboss.osgi.jbossmc.api.ServiceRegistry;
import org.osgi.framework.BundleException;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.launch.Framework;
@@ -44,13 +51,21 @@
// Provide logging
final Logger log = Logger.getLogger(FrameworkImpl.class);
- private Map configuration;
- private SystemBundleContext sysContext;
+ private Map<String, String> properties = new HashMap<String, String>();
private int startLevel;
+
+ private BundleRegistry bundleRegistry;
+ private BundleFactory bundleFactory;
+ private BundleResolver bundleResolver;
+ private BundleEventManager bundleEventManager;
+ private FrameworkEventManager frameworkEventManager;
+ private ServiceEventManager serviceEventManager;
+ private ServiceRegistry serviceRegistry;
- public FrameworkImpl(Map configuration)
+ public FrameworkImpl(Map props)
{
- this.configuration = configuration;
+ if (props != null)
+ properties.putAll(props);
}
/**
@@ -87,12 +102,11 @@
this.startLevel = startLevel;
}
- @Override
- public BundleContext getBundleContext()
+ public String getProperty(String key)
{
- return sysContext;
+ return properties.get(key);
}
-
+
public void init() throws BundleException
{
initInternal();
@@ -177,7 +191,15 @@
setState(STARTING);
// Have a valid Bundle Context
- sysContext = new SystemBundleContext(this);
+ setBundleContext(new SystemBundleContext(this));
+
+ bundleFactory = new BundleFactoryImpl(this);
+ bundleResolver = new BundleResolverImpl(this);
+ bundleRegistry = new BundleRegistryImpl(this);
+ serviceRegistry = new ServiceRegistryImpl(this);
+ bundleEventManager = new BundleEventManagerImpl(this);
+ frameworkEventManager = new FrameworkEventManagerImpl(this);
+ serviceEventManager = new ServiceEventManagerImpl(this);
// Be at start level 0
setStartLevel(0);
@@ -234,4 +256,39 @@
// [TODO] A Framework Event indicating the reason this method returned
return new FrameworkEvent(FrameworkEvent.STOPPED, this, null);
}
+
+ public BundleFactory getBundleFactory()
+ {
+ return bundleFactory;
+ }
+
+ public BundleRegistry getBundleRegistry()
+ {
+ return bundleRegistry;
+ }
+
+ public BundleResolver getBundleResolver()
+ {
+ return bundleResolver;
+ }
+
+ public ServiceRegistry getServiceRegistry()
+ {
+ return serviceRegistry;
+ }
+
+ public BundleEventManager getBundleEventManager()
+ {
+ return bundleEventManager;
+ }
+
+ public ServiceEventManager getServiceEventManager()
+ {
+ return serviceEventManager;
+ }
+
+ public FrameworkEventManager getFrameworkEventManager()
+ {
+ return frameworkEventManager;
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceEventManagerImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceEventManagerImpl.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceEventManagerImpl.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -23,9 +23,13 @@
//$Id: SystemBundleContext.java 91789 2009-07-29 20:49:03Z thomas.diesler at jboss.com $
+import java.util.ArrayList;
+import java.util.List;
+
import org.jboss.logging.Logger;
import org.jboss.osgi.jbossmc.api.ServiceEventManager;
import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
/**
* A simple implementation of a BundleEventManager
@@ -38,15 +42,25 @@
// Provide logging
final Logger log = Logger.getLogger(ServiceEventManagerImpl.class);
- private SystemBundleContext sysContext;
+ private FrameworkImpl framework;
+ private List<ServiceListener> listeners = new ArrayList<ServiceListener>();
- public ServiceEventManagerImpl(SystemBundleContext sysContext)
+ public ServiceEventManagerImpl(FrameworkImpl framework)
{
- this.sysContext = sysContext;
+ this.framework = framework;
}
-
+
public void fireServiceEvent(ServiceEvent event)
{
- // [TODO] fire service event
+ // When a ServiceEvent is fired, it is synchronously delivered to a ServiceListener.
+ for (ServiceListener listener : listeners)
+ listener.serviceChanged(event);
+
+ // [TODO] ServiceEvent object delivery to ServiceListener objects is filtered
}
+
+ public void addServiceListener(ServiceListener listener)
+ {
+ listeners.add(listener);
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceRegistryImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceRegistryImpl.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceRegistryImpl.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -48,12 +48,12 @@
// Provide logging
final Logger log = Logger.getLogger(ServiceRegistryImpl.class);
- private SystemBundleContext sysContext;
private Map<String, ServiceReference> registry = new HashMap<String, ServiceReference>();
+ private FrameworkImpl framework;
- public ServiceRegistryImpl(SystemBundleContext sysContext)
+ public ServiceRegistryImpl(FrameworkImpl framework)
{
- this.sysContext = sysContext;
+ this.framework = framework;
}
public ServiceRegistration registerService(Bundle bundle, String clazz, Object service, Dictionary properties)
@@ -66,6 +66,20 @@
throw new NotImplementedException();
}
+ public ServiceReference getServiceReference(String clazz)
+ {
+ // [TODO] If multiple such services exist, the service with the highest ranking (as specified in its Constants.SERVICE_RANKING property) is returned.
+
+ // [TODO] If there is a tie in ranking, the service with the lowest service ID (as specified in its Constants.SERVICE_ID property); that is, the service that was registered first is returned.
+
+ return registry.get(clazz);
+ }
+
+ public ServiceReference[] getServiceReferences(String clazz, String filter)
+ {
+ throw new NotImplementedException();
+ }
+
private ServiceRegistration registerServiceInternal(Bundle bundle, String clazz, Object service, Dictionary properties)
{
// If service is not a ServiceFactory, an IllegalArgumentException is thrown if service
@@ -94,7 +108,7 @@
registry.put(clazz, serviceRef);
// 4. A service event of type ServiceEvent.REGISTERED is fired.
- ServiceEventManager eventManager = sysContext.getServiceEventManager();
+ ServiceEventManager eventManager = framework.getServiceEventManager();
eventManager.fireServiceEvent(new ServiceEvent(ServiceEvent.REGISTERED, serviceRef));
// 5. A ServiceRegistration object for this registration is returned.
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/SystemBundleContext.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/SystemBundleContext.java 2009-08-18 14:23:55 UTC (rev 92531)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/SystemBundleContext.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -24,14 +24,6 @@
//$Id$
import org.jboss.logging.Logger;
-import org.jboss.osgi.jbossmc.api.BundleEventManager;
-import org.jboss.osgi.jbossmc.api.BundleFactory;
-import org.jboss.osgi.jbossmc.api.BundleRegistry;
-import org.jboss.osgi.jbossmc.api.BundleResolver;
-import org.jboss.osgi.jbossmc.api.FrameworkEventManager;
-import org.jboss.osgi.jbossmc.api.ServiceEventManager;
-import org.jboss.osgi.jbossmc.api.ServiceRegistry;
-import org.osgi.framework.launch.Framework;
/**
* An implementation of the OSGi system BundleContext
@@ -44,65 +36,8 @@
// Provide logging
final Logger log = Logger.getLogger(SystemBundleContext.class);
- private BundleRegistry bundleRegistry;
- private BundleFactory bundleFactory;
- private BundleResolver bundleResolver;
- private BundleEventManager bundleEventManager;
- private FrameworkEventManager frameworkEventManager;
- private ServiceEventManager serviceEventManager;
- private ServiceRegistry serviceRegistry;
-
- public SystemBundleContext(Framework framework)
+ public SystemBundleContext(FrameworkImpl framework)
{
- super(null, framework);
-
- bundleFactory = new BundleFactoryImpl(this);
- bundleResolver = new BundleResolverImpl(this);
- bundleRegistry = new BundleRegistryImpl(this);
- serviceRegistry = new ServiceRegistryImpl(this);
- bundleEventManager = new BundleEventManagerImpl(this);
- frameworkEventManager = new FrameworkEventManagerImpl(this);
- serviceEventManager = new ServiceEventManagerImpl(this);
+ super(framework, framework);
}
-
- @Override
- SystemBundleContext getSystemContext()
- {
- return this;
- }
-
- public BundleFactory getBundleFactory()
- {
- return bundleFactory;
- }
-
- public BundleRegistry getBundleRegistry()
- {
- return bundleRegistry;
- }
-
- public BundleResolver getBundleResolver()
- {
- return bundleResolver;
- }
-
- public ServiceRegistry getServiceRegistry()
- {
- return serviceRegistry;
- }
-
- public BundleEventManager getBundleEventManager()
- {
- return bundleEventManager;
- }
-
- public ServiceEventManager getServiceEventManager()
- {
- return serviceEventManager;
- }
-
- public FrameworkEventManager getFrameworkEventManager()
- {
- return frameworkEventManager;
- }
}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/SystemContextTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/SystemContextTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/SystemContextTestCase.java 2009-08-18 15:22:46 UTC (rev 92532)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.jbossmc;
+
+//$Id: FrameworkLaunchTestCase.java 91789 2009-07-29 20:49:03Z thomas.diesler at jboss.com $
+
+import static org.junit.Assert.assertNotNull;
+
+import org.jboss.osgi.spi.util.ServiceLoader;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+/**
+ * Test OSGi System bundle context
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 27-Jul-2009
+ */
+public class SystemContextTestCase
+{
+ private static Framework framework;
+ private static BundleContext context;
+
+ @BeforeClass
+ public static void beforeClass() throws BundleException
+ {
+ FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
+ framework = factory.newFramework(null);
+ framework.start();
+
+ context = framework.getBundleContext();
+ assertNotNull("System context not null", context);
+ }
+
+ @AfterClass
+ public static void afterClass() throws BundleException
+ {
+ framework.stop();
+ }
+
+ @Test
+ public void testCreateFilter() throws InvalidSyntaxException
+ {
+ Filter filter = context.createFilter("(foo=bar)");
+ assertNotNull("Filter not null", filter);
+ }
+}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/resources/tst.policy
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/resources/tst.policy (rev 0)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/resources/tst.policy 2009-08-18 15:22:46 UTC (rev 92532)
@@ -0,0 +1,4 @@
+grant {
+ permission java.security.AllPermission;
+};
+
More information about the jboss-cvs-commits
mailing list