summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-osgi
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-05-05 23:53:06 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-05-05 23:53:06 +0000
commit5a64d330e22e261d3d6fe62cf74a1f158f20608b (patch)
tree76fc2c5ff37d59f962185b6e38fa7373108901d5 /java/sca/modules/implementation-osgi
parent3e47841070daa13c07af89469f4dbecdd0686e2b (diff)
Allow the SCA composite for bundles can be packaged in an external bundle and leave the original bundles as is
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@772014 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-osgi')
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java47
1 files changed, 45 insertions, 2 deletions
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
index db99bf510e..547de99f50 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
@@ -24,6 +24,8 @@ import static org.apache.tuscany.sca.implementation.osgi.OSGiImplementation.BUND
import static org.apache.tuscany.sca.implementation.osgi.OSGiImplementation.BUNDLE_VERSION;
import static org.apache.tuscany.sca.implementation.osgi.OSGiImplementation.IMPLEMENTATION_OSGI;
+import java.net.URI;
+import java.net.URL;
import java.util.List;
import javax.xml.namespace.QName;
@@ -40,8 +42,11 @@ import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.contribution.resolver.ClassReference;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory;
@@ -71,13 +76,18 @@ import org.osgi.framework.Version;
* @version $Rev$ $Date$
*/
public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiImplementation> {
+ private static final String BUNDLE_COMPONENT_TYPE = "OSGI-INF/sca/bundle.componentType";
+ private static final String COMPONENT_TYPE_HEADER = "SCA-ComponentType";
+
private AssemblyFactory assemblyFactory;
private ServiceDescriptionsFactory serviceDescriptionsFactory;
private OSGiImplementationFactory osgiImplementationFactory;
private JavaInterfaceFactory javaInterfaceFactory;
private Monitor monitor;
+ private ExtensionPointRegistry registry;
+ private StAXArtifactProcessor artifactProcessor;
- public OSGiImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ protected OSGiImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
this.monitor = monitor;
this.serviceDescriptionsFactory = modelFactories.getFactory(ServiceDescriptionsFactory.class);
this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
@@ -85,6 +95,12 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm
this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
}
+ public OSGiImplementationProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor, Monitor monitor) {
+ this(registry.getExtensionPoint(FactoryExtensionPoint.class), monitor);
+ this.artifactProcessor = processor;
+ this.registry = registry;
+ }
+
/**
* Report a error.
*
@@ -172,6 +188,14 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm
return;
}
+ try {
+ if (introspect(impl, resolver, bundle)) {
+ return;
+ }
+ } catch (ContributionReadException e) {
+ throw new ContributionResolveException(e);
+ }
+
// The bundle may be different from the current contribution
ComponentType componentType = assemblyFactory.createComponentType();
// Try to find a bundle.componentType for the target bundle
@@ -183,7 +207,7 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm
// See org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver.resolveModel(Class<T>, T)
componentType = assemblyFactory.createComponentType();
// Try a generic one
- componentType.setURI("OSGI-INF/sca/bundle.componentType");
+ componentType.setURI(BUNDLE_COMPONENT_TYPE);
componentType = resolver.resolveModel(ComponentType.class, componentType);
}
if (componentType.isUnresolved()) {
@@ -293,4 +317,23 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm
writer.writeEndElement();
}
+ private boolean introspect(OSGiImplementation implementation, ModelResolver resolver, Bundle bundle)
+ throws ContributionReadException, ContributionResolveException {
+ String componentTypeFile = (String)bundle.getHeaders().get(COMPONENT_TYPE_HEADER);
+ if (componentTypeFile == null) {
+ componentTypeFile = BUNDLE_COMPONENT_TYPE;
+ }
+ URL url = bundle.getEntry(componentTypeFile);
+ if (url != null) {
+ URLArtifactProcessorExtensionPoint processors =
+ registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ URLArtifactProcessor<ComponentType> processor = processors.getProcessor(ComponentType.class);
+ ComponentType componentType = processor.read(null, URI.create(BUNDLE_COMPONENT_TYPE), url);
+ artifactProcessor.resolve(componentType, resolver);
+ mergeFromComponentType(implementation, componentType, resolver);
+ return true;
+ }
+ return false;
+ }
+
}