[jboss-cvs] JBossAS SVN: r92961 - in projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi: testing and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 28 11:23:38 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-08-28 11:23:38 -0400 (Fri, 28 Aug 2009)
New Revision: 92961
Modified:
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/capability/Capability.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/capability/HttpCapability.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiRuntime.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java
Log:
Support service filter in Capability
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/capability/Capability.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/capability/Capability.java 2009-08-28 15:00:30 UTC (rev 92960)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/capability/Capability.java 2009-08-28 15:23:38 UTC (rev 92961)
@@ -24,22 +24,19 @@
//$Id$
import java.util.ArrayList;
-import java.util.LinkedHashSet;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
-import java.util.Properties;
-import java.util.Set;
+import java.util.Map;
import org.jboss.osgi.spi.testing.OSGiRuntime;
/**
- * An abstract OSGi capability that can be installed in an
- * {@link OSGiRuntime}.
+ * An abstract OSGi capability that can be installed in an {@link OSGiRuntime}.
*
- * The capability is only installed if the service name given in the constructor
- * is not already registered with the OSGi framework.
+ * The capability is only installed if the service name given in the constructor is not already registered with the OSGi framework.
*
- * It maintains an ordered set of dependent capabilities and bundles that
- * must be installed to provide the functionality advertised by this capability.
+ * It maintains an ordered set of dependent capabilities and bundles that must be installed to provide the functionality advertised by this capability.
*
* @author thomas.diesler at jboss.com
* @since 05-May-2009
@@ -47,19 +44,33 @@
public abstract class Capability
{
private String serviceName;
- private Properties props = new Properties();
-
- private Set<Capability> dependencies = new LinkedHashSet<Capability>();
- private Set<String> bundles = new LinkedHashSet<String>();
+ private String filter;
+ private Map<String, String> systemProperties;
+ private List<Capability> dependencies;
+ private List<String> bundles;
+
/**
- * Construct a capability that is identified by the given service name.
- * If the service name is already registered with the {@link OSGiRuntime}
- * adding this capability does nothing.
+ * Construct a capability that is identified by the given service name.
+ *
+ * If the service name is already registered with the {@link OSGiRuntime} adding this capability
+ * does nothing.
*/
public Capability(String serviceName)
{
+ this(serviceName, null);
+ }
+
+ /**
+ * Construct a capability that is identified by the given service name and filter string.
+ *
+ * If the service is already registered with the {@link OSGiRuntime} adding this capability
+ * does nothing.
+ */
+ public Capability(String serviceName, String filter)
+ {
this.serviceName = serviceName;
+ this.filter = filter;
}
/**
@@ -71,33 +82,80 @@
}
/**
- * Get system properties provided by this capability.
+ * Get the filter that is used for service lookup.
+ */
+ public String getFilter()
+ {
+ return filter;
+ }
+
+ /**
+ * Set the filter that is used for service lookup.
+ */
+ public void setFilter(String filter)
+ {
+ this.filter = filter;
+ }
+
+ /**
+ * Add a system property provided by this capability.
*
- * Adding this capability will set the associated system properties
- * if a propperty is not set already.
+ * Adding this capability will set the associated system properties if a propperty is not set already.
*/
- public Properties getProperties()
+ public void addSystemProperty(String key, String value)
{
- return props;
+ getPropertiesInternal().put(key, value);
}
+ /**
+ * Get the system properties for this capability.
+ */
+ public Map<String, String> getSystemProperties()
+ {
+ return Collections.unmodifiableMap(getPropertiesInternal());
+ }
+
public List<Capability> getDependencies()
{
- return new ArrayList<Capability>(dependencies);
+ return Collections.unmodifiableList(getDependenciesInternal());
}
-
+
+ protected void addDependency(Capability dependency)
+ {
+ getDependenciesInternal().add(dependency);
+ }
+
public List<String> getBundles()
{
- return new ArrayList<String>(bundles);
+ return Collections.unmodifiableList(getBundlesInternal());
}
protected void addBundle(String bundle)
{
- bundles.add(bundle);
+ getBundlesInternal().add(bundle);
}
- protected void addDependency(Capability dependency)
+ private Map<String, String> getPropertiesInternal()
{
- dependencies.add(dependency);
+ if (systemProperties == null)
+ systemProperties = new HashMap<String, String>();
+
+ return systemProperties;
}
+
+ private List<Capability> getDependenciesInternal()
+ {
+ if (dependencies == null)
+ dependencies = new ArrayList<Capability>();
+
+ return dependencies;
+ }
+
+ private List<String> getBundlesInternal()
+ {
+ if (bundles == null)
+ bundles = new ArrayList<String>();
+
+ return bundles;
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/capability/HttpCapability.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/capability/HttpCapability.java 2009-08-28 15:00:30 UTC (rev 92960)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/capability/HttpCapability.java 2009-08-28 15:23:38 UTC (rev 92961)
@@ -23,8 +23,6 @@
//$Id$
-import java.util.Properties;
-
import org.jboss.osgi.spi.testing.OSGiRuntime;
import org.osgi.service.http.HttpService;
@@ -51,9 +49,7 @@
public HttpCapability()
{
super(HttpService.class.getName());
-
- Properties props = getProperties();
- props.setProperty("org.osgi.service.http.port", "8090");
+ addSystemProperty("org.osgi.service.http.port", "8090");
addBundle("bundles/org.apache.felix.http.jetty.jar");
}
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiRuntime.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiRuntime.java 2009-08-28 15:00:30 UTC (rev 92960)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiRuntime.java 2009-08-28 15:23:38 UTC (rev 92961)
@@ -44,7 +44,7 @@
* Adding a capability recursively adds the orderded set of dependent capabilities
* before it installs and starts the orderded set bundles.
*/
- void addCapability(Capability capability) throws BundleException;
+ void addCapability(Capability capability) throws BundleException, InvalidSyntaxException;
/**
* Remove a {@link Capability} from the runtime.
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java 2009-08-28 15:00:30 UTC (rev 92960)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java 2009-08-28 15:23:38 UTC (rev 92961)
@@ -25,9 +25,9 @@
import java.net.URL;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.List;
-import java.util.Properties;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
@@ -125,16 +125,15 @@
}
@Override
- public void addCapability(Capability capability) throws BundleException
+ public void addCapability(Capability capability) throws BundleException, InvalidSyntaxException
{
// Copy the properties to the System props
- Properties props = capability.getProperties();
- Enumeration<?> names = props.propertyNames();
- while (names.hasMoreElements())
+ Map<String, String> props = capability.getSystemProperties();
+ for (Entry<String, String> entry : props.entrySet())
{
- String key = (String)names.nextElement();
- String value = props.getProperty(key);
- System.setProperty(key, value);
+ String value = System.getProperty(entry.getKey());
+ if (value == null)
+ System.setProperty(entry.getKey(), entry.getValue());
}
super.addCapability(capability);
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java 2009-08-28 15:00:30 UTC (rev 92960)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java 2009-08-28 15:23:38 UTC (rev 92961)
@@ -48,6 +48,7 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
/**
* An abstract implementation of the {@link OSGiRuntime}
@@ -74,15 +75,15 @@
return helper;
}
- public void addCapability(Capability capability) throws BundleException
+ public void addCapability(Capability capability) throws BundleException, InvalidSyntaxException
{
// Add dependent capabilies
for (Capability dependency : capability.getDependencies())
addCapability(dependency);
// Check if the service provided by the capability exists already
- OSGiServiceReference sref = getServiceReference(capability.getServiceName());
- if (sref == null)
+ OSGiServiceReference[] srefs = getServiceReferences(capability.getServiceName(), capability.getFilter());
+ if (srefs == null)
{
log.debug("Add capability: " + capability);
@@ -113,14 +114,14 @@
{
log.debug("Remove capability : " + capability);
- List<String> bundleLocations = capability.getBundles();
+ List<String> bundleLocations = new ArrayList<String>(capability.getBundles());
Collections.reverse(bundleLocations);
for (String location : bundleLocations)
failsafeUninstall(bundles.remove(location));
}
- List<Capability> dependencies = capability.getDependencies();
+ List<Capability> dependencies = new ArrayList<Capability>(capability.getDependencies());
Collections.reverse(dependencies);
// Remove dependent capabilities
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java 2009-08-28 15:00:30 UTC (rev 92960)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java 2009-08-28 15:23:38 UTC (rev 92961)
@@ -25,7 +25,6 @@
import java.net.URL;
import java.util.HashSet;
-import java.util.Properties;
import java.util.Set;
import javax.management.MBeanException;
@@ -34,7 +33,6 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
-import org.jboss.osgi.spi.capability.Capability;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
import org.jboss.osgi.spi.management.MBeanProxy;
import org.jboss.osgi.spi.management.MBeanProxyException;
@@ -293,23 +291,4 @@
ObjectName oname = new ObjectName("jboss.system:service=MainDeployer");
getMBeanServer().invoke(oname, method, new Object[] { archiveURL }, new String[] { "java.net.URL" });
}
-
- /**
- * A copy of the RemoteLogCapability from the
- * jboss-osgi-remotelog bundle, on which the SPI
- * should not have a dependency.
- */
- class RemoteLogCapability extends Capability
- {
- public RemoteLogCapability()
- {
- super("org.jboss.osgi.remotelog.RemoteLogService");
-
- Properties props = getProperties();
- props.setProperty("org.jboss.osgi.service.remote.log.reader", "true");
- props.setProperty("org.jboss.osgi.service.remote.log.host", System.getProperty("jboss.bind.address", "localhost"));
- props.setProperty("org.jboss.osgi.service.remote.log.port", "5400");
-
- addBundle("bundles/jboss-osgi-remotelog.jar");
- }
- }}
+}
More information about the jboss-cvs-commits
mailing list