diff options
Diffstat (limited to '')
4 files changed, 292 insertions, 860 deletions
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java index afdfe90c3c..73e3dd540d 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java @@ -21,6 +21,7 @@ package org.apache.tuscany.sca; import java.io.Reader; import java.util.List; +import java.util.Map; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; @@ -48,32 +49,33 @@ public interface Node { * of the Assembly Specification. May be null. * @param dependentContributionURIs specifies the contributions that are used to resolve the dependencies of the * root contribution and other dependent contributions. May be null. - * @param startDeployables true if the composites defined as deployable in the contribution's sca-contribution.xml - * file or supplied metaData file should be started, false if they should not be. * @return the URI of the installed contribution * * @throws ContributionReadException * @throws ActivationException * @throws ValidationException */ - String installContribution(String uri, String contributionURL, String metaDataURL, List<String> dependentContributionURIs, boolean startDeployables) throws ContributionReadException, ActivationException, ValidationException; + String installContribution(String uri, String contributionURL, String metaDataURL, List<String> dependentContributionURIs) throws ContributionReadException, ActivationException, ValidationException; - /** - * Creates an installed contribution from a supplied Contribution object. - * See section 10.5.1 of the Assembly Specification. - * - * @param contribution the Contribution object - * @param dependentContributionURIs specifies the contributions that are used to resolve the dependencies of the - * root contribution and other dependent contributions. May be null. - * @param startDeployables true if the composites defined as deployable in the contribution's sca-contribution.xml - * file or supplied metaData file should be started, false if they should not be. - * @return the URI of the installed contribution - * - * @throws ContributionReadException - * @throws ActivationException - * @throws ValidationException - */ - String installContribution(Contribution contribution, List<String> dependentContributionURIs, boolean startDeployables) throws ContributionReadException, ActivationException, ValidationException; + void installContribution(Contribution contribution, List<String> dependentContributionURIs); + +// TODO: I'd still like this one but not in NodeImpl/registry yet +// /** +// * Creates an installed contribution from a supplied Contribution object. +// * See section 10.5.1 of the Assembly Specification. +// * +// * @param contribution the Contribution object +// * @param dependentContributionURIs specifies the contributions that are used to resolve the dependencies of the +// * root contribution and other dependent contributions. May be null. +// * @param startDeployables true if the composites defined as deployable in the contribution's sca-contribution.xml +// * file or supplied metaData file should be started, false if they should not be. +// * @return the URI of the installed contribution +// * +// * @throws ContributionReadException +// * @throws ActivationException +// * @throws ValidationException +// */ +// String installContribution(Contribution contribution, List<String> dependentContributionURIs, boolean startDeployables) throws ContributionReadException, ActivationException, ValidationException; /** * Creates an installed contribution from a supplied root contribution URL. @@ -111,7 +113,7 @@ public interface Node { * @throws ActivationException * @throws ValidationException */ - String start(String contributionURI, Reader compositeXML) throws ContributionReadException, XMLStreamException, ActivationException, ValidationException; + String addDeploymentComposite(String contributionURI, Reader compositeXML) throws ContributionReadException, XMLStreamException, ActivationException, ValidationException; /** * 4599 10.5.2 add Deployment Composite & update Deployment Composite @@ -135,7 +137,7 @@ public interface Node { * @throws ActivationException * @throws ValidationException */ - String start(String contributionURI, Composite composite) throws ActivationException, ValidationException; + String addDeploymentComposite(String contributionURI, Composite composite) throws ActivationException, ValidationException; /** * 4611 11.4.310.5.3 remove Contribution @@ -145,7 +147,7 @@ public interface Node { * @return List of contribution URIs (includes dependent contributions) which were removed * @throws ActivationException */ - List<String> removeContribution(String contributionURI) throws ActivationException; + void uninstallContribution(String contributionURI) throws ActivationException; /** * 4677 10.7.1 add To Domain-Level Composite @@ -164,7 +166,9 @@ public interface Node { * @throws ValidationException * @throws ContributionReadException */ - void start(String contributionURI, String compositeURI) throws ActivationException, ValidationException, ContributionReadException; + void startComposite(String contributionURI, String compositeURI) throws ActivationException, ValidationException, ContributionReadException; + + List<String> startDeployables(String contributionURI) throws ActivationException, ValidationException, ContributionReadException; /** * 4687 10.7.2 remove From Domain-Level Composite @@ -175,7 +179,7 @@ public interface Node { * @param compositeURI * @throws ActivationException */ - void stop(String contributionURI, String compositeURI) throws ActivationException; + void stopComposite(String contributionURI, String compositeURI) throws ActivationException; /** * 10.7.3 get Domain-Level Composite @@ -185,10 +189,7 @@ public interface Node { * * @return */ - Composite getDomainLevelComposite(); - - /* that previous one returns a Composte object but not sure what would be most appropriate, and having one return a string seems convenient: */ - String getDomainLevelCompositeAsString(); + Composite getDomainComposite(); /** * 4695 10.7.4 get QName Definition @@ -207,9 +208,9 @@ public interface Node { */ Object getQNameDefinition(String contributionURI, QName definition, QName symbolSpace); - /** - * Probably want to be able to stop it all at once so a method called stop or shutdown or destroy - */ +// /** +// * Probably want to be able to stop it all at once so a method called stop or shutdown or destroy +// */ void stop(); /** @@ -222,7 +223,8 @@ public interface Node { * @param contributionURI the contribution URI * @return the List of started composite URIs */ - List<String> getStartedCompositeURIs(String contributionURI); +// List<String> getStartedCompositeURIs(String contributionURI); + Map<String, List<QName>> getStartedComposites(); /** * Get the URIs of all the contributions installed on this Node @@ -234,8 +236,10 @@ public interface Node { * Get an installed Contribution * @param uri the URI of the contribution * @return the Contribution + * @throws ValidationException + * @throws ContributionReadException */ - Contribution getInstalledContribution(String uri); + Contribution getContribution(String uri) throws ContributionReadException, ValidationException; String getDomainName(); @@ -289,5 +293,9 @@ public interface Node { // */ // String updateDeploymentComposite(String uri, Reader compositeXML); // String updateDeploymentComposite(String uri, Composite composite); + + List<String> getDeployableCompositeURIs(String contributionURI); + + void validateContribution(String string) throws ContributionReadException, ValidationException; } diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java index 74e86e5421..149599b8fd 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java @@ -38,7 +38,6 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; import org.apache.tuscany.sca.deployment.Deployer; import org.apache.tuscany.sca.impl.NodeImpl; -import org.apache.tuscany.sca.impl.NodeImpl2; import org.apache.tuscany.sca.monitor.ValidationException; import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; @@ -103,19 +102,23 @@ public class TuscanyRuntime { public static Node runComposite(URI domainURI, String compositeURI, String contributionURL, String... dependentContributionURLs) { try { TuscanyRuntime runtime = newInstance(); - String domain = domainURI == null ? "default" : domainURI.toString(); + String domain = domainURI == null ? "default" : domainURI.toString(); DomainRegistry domainRegistry = runtime.domainRegistryFactory.getEndpointRegistry(domain, getDomainName(domain)); NodeImpl node = new NodeImpl(domain, runtime.deployer, runtime.compositeActivator, domainRegistry, runtime.extensionPointRegistry, runtime); if (dependentContributionURLs != null) { for (int i=dependentContributionURLs.length-1; i>-1; i--) { - node.installContribution(null, dependentContributionURLs[i], null, null, false); + node.installContribution(null, dependentContributionURLs[i], null, null); } } - String curi = node.installContribution(null, contributionURL, null, null, compositeURI == null); + String curi = node.installContribution(null, contributionURL, null, null); if (compositeURI != null) { - node.start(curi, compositeURI); + node.startComposite(curi, compositeURI); + } else { + for (String compURI : node.getDeployableCompositeURIs(curi)) { + node.startComposite(curi, compURI); + } } return node; @@ -150,15 +153,6 @@ public class TuscanyRuntime { return new NodeImpl(domainName, deployer, compositeActivator, domainRegistry, extensionPointRegistry, null); } - public NodeImpl2 createNode2(String domainURI) { - String domainName = "default"; - if (domainURI != null){ - domainName = getDomainName(domainURI); - } - DomainRegistry domainRegistry = domainRegistryFactory.getEndpointRegistry(domainURI, domainName); - return new NodeImpl2(domainName, deployer, compositeActivator, domainRegistry, extensionPointRegistry, null); - } - /** * Creates a Node from an XML configuration file * @param configURL the URL to the XML configuration file @@ -166,9 +160,14 @@ public class TuscanyRuntime { */ public Node createNodeFromXML(String configURL) throws ContributionReadException, ActivationException, ValidationException { NodeConfiguration configuration = loadConfiguration(configURL); - Node node = createNode(configuration.getDomainURI()); + NodeImpl node = (NodeImpl)createNode(configuration.getDomainURI()); for ( ContributionConfiguration c : configuration.getContributions()) { - node.installContribution(c.getURI(), c.getLocation(), c.getMetaDataURL(), c.getDependentContributionURIs(), c.isStartDeployables()); + String curi = node.installContribution(c.getURI(), c.getLocation(), c.getMetaDataURL(), c.getDependentContributionURIs()); + if (c.isStartDeployables()) { + for (String compURI : node.getDeployableCompositeURIs(curi)) { + node.startComposite(curi, compURI); + } + } } return node; } diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java index a8b7cac8f3..bc5a1961ec 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java @@ -19,63 +19,41 @@ package org.apache.tuscany.sca.impl; -import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.Reader; +import java.io.StringReader; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import javax.xml.namespace.QName; -import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.Node; import org.apache.tuscany.sca.TuscanyRuntime; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Base; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.assembly.Multiplicity; -import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.xml.Utils; import org.apache.tuscany.sca.common.java.io.IOHelper; -import org.apache.tuscany.sca.context.CompositeContext; -import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.ContributionMetadata; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; import org.apache.tuscany.sca.deployment.Deployer; -import org.apache.tuscany.sca.interfacedef.Interface; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; -import org.apache.tuscany.sca.interfacedef.java.JavaInterface; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.ValidationException; import org.apache.tuscany.sca.runtime.ActivationException; import org.apache.tuscany.sca.runtime.CompositeActivator; +import org.apache.tuscany.sca.runtime.ContributionListener; import org.apache.tuscany.sca.runtime.DomainRegistry; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; -import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; +import org.apache.tuscany.sca.runtime.InstalledContribution; import org.oasisopen.sca.NoSuchServiceException; -import org.oasisopen.sca.ServiceRuntimeException; public class NodeImpl implements Node { @@ -85,179 +63,204 @@ public class NodeImpl implements Node { private DomainRegistry domainRegistry; private ExtensionPointRegistry extensionPointRegistry; private TuscanyRuntime tuscanyRuntime; - private Map<String, InstalledContribution> locallyInstalledContributions = new HashMap<String, InstalledContribution>(); - public NodeImpl(String domainName, Deployer deployer, CompositeActivator compositeActivator, DomainRegistry domainRegistry, ExtensionPointRegistry extensionPointRegistry, TuscanyRuntime tuscanyRuntime) { + private Map<String, Contribution> loadedContributions = new ConcurrentHashMap<String, Contribution>(); + + private Map<String, DeployedComposite> startedComposites = new HashMap<String, DeployedComposite>(); + private Map<String, DeployedComposite> stoppedComposites = new HashMap<String, DeployedComposite>(); + + public NodeImpl(String domainName, + Deployer deployer, + CompositeActivator compositeActivator, + DomainRegistry domainRegistry, + ExtensionPointRegistry extensionPointRegistry, + TuscanyRuntime tuscanyRuntime) { this.domainName = domainName; this.deployer = deployer; this.compositeActivator = compositeActivator; this.domainRegistry = domainRegistry; this.extensionPointRegistry = extensionPointRegistry; this.tuscanyRuntime = tuscanyRuntime; + + domainRegistry.addContributionListener(new ContributionListener() { + public void contributionUpdated(String uri) { + loadedContributions.remove(uri); + } + public void contributionRemoved(String uri) { + loadedContributions.remove(uri); + } + }); } public String installContribution(String contributionURL) throws ContributionReadException, ActivationException, ValidationException { - return installContribution(null, contributionURL, null, null, true); + return installContribution(null, contributionURL, null, null); } - public String installContribution(String uri, String contributionURL, String metaDataURL, List<String> dependentContributionURIs, boolean startDeployables) throws ContributionReadException, ActivationException, ValidationException { - // TODO: sort out deployables and exports - org.apache.tuscany.sca.runtime.InstalledContribution ic = new org.apache.tuscany.sca.runtime.InstalledContribution(uri, contributionURL); + public String installContribution(String uri, String contributionURL) throws ContributionReadException, ActivationException, ValidationException { + return installContribution(uri, contributionURL, null, null); + } + + public String installContribution(String uri, String contributionURL, String metaDataURL, List<String> dependentContributionURIs) throws ContributionReadException, ActivationException, ValidationException { + InstalledContribution ic = new InstalledContribution(uri, contributionURL); + + if (dependentContributionURIs != null) { + ic.getDependentContributionURIs().addAll(dependentContributionURIs); + } + + if (metaDataURL != null) { + mergeContributionMetaData(metaDataURL, loadContribution(ic)); + } + peekIntoContribution(ic); + domainRegistry.installContribution(ic); - if (startDeployables) { - for (String compositeURI : ic.getDeployables()) { - start(ic.getURI(), compositeURI); - } - // TODO: sort out metadata and dependents in distributed - localInstall(ic.getURI(), contributionURL, metaDataURL, dependentContributionURIs, startDeployables); - } + return ic.getURI(); } - + + public void installContribution(Contribution contribution, List<String> dependentContributionURIs) { + InstalledContribution ic = new InstalledContribution(contribution.getURI(), contribution.getLocation()); + if (dependentContributionURIs != null) { + ic.getDependentContributionURIs().addAll(dependentContributionURIs); + } + ic.configureMetaData(contribution); + domainRegistry.installContribution(ic); + loadedContributions.put(ic.getURI(), contribution); + } + + public void uninstallContribution(String contributionURI) { + domainRegistry.uninstallContribution(contributionURI); + } + + protected void mergeContributionMetaData(String metaDataURL, Contribution contribution) throws ValidationException { + ContributionMetadata metaData; + Monitor monitor = deployer.createMonitor(); + try { + metaData = deployer.loadXMLDocument(IOHelper.getLocationAsURL(metaDataURL), monitor); + } catch (Exception e) { + throw new ValidationException(e); + } + monitor.analyzeProblems(); + contribution.mergeMetaData(metaData); + } + /** + * Peek into the contribution to find its attributes. * ASM12032 and ASM12033 say no error checking should be done during install and that should happen later, but - * we would still like to know about deployables and exports so peek into the contribution to try to get those, + * we need to know about deployables and exports so peek into the contribution to try to get those, * and just ignore any errors they might happen while doing that. */ - protected void peekIntoContribution(org.apache.tuscany.sca.runtime.InstalledContribution ic) { + protected void peekIntoContribution(InstalledContribution ic) { Contribution contribution = null; try { - contribution = deployer.loadContribution(IOHelper.createURI(ic.getURI()), IOHelper.getLocationAsURL(ic.getURI()), deployer.createMonitor()); + contribution = loadContribution(ic); } catch (Exception e) { - // ignore any errors + // ignore it } + if (contribution != null) { - for (Composite composite : contribution.getDeployables()) { - ic.getDeployables().add(composite.getURI()); - } - // TODO: need to sort out if Export or xml goes in the reg -// for (Export e : contribution.getExports()) { -// } + ic.configureMetaData(contribution); } } + + public List<String> getInstalledContributionURIs() { + return new ArrayList<String>(domainRegistry.getInstalledContributionURIs()); + } - private void localInstall(String uri, String contributionURL, String metaDataURL, List<String> dependentContributionURIs, boolean startDeployables) throws ContributionReadException, ValidationException, ActivationException { - Monitor monitor = deployer.createMonitor(); - Contribution contribution = deployer.loadContribution(IOHelper.createURI(uri), IOHelper.getLocationAsURL(contributionURL), monitor); - monitor.analyzeProblems(); - if (metaDataURL != null) { - mergeContributionMetaData(metaDataURL, contribution); - } - installContribution(contribution, dependentContributionURIs, startDeployables); + public Contribution getContribution(String contributionURI) throws ContributionReadException, ValidationException { + return loadContribution(getInstalledContribution(contributionURI)); } - private void mergeContributionMetaData(String metaDataURL, Contribution contribution) throws ValidationException { - ContributionMetadata metaData; - Monitor monitor = deployer.createMonitor(); - try { - metaData = deployer.loadXMLDocument(IOHelper.getLocationAsURL(metaDataURL), monitor); - } catch (Exception e) { - throw new ValidationException(e); - } - monitor.analyzeProblems(); - contribution.mergeMetaData(metaData); + public List<String> getDeployableCompositeURIs(String contributionURI) { + InstalledContribution ic = domainRegistry.getInstalledContribution(contributionURI); + return new ArrayList<String>(ic.getDeployables()); } - public String installContribution(Contribution contribution, List<String> dependentContributionURIs, boolean startDeployables) throws ContributionReadException, ActivationException, ValidationException { - InstalledContribution ic = new InstalledContribution(contribution.getURI(), contribution.getLocation(), contribution, dependentContributionURIs); - locallyInstalledContributions.put(contribution.getURI(), ic); - if (startDeployables) { - for (Composite c : ic.getDefaultDeployables()) { - startComposite(c, ic); - } - } else { - contribution.getDeployables().clear(); - - List<Contribution> dependentContributions = calculateDependentContributions(ic); + public String addDeploymentComposite(String contributionURI, Reader compositeXML) throws ContributionReadException, XMLStreamException, ValidationException { + InstalledContribution ic = getInstalledContribution(contributionURI); + + // load it to check its valid composite XML + Composite composite = deployer.loadXMLDocument(compositeXML); + + return addDeploymentComposite(ic, composite); + } - Monitor monitor = deployer.createMonitor(); - try { - deployer.resolve(contribution, dependentContributions, monitor); - } catch (Exception e) { - throw new RuntimeException(e); - } - monitor.analyzeProblems(); - } - return ic.getURI(); + public String addDeploymentComposite(String contributionURI, Composite composite) { + InstalledContribution ic = getInstalledContribution(contributionURI); + return addDeploymentComposite(ic, composite); } - protected List<Contribution> calculateDependentContributions(InstalledContribution ic) { - List<Contribution> dependentContributions = new ArrayList<Contribution>(); - if (ic.getDependentContributionURIs() != null) { - // if the install specified dependent uris use just those contributions - for (String uri : ic.getDependentContributionURIs()) { - InstalledContribution dependee = locallyInstalledContributions.get(uri); - if (dependee != null) { - dependentContributions.add(dependee.getContribution()); - } - } - } else { - // otherwise use all available contributions for dependents - for (InstalledContribution ics : locallyInstalledContributions.values()) { - dependentContributions.add(ics.getContribution()); - } + protected String addDeploymentComposite(InstalledContribution ic, Composite composite) { + if (composite.getURI() == null || composite.getURI().length() < 1) { + composite.setURI(composite.getName().getLocalPart() + ".composite"); } - return dependentContributions; + ic.getAdditionalDeployables().put(composite.getURI(), Utils.modelToXML(composite, false, extensionPointRegistry)); + domainRegistry.updateInstalledContribution(ic); + return composite.getURI(); } - public String start(String contributionURI, Reader compositeXML) throws ContributionReadException, XMLStreamException, ActivationException, ValidationException { - Monitor monitor = deployer.createMonitor(); - Composite composite = deployer.loadXMLDocument(compositeXML, monitor); - monitor.analyzeProblems(); - return start(contributionURI, composite); - } + public void validateContribution(String contributionURI) throws ContributionReadException, ValidationException { + InstalledContribution ic = getInstalledContribution(contributionURI); + Contribution contribution = loadContribution(ic); - public String start(String contributionURI, Composite composite) throws ActivationException, ValidationException { - InstalledContribution ic = locallyInstalledContributions.get(contributionURI); - if (ic == null) { - throw new IllegalArgumentException("contribution not installed: " + contributionURI); + Monitor monitor = deployer.createMonitor(); + try { + deployer.resolve(contribution, calculateDependentContributions(ic), monitor); + } catch (Exception e) { + loadedContributions.remove(ic.getURI()); + throw new RuntimeException(e); + } + try { + monitor.analyzeProblems(); + } catch (ValidationException e) { + loadedContributions.remove(ic.getURI()); + throw e; } - String compositeArtifcatURI = deployer.attachDeploymentComposite(ic.getContribution(), composite, true); - startComposite(composite, ic); - return compositeArtifcatURI; + } + + public Map<String, List<QName>> getStartedComposites() { + return domainRegistry.getRunningCompositeNames(); } - public void start(String contributionURI, String compositeURI) throws ActivationException, ValidationException, ContributionReadException { - InstalledContribution ic = locallyInstalledContributions.get(contributionURI); - if (ic == null) { - - org.apache.tuscany.sca.runtime.InstalledContribution icx = domainRegistry.getInstalledContribution(contributionURI); - String url = null; - if (icx != null) { - url = icx.getURL(); - } - if (url == null) { - throw new IllegalArgumentException("Contribution not installed: " + contributionURI); - } - localInstall(contributionURI, url, null, null, false); - ic = locallyInstalledContributions.get(contributionURI); + public void startComposite(String contributionURI, String compositeURI) throws ActivationException, ValidationException, ContributionReadException { + String key = contributionURI+"/"+compositeURI; + if (startedComposites.containsKey(key)) { + throw new IllegalStateException("composite already started: " + compositeURI); } - if (!ic.restart(compositeURI)) { - for (Artifact a : ic.getContribution().getArtifacts()) { - if (a.getURI().equals(compositeURI)) { - startComposite((Composite) a.getModel(), ic); - return; - } - } - throw new IllegalArgumentException("composite not found: " + compositeURI); + DeployedComposite dc = stoppedComposites.remove(key); + if (dc != null) { + dc.start(); + startedComposites.put(key, dc); + } else { + InstalledContribution ic = getInstalledContribution(contributionURI); + Contribution contribution = loadContribution(ic); + Composite composite = contribution.getArtifactModel(compositeURI); + List<Contribution> dependentContributions = calculateDependentContributions(ic); + dc = new DeployedComposite(composite, contribution, dependentContributions, deployer, compositeActivator, domainRegistry, extensionPointRegistry); + dc.start(); + startedComposites.put(key, dc); } } - - @Override - public void stop(String contributionURI, String compositeURI) throws ActivationException { - InstalledContribution ic = locallyInstalledContributions.get(contributionURI); - if (ic == null) { - throw new IllegalArgumentException("Contribution not installed: " + contributionURI); + + public void stopComposite(String contributionURI, String compositeURI) throws ActivationException { + String key = contributionURI+"/"+compositeURI; + DeployedComposite dc = startedComposites.remove(key); + if (dc == null) { + throw new IllegalStateException("composite not started: " + compositeURI); } - ic.stop(compositeURI); + dc.stop(); + stoppedComposites.put(key, dc); } - public Composite getDomainLevelComposite() { + public String getDomainName() { + return domainName; + } + + public Composite getDomainComposite() { FactoryExtensionPoint factories = extensionPointRegistry.getExtensionPoint(FactoryExtensionPoint.class); AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); Composite domainComposite = assemblyFactory.createComposite(); - domainComposite.setName(new QName(Base.SCA11_TUSCANY_NS, "domainComposite")); + domainComposite.setName(new QName(Base.SCA11_TUSCANY_NS, domainName)); domainComposite.setAutowire(false); domainComposite.setLocal(false); List<Composite> domainIncludes = domainComposite.getIncludes(); @@ -270,292 +273,113 @@ public class NodeImpl implements Node { return domainComposite; } - public String getDomainLevelCompositeAsString() { - StAXArtifactProcessorExtensionPoint xmlProcessors = extensionPointRegistry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - StAXArtifactProcessor<Composite> compositeProcessor = xmlProcessors.getProcessor(Composite.class); - XMLOutputFactory outputFactory = extensionPointRegistry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(XMLOutputFactory.class); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - try { - XMLStreamWriter sw = outputFactory.createXMLStreamWriter(bos); - compositeProcessor.write(getDomainLevelComposite(), sw, new ProcessorContext(extensionPointRegistry)); - sw.close(); - } catch(Exception e) { - throw new RuntimeException(e); - } - - return bos.toString(); - } - public Object getQNameDefinition(String contributionURI, QName definition, QName symbolSpace) { - // TODO Auto-generated method stub - return null; + public <T> T getService(Class<T> interfaze, String serviceURI) throws NoSuchServiceException { + return ServiceHelper.getService(interfaze, serviceURI, domainRegistry, extensionPointRegistry, deployer); } - - public List<String> removeContribution(String contributionURI) throws ActivationException { - domainRegistry.uninstallContribution(contributionURI); - - // TODO: should this next bit happen? - List<String> removedContributionURIs = new ArrayList<String>(); - InstalledContribution ic = locallyInstalledContributions.get(contributionURI); - if (ic != null) { - removedContributionURIs.add(ic.getURI()); - for (String dependent : getDependentContributions(contributionURI)) { - removedContributionURIs.addAll(removeContribution(dependent)); - } - locallyInstalledContributions.remove(contributionURI); - for (String compositeURI : ic.getStartedCompositeURIs()) { - ic.stop(compositeURI); - } + + protected InstalledContribution getInstalledContribution(String contributionURI) { + InstalledContribution ic = domainRegistry.getInstalledContribution(contributionURI); + if (ic == null) { + throw new IllegalArgumentException("Contribution not installed: " + contributionURI); } - return removedContributionURIs; + return ic; } - public void updateContribution(String uri, String contributionURL) { - // TODO Auto-generated method stub - // is this just removeContribution/installContribution? - } - public void updateContribution(Contribution contribution) { - // TODO Auto-generated method stub - } - - public String updateDeploymentComposite(String uri, Reader compositeXML) { - // TODO Auto-generated method stub - // is this removeFromDomainLevelComposite/addDeploymentComposite - return null; - } - public String updateDeploymentComposite(String uri, Composite composite) { - // TODO Auto-generated method stub - return null; - } - - public void stop() { - ArrayList<String> ics = new ArrayList<String>(locallyInstalledContributions.keySet()); - for (String uri : ics) { - try { - removeContribution(uri); - } catch (Exception e) { - // TODO: log - e.printStackTrace(); + protected Contribution loadContribution(InstalledContribution ic) throws ContributionReadException, ValidationException { + Contribution contribution = loadedContributions.get(ic.getURI()); + if (contribution == null) { + Monitor monitor = deployer.createMonitor(); + contribution = deployer.loadContribution(IOHelper.createURI(ic.getURI()), IOHelper.getLocationAsURL(ic.getURL()), monitor); + monitor.analyzeProblems(); + if (ic.getAdditionalDeployables().size() > 0) { + for (String uri : ic.getAdditionalDeployables().keySet()) { + String compositeXML = ic.getAdditionalDeployables().get(uri); + Composite composite; + try { + composite = deployer.loadXMLDocument(new StringReader(compositeXML)); + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } + composite.setURI(composite.getName().getLocalPart() + ".composite"); + contribution.addComposite(composite); + } } + loadedContributions.put(ic.getURI(), contribution); } - if (tuscanyRuntime != null) { - tuscanyRuntime.stop(); - } + return contribution; } - public <T> T getService(Class<T> interfaze, String serviceURI) throws NoSuchServiceException { - - List<Endpoint> endpoints = domainRegistry.findEndpoint(serviceURI); - if (endpoints.size() < 1) { - throw new NoSuchServiceException(serviceURI); - } - - String serviceName = null; - if (serviceURI.contains("/")) { - int i = serviceURI.indexOf("/"); - if (i < serviceURI.length() - 1) { - serviceName = serviceURI.substring(i + 1); + protected List<Contribution> calculateDependentContributions(InstalledContribution ic) throws ContributionReadException, ValidationException { + List<Contribution> dependentContributions = new ArrayList<Contribution>(); + if (ic.getDependentContributionURIs() != null && ic.getDependentContributionURIs().size() > 0) { + // if the install specified dependent uris use just those contributions + for (String uri : ic.getDependentContributionURIs()) { + InstalledContribution dependee = domainRegistry.getInstalledContribution(uri); + if (dependee != null) { + dependentContributions.add(loadContribution(dependee)); + } } - } - - Endpoint ep = endpoints.get(0); - if (((RuntimeComponent)ep.getComponent()).getComponentContext() != null) { - return ((RuntimeComponent)ep.getComponent()).getServiceReference(interfaze, serviceName).getService(); } else { - return getRemoteProxy(interfaze, ep); - } - } - - private <T> T getRemoteProxy(Class<T> serviceInterface, Endpoint endpoint) throws NoSuchServiceException { - FactoryExtensionPoint factories = extensionPointRegistry.getExtensionPoint(FactoryExtensionPoint.class); - AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); - JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class); - ProxyFactory proxyFactory = - new ExtensibleProxyFactory(extensionPointRegistry.getExtensionPoint(ProxyFactoryExtensionPoint.class)); - - CompositeContext compositeContext = - new CompositeContext(extensionPointRegistry, domainRegistry, null, null, null, - deployer.getSystemDefinitions()); - - RuntimeEndpointReference epr; - try { - epr = - createEndpointReference(javaInterfaceFactory, - compositeContext, - assemblyFactory, - endpoint, - serviceInterface); - } catch (Exception e) { - throw new ServiceRuntimeException(e); - } - - return proxyFactory.createProxy(serviceInterface, epr); - } - - private RuntimeEndpointReference createEndpointReference(JavaInterfaceFactory javaInterfaceFactory, - CompositeContext compositeContext, - AssemblyFactory assemblyFactory, - Endpoint endpoint, - Class<?> businessInterface) - throws CloneNotSupportedException, InvalidInterfaceException { - Component component = endpoint.getComponent(); - ComponentService service = endpoint.getService(); - ComponentReference componentReference = assemblyFactory.createComponentReference(); - componentReference.setName("sca.client." + service.getName()); - - componentReference.setCallback(service.getCallback()); - componentReference.getTargets().add(service); - componentReference.getPolicySets().addAll(service.getPolicySets()); - componentReference.getRequiredIntents().addAll(service.getRequiredIntents()); - componentReference.getBindings().add(endpoint.getBinding()); - - InterfaceContract interfaceContract = service.getInterfaceContract(); - Service componentTypeService = service.getService(); - if (componentTypeService != null && componentTypeService.getInterfaceContract() != null) { - interfaceContract = componentTypeService.getInterfaceContract(); - } - interfaceContract = getInterfaceContract(javaInterfaceFactory, interfaceContract, businessInterface); - componentReference.setInterfaceContract(interfaceContract); - componentReference.setMultiplicity(Multiplicity.ONE_ONE); - // component.getReferences().add(componentReference); - - // create endpoint reference - EndpointReference endpointReference = assemblyFactory.createEndpointReference(); - endpointReference.setComponent(component); - endpointReference.setReference(componentReference); - endpointReference.setBinding(endpoint.getBinding()); - endpointReference.setUnresolved(false); - endpointReference.setStatus(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED); - - endpointReference.setTargetEndpoint(endpoint); - - componentReference.getEndpointReferences().add(endpointReference); - ((RuntimeComponentReference)componentReference).setComponent((RuntimeComponent)component); - ((RuntimeEndpointReference)endpointReference).bind(compositeContext); - - return (RuntimeEndpointReference)endpointReference; - } - - private InterfaceContract getInterfaceContract(JavaInterfaceFactory javaInterfaceFactory, - InterfaceContract interfaceContract, - Class<?> businessInterface) throws CloneNotSupportedException, - InvalidInterfaceException { - if (businessInterface == null) { - return interfaceContract; - } - boolean compatible = false; - if (interfaceContract != null && interfaceContract.getInterface() != null) { - Interface interfaze = interfaceContract.getInterface(); - if (interfaze instanceof JavaInterface) { - Class<?> cls = ((JavaInterface)interfaze).getJavaClass(); - if (cls != null && businessInterface.isAssignableFrom(cls)) { - compatible = true; + for (Import imprt : loadContribution(ic).getImports()) { + for (InstalledContribution exportingIC : findExportingContributions(imprt)) { + dependentContributions.add(loadContribution(exportingIC)); } } } - - if (!compatible) { - // The interface is not assignable from the interface contract - interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); - JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(businessInterface); - interfaceContract.setInterface(callInterface); - if (callInterface.getCallbackClass() != null) { - interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(callInterface - .getCallbackClass())); - } - } - - return interfaceContract; - } - - public String getDomainName() { - return domainName; + // TODO: there is also the location attribute on the import which should be taken into account + return dependentContributions; } - public List<String> getStartedCompositeURIs(String contributionURI) { - InstalledContribution ic = locallyInstalledContributions.get(contributionURI); - if (ic == null) { - throw new IllegalArgumentException("no contribution found for: " + contributionURI); + private List<InstalledContribution> findExportingContributions(Import imprt) { + List<InstalledContribution> ics = new ArrayList<InstalledContribution>(); + // TODO: Handle Imports in a more extensible way + for (String curi : domainRegistry.getInstalledContributionURIs()) { + InstalledContribution ic = domainRegistry.getInstalledContribution(curi); + if (imprt instanceof JavaImport) { + for (String s : ic.getJavaExports()) { + if (s.startsWith(((JavaImport)imprt).getPackage())) { + ics.add(ic); + } + } + } else if (imprt instanceof NamespaceImport) { + if (ic.getNamespaceExports().contains(((NamespaceImport)imprt).getNamespace())) { + ics.add(ic); + } + } } - return ic.getStartedCompositeURIs(); + return ics; } - - public List<String> getInstalledContributionURIs() { - Set<String> ls = new HashSet<String>(domainRegistry.getInstalledContributionURIs()); - ls.addAll(locallyInstalledContributions.keySet()); - return new ArrayList<String>(ls); - } - - public Contribution getInstalledContribution(String uri) { - if (locallyInstalledContributions.containsKey(uri)) { - return locallyInstalledContributions.get(uri).getContribution(); - } - throw new IllegalArgumentException("no contribution found for: " + uri); + + @Override + public Object getQNameDefinition(String contributionURI, QName definition, QName symbolSpace) { + // TODO Auto-generated method stub + return null; } - protected String getContributionUriForArtifact(String artifactURI) { - String contributionURI = null; - for (String uri : locallyInstalledContributions.keySet()) { - if (artifactURI.startsWith(uri)) { - contributionURI = uri; - break; - } - } - if (contributionURI == null) { - throw new IllegalArgumentException("no contribution found for: " + artifactURI); + @Override + public List<String> startDeployables(String contributionURI) throws ActivationException, ValidationException, ContributionReadException { + List<String> dcURIs = getDeployableCompositeURIs(contributionURI); + for (String dcURI : dcURIs) { + startComposite(contributionURI, dcURI); } - return contributionURI; + return dcURIs; } - protected void startComposite(Composite c, InstalledContribution ic) throws ActivationException, ValidationException { - List<Contribution> dependentContributions = calculateDependentContributions(ic); - DeployedComposite dc = new DeployedComposite(c, ic.getContribution(), dependentContributions, deployer, compositeActivator, domainRegistry, extensionPointRegistry); - ic.start(dc); + // TODO: this is used by the shell to endpoint detail, should it be on the Node interface? + public DomainRegistry getEndpointRegistry() { + return domainRegistry; } - public Set<String> getDependentContributions(String contributionURI) { - InstalledContribution ic = locallyInstalledContributions.get(contributionURI); - if (ic == null) { - throw new IllegalArgumentException("Contribution not installed: " + contributionURI); - } - Set<String> dependentContributionURIs = new HashSet<String>(); - for (InstalledContribution icx : locallyInstalledContributions.values()) { - if (ic != icx) { - List<Contribution> dependencies = icx.getContribution().getDependencies(); - if (dependencies != null && dependencies.contains(ic.getContribution())) { - dependentContributionURIs.addAll(getDependentContributions(icx.getURI())); - } - } - } - return dependentContributionURIs; - } - - /** - * Returns a default URI for a contribution based on the contribution URL - */ - protected String getDefaultContributionURI(String contributionURL) { - String uri = null; - try { - File f = new File(contributionURL); - if ("classes".equals(f.getName()) && "target".equals(f.getParentFile().getName())) { - uri = f.getParentFile().getParentFile().getName(); - } else { - uri = f.getName(); + public void stop() { + for (DeployedComposite dc : startedComposites.values()) { + try { + dc.stop(); + } catch (ActivationException e) { } - } catch (Exception e) { - // ignore } - if (uri == null) { - uri = contributionURL; - } - if (uri.endsWith(".zip") || uri.endsWith(".jar")) { - uri = uri.substring(0, uri.length()-4); - } - return uri; + startedComposites.clear(); + startedComposites.clear(); + } - public DomainRegistry getEndpointRegistry() { - return domainRegistry; - } - } diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java deleted file mode 100644 index e133a3d671..0000000000 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java +++ /dev/null @@ -1,399 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tuscany.sca.impl;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-
-import org.apache.tuscany.sca.TuscanyRuntime;
-import org.apache.tuscany.sca.assembly.AssemblyFactory;
-import org.apache.tuscany.sca.assembly.Base;
-import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.common.java.io.IOHelper;
-import org.apache.tuscany.sca.common.xml.stax.StAXHelper;
-import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.contribution.ContributionMetadata;
-import org.apache.tuscany.sca.contribution.Export;
-import org.apache.tuscany.sca.contribution.Import;
-import org.apache.tuscany.sca.contribution.java.JavaExport;
-import org.apache.tuscany.sca.contribution.java.JavaImport;
-import org.apache.tuscany.sca.contribution.namespace.NamespaceExport;
-import org.apache.tuscany.sca.contribution.namespace.NamespaceImport;
-import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
-import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.deployment.Deployer;
-import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.ValidationException;
-import org.apache.tuscany.sca.runtime.ActivationException;
-import org.apache.tuscany.sca.runtime.CompositeActivator;
-import org.apache.tuscany.sca.runtime.ContributionListener;
-import org.apache.tuscany.sca.runtime.DomainRegistry;
-import org.apache.tuscany.sca.runtime.InstalledContribution;
-import org.oasisopen.sca.NoSuchServiceException;
-
-public class NodeImpl2 {
-
- private String domainName;
- private Deployer deployer;
- private CompositeActivator compositeActivator;
- private DomainRegistry domainRegistry;
- private ExtensionPointRegistry extensionPointRegistry;
- private TuscanyRuntime tuscanyRuntime;
-
- private Map<String, Contribution> loadedContributions = new ConcurrentHashMap<String, Contribution>();
-
- private Map<String, DeployedComposite> startedComposites = new HashMap<String, DeployedComposite>();
- private Map<String, DeployedComposite> stoppedComposites = new HashMap<String, DeployedComposite>();
-
- public NodeImpl2(String domainName,
- Deployer deployer,
- CompositeActivator compositeActivator,
- DomainRegistry domainRegistry,
- ExtensionPointRegistry extensionPointRegistry,
- TuscanyRuntime tuscanyRuntime) {
- this.domainName = domainName;
- this.deployer = deployer;
- this.compositeActivator = compositeActivator;
- this.domainRegistry = domainRegistry;
- this.extensionPointRegistry = extensionPointRegistry;
- this.tuscanyRuntime = tuscanyRuntime;
-
- domainRegistry.addContributionListener(new ContributionListener() {
- public void contributionUpdated(String uri) {
- loadedContributions.remove(uri);
- }
- public void contributionRemoved(String uri) {
- loadedContributions.remove(uri);
- }
- });
- }
-
- public String installContribution(String contributionURL) throws ContributionReadException, ActivationException, ValidationException {
- return installContribution(null, contributionURL, null, null);
- }
-
- public String installContribution(String uri, String contributionURL) throws ContributionReadException, ActivationException, ValidationException {
- return installContribution(uri, contributionURL, null, null);
- }
-
- public String installContribution(String uri, String contributionURL, String metaDataURL, List<String> dependentContributionURIs) throws ContributionReadException, ActivationException, ValidationException {
- InstalledContribution ic = new InstalledContribution(uri, contributionURL);
-
- if (dependentContributionURIs != null) {
- ic.getDependentContributionURIs().addAll(dependentContributionURIs);
- }
-
- if (metaDataURL != null) {
- mergeContributionMetaData(metaDataURL, loadContribution(ic));
- }
-
- peekIntoContribution(ic);
-
- domainRegistry.installContribution(ic);
-
- return ic.getURI();
- }
-
- public void uninstallContribution(String contributionURI) {
- domainRegistry.uninstallContribution(contributionURI);
- }
-
- protected void mergeContributionMetaData(String metaDataURL, Contribution contribution) throws ValidationException {
- ContributionMetadata metaData;
- Monitor monitor = deployer.createMonitor();
- try {
- metaData = deployer.loadXMLDocument(IOHelper.getLocationAsURL(metaDataURL), monitor);
- } catch (Exception e) {
- throw new ValidationException(e);
- }
- monitor.analyzeProblems();
- contribution.mergeMetaData(metaData);
- }
-
- /**
- * Peek into the contribution to find its attributes.
- * ASM12032 and ASM12033 say no error checking should be done during install and that should happen later, but
- * we need to know about deployables and exports so peek into the contribution to try to get those,
- * and just ignore any errors they might happen while doing that.
- */
- protected void peekIntoContribution(InstalledContribution ic) {
- Contribution contribution = null;
- try {
- contribution = loadContribution(ic);
- } catch (Exception e) {
- // ignore it
- }
-
- if (contribution != null) {
-
- // deployables
- if (contribution.getDeployables() != null) {
- for (Composite composite : contribution.getDeployables()) {
- ic.getDeployables().add(composite.getURI());
- }
- }
-
- // Exports
- if (contribution.getExports() != null) {
- for (Export export : contribution.getExports()) {
- // TODO: Handle these and others in a more extensible way
- if (export instanceof JavaExport) {
- ic.getJavaExports().add(((JavaExport)export).getPackage());
- } else if (export instanceof NamespaceExport) {
- ic.getNamespaceExports().add(((NamespaceExport)export).getNamespace());
- }
- }
- }
-
- // Imports
- if (contribution.getImports() != null) {
- for (Import imprt : contribution.getImports()) {
- // TODO: Handle these and others in a more extensible way
- if (imprt instanceof JavaImport) {
- ic.getJavaImports().add(((JavaImport)imprt).getPackage());
- } else if (imprt instanceof NamespaceImport) {
- ic.getNamespaceImports().add(((NamespaceImport)imprt).getNamespace());
- }
- }
- }
- }
- }
-
- public List<String> getInstalledContributionURIs() {
- return new ArrayList<String>(domainRegistry.getInstalledContributionURIs());
- }
-
- public Contribution getContribution(String contributionURI) throws ContributionReadException, ValidationException {
- return loadContribution(getInstalledContribution(contributionURI));
- }
-
- public List<String> getDeployableCompositeURIs(String contributionURI) {
- InstalledContribution ic = domainRegistry.getInstalledContribution(contributionURI);
- return new ArrayList<String>(ic.getDeployables());
- }
-
- public String addDeploymentComposite(String contributionURI, Reader compositeXML) throws ContributionReadException, XMLStreamException, ValidationException {
- InstalledContribution ic = getInstalledContribution(contributionURI);
-
- // load it to check its valid composite XML
- Composite composite = deployer.loadXMLDocument(compositeXML);
-
- return addDeploymentComposite(ic, composite);
- }
-
- public String addDeploymentComposite(String contributionURI, Composite composite) {
- InstalledContribution ic = getInstalledContribution(contributionURI);
- return addDeploymentComposite(ic, composite);
- }
-
- protected String addDeploymentComposite(InstalledContribution ic, Composite composite) {
- if (composite.getURI() == null || composite.getURI().length() < 1) {
- composite.setURI(composite.getName().getLocalPart() + ".composite");
- }
- ic.getAdditionalDeployables().put(composite.getURI(), compositeToXML(composite));
- domainRegistry.updateInstalledContribution(ic);
- return composite.getURI();
- }
-
- public void validateContribution(String contributionURI) throws ContributionReadException, ValidationException {
- InstalledContribution ic = getInstalledContribution(contributionURI);
- Contribution contribution = loadContribution(ic);
-
- Monitor monitor = deployer.createMonitor();
- try {
- deployer.resolve(contribution, calculateDependentContributions(ic), monitor);
- } catch (Exception e) {
- loadedContributions.remove(ic.getURI());
- throw new RuntimeException(e);
- }
- try {
- monitor.analyzeProblems();
- } catch (ValidationException e) {
- loadedContributions.remove(ic.getURI());
- throw e;
- }
- }
-
- public Map<String, List<QName>> getStartedComposites() {
- return domainRegistry.getRunningCompositeNames();
- }
-
- public void startComposite(String contributionURI, String compositeURI) throws ActivationException, ValidationException, ContributionReadException {
- String key = contributionURI+"/"+compositeURI;
- if (startedComposites.containsKey(key)) {
- throw new IllegalStateException("composite already started: " + compositeURI);
- }
- DeployedComposite dc = stoppedComposites.remove(key);
- if (dc != null) {
- dc.start();
- startedComposites.put(key, dc);
- } else {
- InstalledContribution ic = getInstalledContribution(contributionURI);
- Contribution contribution = loadContribution(ic);
- Composite composite = contribution.getArtifactModel(compositeURI);
- List<Contribution> dependentContributions = calculateDependentContributions(ic);
- dc = new DeployedComposite(composite, contribution, dependentContributions, deployer, compositeActivator, domainRegistry, extensionPointRegistry);
- dc.start();
- startedComposites.put(key, dc);
- }
- }
-
- public void stopComposite(String contributionURI, String compositeURI) throws ActivationException {
- String key = contributionURI+"/"+compositeURI;
- DeployedComposite dc = startedComposites.remove(key);
- if (dc == null) {
- throw new IllegalStateException("composite not started: " + compositeURI);
- }
- dc.stop();
- stoppedComposites.put(key, dc);
- }
-
- public String getDomainName() {
- return domainName;
- }
-
- public Composite getDomainComposite() {
- FactoryExtensionPoint factories = extensionPointRegistry.getExtensionPoint(FactoryExtensionPoint.class);
- AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class);
- Composite domainComposite = assemblyFactory.createComposite();
- domainComposite.setName(new QName(Base.SCA11_TUSCANY_NS, domainName));
- domainComposite.setAutowire(false);
- domainComposite.setLocal(false);
- List<Composite> domainIncludes = domainComposite.getIncludes();
- Map<String, List<QName>> runningComposites = domainRegistry.getRunningCompositeNames();
- for (String curi : runningComposites.keySet()) {
- for (QName name : runningComposites.get(curi)) {
- domainIncludes.add(domainRegistry.getRunningComposite(curi, name));
- }
- }
- return domainComposite;
- }
-
- public <T> T getService(Class<T> interfaze, String serviceURI) throws NoSuchServiceException {
- return ServiceHelper.getService(interfaze, serviceURI, domainRegistry, extensionPointRegistry, deployer);
- }
-
- protected InstalledContribution getInstalledContribution(String contributionURI) {
- InstalledContribution ic = domainRegistry.getInstalledContribution(contributionURI);
- if (ic == null) {
- throw new IllegalArgumentException("Contribution not installed: " + contributionURI);
- }
- return ic;
- }
-
- protected Contribution loadContribution(InstalledContribution ic) throws ContributionReadException, ValidationException {
- Contribution contribution = loadedContributions.get(ic.getURI());
- if (contribution == null) {
- Monitor monitor = deployer.createMonitor();
- contribution = deployer.loadContribution(IOHelper.createURI(ic.getURI()), IOHelper.getLocationAsURL(ic.getURL()), monitor);
- monitor.analyzeProblems();
- if (ic.getAdditionalDeployables().size() > 0) {
- for (String uri : ic.getAdditionalDeployables().keySet()) {
- String compositeXML = ic.getAdditionalDeployables().get(uri);
- Composite composite;
- try {
- composite = deployer.loadXMLDocument(new StringReader(compositeXML));
- } catch (XMLStreamException e) {
- throw new ContributionReadException(e);
- }
- composite.setURI(composite.getName().getLocalPart() + ".composite");
- contribution.addComposite(composite);
- }
- }
- loadedContributions.put(ic.getURI(), contribution);
- }
- return contribution;
- }
-
- protected List<Contribution> calculateDependentContributions(InstalledContribution ic) throws ContributionReadException, ValidationException {
- List<Contribution> dependentContributions = new ArrayList<Contribution>();
- if (ic.getDependentContributionURIs() != null && ic.getDependentContributionURIs().size() > 0) {
- // if the install specified dependent uris use just those contributions
- for (String uri : ic.getDependentContributionURIs()) {
- InstalledContribution dependee = domainRegistry.getInstalledContribution(uri);
- if (dependee != null) {
- dependentContributions.add(loadContribution(dependee));
- }
- }
- } else {
- for (Import imprt : loadContribution(ic).getImports()) {
- for (InstalledContribution exportingIC : findExportingContributions(imprt)) {
- dependentContributions.add(loadContribution(exportingIC));
- }
- }
- }
- // TODO: there is also the location attribute on the import which should be taken into account
- return dependentContributions;
- }
-
- private List<InstalledContribution> findExportingContributions(Import imprt) {
- List<InstalledContribution> ics = new ArrayList<InstalledContribution>();
- // TODO: Handle Imports in a more extensible way
- for (String curi : domainRegistry.getInstalledContributionURIs()) {
- InstalledContribution ic = domainRegistry.getInstalledContribution(curi);
- if (imprt instanceof JavaImport) {
- for (String s : ic.getJavaExports()) {
- if (s.startsWith(((JavaImport)imprt).getPackage())) {
- ics.add(ic);
- }
- }
- } else if (imprt instanceof NamespaceImport) {
- if (ic.getNamespaceExports().contains(((NamespaceImport)imprt).getNamespace())) {
- ics.add(ic);
- }
- }
- }
- return ics;
- }
-
- /**
- * TODO: this should be somewhere else, perhaps common-xml, and more general to work with any model object
- */
- protected String compositeToXML(Composite composite) {
- try {
- StAXHelper stAXHelper = StAXHelper.getInstance(extensionPointRegistry);
- StAXArtifactProcessorExtensionPoint staxProcessors = extensionPointRegistry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, null, stAXHelper.getOutputFactory());
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- staxProcessor.write(composite, bos, new ProcessorContext(extensionPointRegistry));
- bos.close();
- return bos.toString();
- } catch (ContributionWriteException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-}
|