summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-osgi/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-18 00:06:29 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-18 00:06:29 +0000
commit0271e8155a8afa2d31c6af759c13f9dfbb198751 (patch)
tree651d41fea56b50f09f5ae202569c4e6b1f47ac79 /java/sca/modules/implementation-osgi/src
parent57a1311b991c18e0b3a5b37c7cc9e45362a4776a (diff)
Change the name of OSGi remote service related properties
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@795280 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-osgi/src')
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java108
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java56
2 files changed, 138 insertions, 26 deletions
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java
index 26b588a099..455071dbb8 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java
@@ -28,20 +28,106 @@ public interface OSGiProperty {
String NAME = "name";
QName PROPERTY_QNAME = new QName(OSGiImplementation.SCA11_TUSCANY_NS, "osgi.property");
+ String SCA_BINDINGS = "sca.bindings";
+ String SCA_REFERENCE = "sca.reference";
+ String SCA_SERVICE = "sca.service";
+ String SCA_REFERENCE_BINDING = "sca.reference.binding";
+ String SCA_SERVICE_BINDING = "sca.service.binding";
+ String REMOTE_CONFIG_SCA = "sca";
+
/**
- * Standard OSGi property names
+ * The configuration types supported by this Distribution Provider. Services
+ * that are suitable for distribution list the configuration types that
+ * describe the configuration information for that service in the
+ * SERVICE_EXPORTED_CONFIGS or SERVICE_IMPORTED_CONFIGS property. A
+ * distribution provider must register a service that has this property and
+ * enumerate all configuration types that it supports. The type of this
+ * property String+
+ *
+ * @see SERVICE_EXPORTED_CONFIGS
+ * @see SERVICE_IMPORTED_CONFIGS
+ */
+ String REMOTE_CONFIGS_SUPPORTED = "remote.configs.supported";
+ /**
+ * Service property that lists the intents supported by the distribution
+ * provider. Each distribution provider must register a service that has
+ * this property and enumerate all the supported intents, having any
+ * qualified intents expanded. The value of this property is of type
+ * String+.
+ *
+ * @see SERVICE_INTENTS
+ * @see SERVICE_EXPORTED_INTENTS
+ * @see SERVICE_EXPORTED_INTENTS_EXTRA
+ */
+ String REMOTE_INTENTS_SUPPORTED = "remote.intents.supported";
+ /**
+ * A list of configuration types that should be used to export the service.
+ * Configuration types can be synonymous or alternatives. In principle, a
+ * distribution provider should create an endpoint for each recognized
+ * configuration type, the deployer is responsible that synonyms do not
+ * clash. Each configuration type has an associated specification that
+ * describes how the configuration data for the exported service is
+ * represented in an OSGi framework. The value of this property is of type
+ * String+.
+ */
+ String SERVICE_EXPORTED_CONFIGS = "service.exported.configs";
+ /**
+ * A list of intents that the distribution provider must implement to
+ * distribute the service. Intents listed in this property are reserved for
+ * intents that are critical for the code to function correctly, for
+ * example, ordering of messages. These intents should not be configurable.
+ * The value of this property is of type String+.
+ */
+ String SERVICE_EXPORTED_INTENTS = "service.exported.intents";
+ /**
+ * Extra intents configured in addition to the the intents specified in
+ * SERVICE_EXPORTED_INTENTS. These intents are merged with the service.
+ * exported.intents and therefore have the same semantics. They are extra,
+ * so that the SERVICE_EXPORTED_INTENTS can be set by the bundle developer
+ * and this property is then set by the administrator/deployer. Bundles
+ * should make this property configurable, for example through the
+ * Configuration Admin service. The value of this property is of type
+ * String+.
+ */
+ String SERVICE_EXPORTED_INTENTS_EXTRA = "service.exported.intents.extra";
+ /**
+ * Defines the interfaces under which this service can be exported. This
+ * list must be a subset of the types listed in the objectClass service
+ * property. The single value of an asterisk ('*' *) indicates all
+ * interfaces in the registration's objectClass property (not classes). It
+ * is highly recommended to only export interfaces and not concrete classes
+ * due to the complexity of creating proxies for some type of classes. The
+ * value of this property is of type String+.
+ */
+ String SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
+ /**
+ * Must be set by a distribution provider to true when it registers the
+ * end-point proxy as an imported service. Can be used by a bundle to
+ * prevent it from getting an imported service. The value of this property
+ * is not defined, setting it is sufficient.
+ */
+ String SERVICE_IMPORTED = "service.imported";
+ /**
+ * A list of intents that this service implements. This property has dual
+ * purpose. A bundle can use this service property to notify the
+ * distribution provider that these intents are already implemented by the
+ * exported service object. For an imported service, a distribution provider
+ * must use this property to convey the combined intents of the exporting
+ * service and the intents that the distribution providers add. To export a
+ * service, a distribution provider must recognize all these intents and
+ * expand any qualified intents. The value of this property is of type
+ * String+.
*/
- String OSGI_REMOTE = "osgi.remote";
String SERVICE_INTENTS = "service.intents";
- String OSGI_REMOTE_INTERFACES = "osgi.remote.interfaces";
- String OSGI_REMOTE_INTENTS = "osgi.remote.requires.intents";
- String OSGI_REMOTE_CONFIGURATION_TYPE = "osgi.remote.configuration.type";
- String SCA_BINDINGS = "osgi.remote.configuration.sca.bindings";
- String SCA_REFERENCE = "osgi.remote.configuration.sca.reference";
- String SCA_SERVICE = "osgi.remote.configuration.sca.service";
- String SCA_REFERENCE_BINDING = "osgi.remote.configuration.sca.reference.binding";
- String SCA_SERVICE_BINDING = "osgi.remote.configuration.sca.service.binding";
- String OSGI_REMOTE_CONFIGURATION_TYPE_SCA = "sca";
+ /**
+ * The configuration type used to import this services, as described in
+ * SERVICE_EXPORTED_CONFIGS. Any associated properties for this
+ * configuration types must be properly mapped to the importing system. For
+ * example, a URL in these properties must point to a valid resource when
+ * used in the importing framework. Configuration types in this property
+ * must be synonymous. The value of this property is of type String+.
+ */
+ String SERVICE_IMPORTED_CONFIGS = "service.imported.configs";
String getValue();
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java
index f6abf3b2b4..a997724ce0 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java
@@ -20,11 +20,12 @@
package org.apache.tuscany.sca.implementation.osgi.introspection;
import static org.apache.tuscany.sca.assembly.Base.SCA11_TUSCANY_NS;
-import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.OSGI_REMOTE_CONFIGURATION_TYPE;
-import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.OSGI_REMOTE_CONFIGURATION_TYPE_SCA;
-import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.OSGI_REMOTE_INTENTS;
-import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.OSGI_REMOTE_INTERFACES;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.REMOTE_CONFIG_SCA;
import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SCA_BINDINGS;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS_EXTRA;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTERFACES;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_IMPORTED_CONFIGS;
import static org.osgi.framework.Constants.OBJECTCLASS;
import static org.osgi.framework.Constants.SERVICE_ID;
@@ -34,6 +35,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
@@ -236,9 +238,9 @@ public class ExportedServiceIntrospector {
component.setImplementation(implementation);
implementation.setUnresolved(false);
- String[] remoteInterfaces = (String[])reference.getProperty(OSGI_REMOTE_INTERFACES);
+ String[] remoteInterfaces = getStrings(reference.getProperty(SERVICE_EXPORTED_INTERFACES));
if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
- remoteInterfaces = (String[])reference.getProperty(OBJECTCLASS);
+ remoteInterfaces = getStrings(reference.getProperty(OBJECTCLASS));
} else {
remoteInterfaces = parse(remoteInterfaces);
}
@@ -261,18 +263,22 @@ public class ExportedServiceIntrospector {
implementation.getServices().add(service);
ComponentService componentService = assemblyFactory.createComponentService();
+ componentService.setName(service.getName());
component.getServices().add(componentService);
componentService.setService(service);
}
- String[] requiredIntents = (String[])properties.get(OSGI_REMOTE_INTENTS);
+ String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
List<Intent> intents = getIntents(requiredIntents);
+ String[] requiredIntentsExtra = getStrings(properties.get(SERVICE_EXPORTED_INTENTS_EXTRA));
+ List<Intent> extraIntents = getIntents(requiredIntentsExtra);
- String[] bindingDocuments = (String[])properties.get(SCA_BINDINGS);
+ String[] bindingDocuments = getStrings(properties.get(SCA_BINDINGS));
List<Binding> bindings = loadBindings(reference.getBundle(), bindingDocuments);
for (ComponentService componentService : component.getServices()) {
componentService.getRequiredIntents().addAll(intents);
+ componentService.getRequiredIntents().addAll(extraIntents);
componentService.getBindings().addAll(bindings);
}
@@ -286,7 +292,7 @@ public class ExportedServiceIntrospector {
contribution.setUnresolved(true);
return contribution;
}
-
+
/**
* Introspect an OSGi filter to create an SCA reference
*
@@ -304,9 +310,10 @@ public class ExportedServiceIntrospector {
e.printStackTrace();
return null;
}
+
Dictionary<String, Object> props = new Hashtable<String, Object>();
- props.put(OSGI_REMOTE_CONFIGURATION_TYPE, OSGI_REMOTE_CONFIGURATION_TYPE_SCA);
- if(!filter.match(props)) {
+ props.put(SERVICE_IMPORTED_CONFIGS, new String[] {REMOTE_CONFIG_SCA});
+ if (!filter.match(props)) {
return null;
}
String id = "osgi.reference." + UUID.randomUUID();
@@ -325,9 +332,9 @@ public class ExportedServiceIntrospector {
component.setImplementation(implementation);
implementation.setUnresolved(false);
- String[] remoteInterfaces = (String[])properties.get(OSGiProperty.OSGI_REMOTE_INTERFACES);
+ String[] remoteInterfaces = getStrings(properties.get(SERVICE_EXPORTED_INTERFACES));
if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
- remoteInterfaces = (String[])properties.get(OBJECTCLASS);
+ remoteInterfaces = getStrings(properties.get(OBJECTCLASS));
} else {
remoteInterfaces = parse(remoteInterfaces);
}
@@ -355,10 +362,10 @@ public class ExportedServiceIntrospector {
componentReference.setWiredByImpl(true);
}
- String[] requiredIntents = (String[])properties.get(OSGI_REMOTE_INTENTS);
+ String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
List<Intent> intents = getIntents(requiredIntents);
- String[] bindingDocuments = (String[])properties.get(SCA_BINDINGS);
+ String[] bindingDocuments = getStrings(properties.get(SCA_BINDINGS));
List<Binding> bindings = loadBindings(bundle, bindingDocuments);
for (ComponentReference componentReference : component.getReferences()) {
@@ -419,4 +426,23 @@ public class ExportedServiceIntrospector {
return bundle.getEntry(location);
}
+ /**
+ * In OSGi, the value of String+ can be a single String, String[] or Collection<String>
+ * @param value
+ * @return
+ */
+ private String[] getStrings(Object value) {
+ if (value == null) {
+ return null;
+ }
+ if (value instanceof String) {
+ return new String[] {(String)value};
+ } else if (value instanceof Collection) {
+ Collection<String> collection = (Collection)value;
+ return collection.toArray(new String[collection.size()]);
+ }
+ return (String[])value;
+
+ }
+
}