diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-21 23:13:50 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-21 23:13:50 +0000 |
commit | 5d7f85acd206a959e58ccba6d4b5687cd68b1942 (patch) | |
tree | d2f3ce62d062169a9e35b2d1626b0e60265f3e1f | |
parent | 11d80a409e2d7e65be7e46ca872d995d35964f83 (diff) |
Refactor the deployment-related code from NodeFactoryImpl into a Deployer utility
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@828248 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiNodeFactoryImpl.java | 4 | ||||
-rw-r--r-- | java/sca/modules/node-impl/META-INF/MANIFEST.MF | 31 | ||||
-rw-r--r-- | java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/deployment/Deployer.java | 189 | ||||
-rw-r--r-- | java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java | 540 | ||||
-rw-r--r-- | java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java | 410 | ||||
-rw-r--r-- | java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java | 8 | ||||
-rw-r--r-- | java/sca/modules/node-impl/src/main/resources/org/apache/tuscany/sca/node/impl/node-impl-validation-messages.properties (renamed from java/sca/modules/node-impl/src/main/resources/node-impl-validation-messages.properties) | 0 |
7 files changed, 807 insertions, 375 deletions
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiNodeFactoryImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiNodeFactoryImpl.java index 3a698eeb4b..42481c7e8e 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiNodeFactoryImpl.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiNodeFactoryImpl.java @@ -26,6 +26,7 @@ import java.util.Hashtable; import java.util.logging.Level; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.extensibility.equinox.OSGiExtensionPointRegistry; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory; @@ -56,6 +57,7 @@ public class OSGiNodeFactoryImpl extends NodeFactoryImpl { init(); // Create a node configuration + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); NodeConfigurationFactory configurationFactory = modelFactories.getFactory(NodeConfigurationFactory.class); NodeConfiguration configuration = configurationFactory.createNodeConfiguration(); @@ -86,7 +88,7 @@ public class OSGiNodeFactoryImpl extends NodeFactoryImpl { // Register the ExtensionPointRegistry as an OSGi service Dictionary<Object, Object> props = new Hashtable<Object, Object>(); registration = - bundleContext.registerService(ExtensionPointRegistry.class.getName(), extensionPoints, props); + bundleContext.registerService(ExtensionPointRegistry.class.getName(), registry, props); } } diff --git a/java/sca/modules/node-impl/META-INF/MANIFEST.MF b/java/sca/modules/node-impl/META-INF/MANIFEST.MF index 2094b9cdad..6e14e309ef 100644 --- a/java/sca/modules/node-impl/META-INF/MANIFEST.MF +++ b/java/sca/modules/node-impl/META-INF/MANIFEST.MF @@ -1,13 +1,25 @@ Manifest-Version: 1.0
-Export-Package: org.apache.tuscany.sca.node.impl;uses:="org.apache.tus
- cany.sca.runtime,org.apache.tuscany.sca.definitions,org.apache.tuscan
- y.sca.core,javax.xml.namespace,javax.xml.stream,org.apache.tuscany.sc
- a.core.assembly,org.apache.tuscany.sca.contribution.resolver,org.apac
- he.tuscany.sca.workspace,org.apache.tuscany.sca.core.invocation,org.o
- soa.sca,org.apache.tuscany.sca.assembly.builder,org.apache.tuscany.sc
- a.assembly,org.apache.tuscany.sca.node,org.apache.tusc any.sca.contri
- bution,org.apache.tuscany.sca.monitor,org.apache.tuscany.sca.work,org
- .apache.tuscany.sca.contribution.processor";version="2.0.0"
+Export-Package: org.apache.tuscany.sca.deployment;version="2.0.0";
+ uses:="javax.xml.stream,
+ org.apache.tuscany.sca.assembly,
+ org.apache.tuscany.sca.contribution.processor,
+ org.apache.tuscany.sca.core,
+ org.apache.tuscany.sca.contribution,
+ org.apache.tuscany.sca.monitor,
+ org.apache.tuscany.sca.assembly.builder",
+ org.apache.tuscany.sca.deployment.impl;version="2.0.0";
+ uses:="org.apache.tuscany.sca.assembly,
+ org.apache.tuscany.sca.definitions,
+ org.apache.tuscany.sca.common.xml.stax,
+ org.apache.tuscany.sca.core,
+ org.apache.tuscany.sca.contribution,
+ org.apache.tuscany.sca.deployment,
+ org.apache.tuscany.sca.monitor,
+ javax.xml.stream,
+ org.apache.tuscany.sca.contribution.resolver,
+ org.apache.tuscany.sca.contribution.processor,
+ org.apache.tuscany.sca.assembly.builder",
+ org.apache.tuscany.sca.node.impl;version="2.0.0"
Tool: Bnd-0.0.255
Bundle-Name: Apache Tuscany SCA Node Implementation
Created-By: 1.6.0_07 (Sun Microsystems Inc.)
@@ -34,6 +46,7 @@ Import-Package: javax.management;resolution:=optional, org.apache.tuscany.sca.definitions;version="2.0.0",
org.apache.tuscany.sca.definitions.util;version="2.0.0",
org.apache.tuscany.sca.definitions.xml;version="2.0.0",
+ org.apache.tuscany.sca.deployment;version="2.0.0",
org.apache.tuscany.sca.extensibility;version="2.0.0",
org.apache.tuscany.sca.management;version="2.0.0",
org.apache.tuscany.sca.monitor;version="2.0.0",
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/deployment/Deployer.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/deployment/Deployer.java new file mode 100644 index 0000000000..3d7b99612e --- /dev/null +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/deployment/Deployer.java @@ -0,0 +1,189 @@ +/* + * 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.deployment; + +import java.io.Reader; +import java.io.Writer; +import java.net.URI; +import java.net.URL; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +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.ProcessorContext; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.LifeCycleListener; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A utility that provides system functions to handle Tuscany SCA application deployment + */ +public interface Deployer extends LifeCycleListener { + /** + * Attach a deployment composite to the given contribution + * @param contribution The target contribution + * @param composite The deployment composite + * @param appending A flag to indicate if existing deployable composites in the contribution should be appended or replaced + */ + void attachDeploymentComposite(Contribution contribution, Composite composite, boolean appending); + + /** + * Configure a list of contributions to create a composite representing a view of the domain + * @param contributions + * @param bindingBaseURIs + * @param monitor + * @return + * @throws ContributionResolveException + * @throws CompositeBuilderException + */ + Composite build(List<Contribution> contributions, Map<QName, List<String>> bindingBaseURIs, Monitor monitor) + throws ContributionResolveException, CompositeBuilderException; + + /** + * Create an instance of {@link BuilderContext} + * @return + */ + BuilderContext createBuilderContext(); + + /** + * Create an instance of {@link ProcessorContext} + * @return + */ + ProcessorContext createProcessorContext(); + + /** + * Get the {@link ExtensionPointRegistry} + * @return + */ + ExtensionPointRegistry getExtensionPointRegistry(); + + /** + * Load an artifact from the given location + * @param uri + * @param location + * @param monitor + * @return + * @throws ContributionReadException + */ + Artifact loadArtifact(URI uri, URL location, Monitor monitor) throws ContributionReadException; + + /** + * Load a contribution from the given location + * @param uri + * @param location + * @param monitor + * @return + * @throws ContributionReadException + */ + Contribution loadContribution(URI uri, URL location, Monitor monitor) throws ContributionReadException; + + /** + * @param <T> + * @param uri + * @param location + * @param monitor + * @return + * @throws ContributionReadException + */ + <T> T loadDocument(URI uri, URL location, Monitor monitor) throws ContributionReadException; + + /** + * @param <T> + * @param reader + * @param monitor + * @return + * @throws XMLStreamException + * @throws ContributionReadException + */ + <T> T loadXMLDocument(Reader reader, Monitor monitor) throws XMLStreamException, ContributionReadException; + + /** + * @param <T> + * @param location + * @param monitor + * @return + * @throws XMLStreamException + * @throws ContributionReadException + */ + <T> T loadXMLDocument(URL location, Monitor monitor) throws XMLStreamException, ContributionReadException; + + /** + * @param <T> + * @param reader + * @param monitor + * @return + * @throws ContributionReadException + * @throws XMLStreamException + */ + <T> T loadXMLElement(XMLStreamReader reader, Monitor monitor) throws ContributionReadException, XMLStreamException; + + /** + * Save the model as XML + * @param model + * @param writer + * @param monitor + * @throws XMLStreamException + * @throws ContributionWriteException + */ + void saveXMLDocument(Object model, Writer writer, Monitor monitor) throws XMLStreamException, + ContributionWriteException; + + /** + * Save the model as XML + * @param model + * @param writer + * @param monitor + * @throws XMLStreamException + * @throws ContributionWriteException + */ + void saveXMLElement(Object model, XMLStreamWriter writer, Monitor monitor) throws XMLStreamException, + ContributionWriteException; + + /* + * @see org.apache.tuscany.sca.core.LifeCycleListener#start() + */ + void start(); + + /* + * @see org.apache.tuscany.sca.core.LifeCycleListener#stop() + */ + void stop(); + + /** + * @return + */ + boolean isSchemaValidationEnabled(); + /** + * @param schemaValidationEnabled + */ + void setSchemaValidationEnabled(boolean schemaValidationEnabled); +} diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java new file mode 100644 index 0000000000..5449230bc9 --- /dev/null +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java @@ -0,0 +1,540 @@ +/* + * 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.deployment.impl; + +import static java.lang.System.currentTimeMillis; + +import java.io.Reader; +import java.io.Writer; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +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.assembly.builder.BuilderContext; +import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.common.xml.stax.StAXHelper; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DefaultImport; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +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.ExtendedURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; +import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.DefaultImportModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.definitions.Definitions; +import org.apache.tuscany.sca.definitions.DefinitionsFactory; +import org.apache.tuscany.sca.definitions.util.DefinitionsUtil; +import org.apache.tuscany.sca.definitions.xml.DefinitionsExtensionPoint; +import org.apache.tuscany.sca.deployment.Deployer; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.node.impl.Contributions; +import org.apache.tuscany.sca.node.impl.NodeImpl; + +/** + * + */ +public class DeployerImpl implements Deployer { + protected static final Logger logger = Logger.getLogger(NodeImpl.class.getName()); + + protected boolean inited; + protected boolean schemaValidationEnabled; + protected StAXHelper staxHelper; + protected AssemblyFactory assemblyFactory; + protected CompositeBuilder compositeBuilder; + protected ContributionFactory contributionFactory; + protected ExtendedURLArtifactProcessor<Contribution> contributionProcessor; + protected ExtensionPointRegistry registry; + protected FactoryExtensionPoint modelFactories; + protected ModelResolverExtensionPoint modelResolvers; + protected Contribution systemContribution; + protected Definitions systemDefinitions; + protected ExtensibleURLArtifactProcessor artifactProcessor; + protected ExtensibleStAXArtifactProcessor staxProcessor; + + protected MonitorFactory monitorFactory; + + protected static final String NODE_IMPL_VALIDATION_MESSAGES = + "org.apache.tuscany.sca.node.impl.node-impl-validation-messages"; + + /** + * @param registry + */ + public DeployerImpl(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + public synchronized void stop() { + if (inited) { + staxHelper = null; + assemblyFactory = null; + compositeBuilder = null; + contributionFactory = null; + contributionProcessor = null; + modelFactories = null; + modelResolvers = null; + systemContribution = null; + systemDefinitions = null; + artifactProcessor = null; + staxProcessor = null; + monitorFactory = null; + inited = false; + } + } + + /** + * Analyze a contribution and add its dependencies to the given dependency set. + */ + protected void addContributionDependencies(Contribution contribution, + List<Contribution> contributions, + List<Contribution> dependencies, + Set<Contribution> set, + Monitor monitor) { + + // Go through the contribution imports + for (Import import_ : contribution.getImports()) { + boolean resolved = false; + + // Go through all contribution candidates and their exports + List<Export> matchingExports = new ArrayList<Export>(); + for (Contribution dependency : contributions) { + if (dependency == contribution) { + // Do not self import + continue; + } + for (Export export : dependency.getExports()) { + + // If an export from a contribution matches the import in hand + // add that contribution to the dependency set + if (import_.match(export)) { + resolved = true; + matchingExports.add(export); + + if (!set.contains(dependency)) { + set.add(dependency); + dependencies.add(dependency); + + // Now add the dependencies of that contribution + addContributionDependencies(dependency, contributions, dependencies, set, monitor); + } // end if + } // end if + } // end for + } // end for + + if (resolved) { + // Initialize the import's model resolver with a delegating model + // resolver which will delegate to the matching exports + import_.setModelResolver(new DefaultImportModelResolver(matchingExports)); + + } else { + // Record import resolution issue + if (!(import_ instanceof DefaultImport)) { + // Add the (empty) matchingExports List and report a warning + import_.setModelResolver(new DefaultImportModelResolver(matchingExports)); + Monitor.error(monitor, this, NODE_IMPL_VALIDATION_MESSAGES, "UnresolvedImport", import_); + } + } // end if + } + } + + protected void buildDependencies(Contribution contribution, List<Contribution> contributions, Monitor monitor) { + contribution.getDependencies().clear(); + + List<Contribution> dependencies = new ArrayList<Contribution>(); + Set<Contribution> set = new HashSet<Contribution>(); + + dependencies.add(contribution); + set.add(contribution); + addContributionDependencies(contribution, contributions, dependencies, set, monitor); + + Collections.reverse(dependencies); + + contribution.getDependencies().addAll(dependencies); + } + + /** + * Pre-resolve phase for contributions, to set up handling of imports and exports prior to full resolution + * @param contributions - the contributions to preresolve + * @param resolver - the ModelResolver to use + * @throws ContributionResolveException + */ + protected void contributionsPreresolve(List<Contribution> contributions, + ModelResolver resolver, + ProcessorContext context) throws ContributionResolveException { + + for (Contribution contribution : contributions) { + contributionProcessor.preResolve(contribution, resolver, context); + } // end for + } // end method contributionsPreresolve + + public ExtensionPointRegistry getExtensionPointRegistry() { + return registry; + } + + public synchronized void start() { + if (inited) { + return; + } + long start = currentTimeMillis(); + + // Enable schema validation only of the logger level is FINE or higher + if (isSchemaValidationEnabled()) { + ValidationSchemaExtensionPoint schemas = + registry.getExtensionPoint(ValidationSchemaExtensionPoint.class); + if (schemas != null) { + schemas.setEnabled(true); + } + } + + // Use the runtime-enabled assembly factory + modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + + // Create a monitor + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + staxHelper = utilities.getUtility(StAXHelper.class); + + monitorFactory = utilities.getUtility(MonitorFactory.class); + + // Initialize the Tuscany module activators + // The module activators will be started + registry.getExtensionPoint(ModuleActivatorExtensionPoint.class); + + // Get contribution workspace and assembly model factories + contributionFactory = modelFactories.getFactory(ContributionFactory.class); + + // Create XML artifact processors + staxProcessor = new ExtensibleStAXArtifactProcessor(registry); + + // Create contribution content processor + URLArtifactProcessorExtensionPoint docProcessorExtensions = + registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + artifactProcessor = new ExtensibleURLArtifactProcessor(docProcessorExtensions); + + contributionProcessor = + (ExtendedURLArtifactProcessor<Contribution>)docProcessorExtensions.getProcessor(Contribution.class); + + // Get the model resolvers + modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class); + + // Get composite builders + BuilderExtensionPoint compositeBuilders = registry.getExtensionPoint(BuilderExtensionPoint.class); + compositeBuilder = + compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); + + loadSystemContribution(monitorFactory.createMonitor()); + + inited = true; + + if (logger.isLoggable(Level.FINE)) { + long end = currentTimeMillis(); + logger.fine("The tuscany runtime started in " + (end - start) + " ms."); + } + } + + protected void loadSystemContribution(Monitor monitor) { + DefinitionsFactory definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class); + systemDefinitions = definitionsFactory.createDefinitions(); + + DefinitionsExtensionPoint definitionsExtensionPoint = + registry.getExtensionPoint(DefinitionsExtensionPoint.class); + monitor.pushContext("Extension points definitions"); + try { + for (Definitions defs : definitionsExtensionPoint.getDefinitions()) { + DefinitionsUtil.aggregate(defs, systemDefinitions, monitor); + } + } finally { + monitor.popContext(); + } + + // create a system contribution to hold the definitions. The contribution + // will be extended later with definitions from application contributions + systemContribution = contributionFactory.createContribution(); + systemContribution.setURI("http://tuscany.apache.org/SystemContribution"); + systemContribution.setLocation("http://tuscany.apache.org/SystemContribution"); + ModelResolver modelResolver = new ExtensibleModelResolver(systemContribution, modelResolvers, modelFactories); + systemContribution.setModelResolver(modelResolver); + systemContribution.setUnresolved(true); + + // create an artifact to represent the system defintions and + // add it to the contribution + List<Artifact> artifacts = systemContribution.getArtifacts(); + Artifact artifact = contributionFactory.createArtifact(); + artifact.setURI("http://tuscany.apache.org/SystemContribution/Definitions"); + artifact.setLocation("Derived"); + artifact.setModel(systemDefinitions); + artifacts.add(artifact); + } + + protected Contribution cloneSystemContribution(Monitor monitor) { + start(); + Contribution contribution = contributionFactory.createContribution(); + contribution.setURI(systemContribution.getURI()); + contribution.setLocation(systemContribution.getLocation()); + ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories); + contribution.setModelResolver(modelResolver); + contribution.setUnresolved(true); + + DefinitionsFactory definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class); + Definitions definitions = definitionsFactory.createDefinitions(); + DefinitionsUtil.aggregate(systemDefinitions, definitions, monitor); + // create an artifact to represent the system defintions and + // add it to the contribution + List<Artifact> artifacts = contribution.getArtifacts(); + Artifact artifact = contributionFactory.createArtifact(); + artifact.setURI("http://tuscany.apache.org/SystemContribution/Definitions"); + artifact.setLocation("Derived"); + artifact.setModel(definitions); + artifacts.add(artifact); + return contribution; + } + + public void attachDeploymentComposite(Contribution contribution, Composite composite, boolean appending) { + start(); + // Create an artifact for the deployment composite + Artifact artifact = contributionFactory.createArtifact(); + String uri = composite.getName().getLocalPart() + ".composite"; + artifact.setURI(uri); + + artifact.setLocation(uri); + artifact.setModel(composite); + artifact.setUnresolved(false); + // Add it to the contribution + contribution.getArtifacts().add(artifact); + + // Replace the deployable composites with the deployment composites + // Clear the deployable composites if it's the first deployment composite + if (!appending) { + contribution.getDeployables().clear(); + } + contribution.getDeployables().add(composite); + } + + public Composite build(List<Contribution> contributions, Map<QName, List<String>> bindingMap, Monitor monitor) throws ContributionResolveException, CompositeBuilderException { + start(); + Contribution systemContribution = cloneSystemContribution(monitor); + Definitions systemDefinitions = systemContribution.getArtifacts().get(0).getModel(); + // Build an aggregated SCA definitions model. Must be done before we try and + // resolve any contributions or composites as they may depend on the full + // definitions.xml picture + + // get all definitions.xml artifacts from contributions and aggregate + // into the system contribution. In turn add a default import into + // each contribution so that for unresolved items the resolution + // processing will look in the system contribution + ProcessorContext context = new ProcessorContext(monitor); + for (Contribution contribution : contributions) { + monitor.pushContext("Contribution: " + contribution.getURI()); + try { + // aggregate definitions + for (Artifact artifact : contribution.getArtifacts()) { + if (!"META-INF/definitions.xml".equals(artifact.getURI())) { + continue; + } + Object model = artifact.getModel(); + // FIXME: Should we check the artifact URI is META-INF/definitions.xml? + if (model instanceof Definitions) { + monitor.pushContext("Definitions: " + artifact.getLocation()); + DefinitionsUtil.aggregate((Definitions)model, systemDefinitions, monitor); + } + } + + // create a default import and wire it up to the system contribution + // model resolver. This is the trick that makes the resolution processing + // skip over to the system contribution if resolution is unsuccessful + // in the current contribution + DefaultImport defaultImport = contributionFactory.createDefaultImport(); + defaultImport.setModelResolver(systemContribution.getModelResolver()); + contribution.getImports().add(defaultImport); + } finally { + monitor.popContext(); + } + } + + ExtensibleModelResolver modelResolver = + new ExtensibleModelResolver(new Contributions(contributions), modelResolvers, modelFactories); + + // now resolve and add the system contribution + contributionProcessor.resolve(systemContribution, modelResolver, context); + contributions.add(systemContribution); + + // pre-resolve the contributions + contributionsPreresolve(contributions, modelResolver, context); + + // Build the contribution dependencies + Set<Contribution> resolved = new HashSet<Contribution>(); + for (Contribution contribution : contributions) { + buildDependencies(contribution, contributions, monitor); + + // Resolve contributions + for (Contribution dependency : contribution.getDependencies()) { + if (!resolved.contains(dependency)) { + resolved.add(dependency); + contributionProcessor.resolve(dependency, modelResolver, context); + } + } + } + + // Create a top level composite to host our composite + // This is temporary to make the activator happy + Composite domainComposite = assemblyFactory.createComposite(); + domainComposite.setName(Composite.DOMAIN_COMPOSITE); + domainComposite.setURI(Base.SCA11_NS); + + for (Contribution contribution : contributions) { + for (Composite composite : contribution.getDeployables()) { + // Include the node composite in the top-level composite + domainComposite.getIncludes().add(composite); + } + } + + // build the top level composite + BuilderContext builderContext = new BuilderContext(systemDefinitions, bindingMap, monitor); + compositeBuilder.build(domainComposite, builderContext); + // analyzeProblems(monitor); + + return domainComposite; + } + + public Artifact loadArtifact(URI uri, URL location, Monitor monitor) throws ContributionReadException { + start(); + Artifact artifact = contributionFactory.createArtifact(); + artifact.setLocation(location.toString()); + artifact.setURI(uri.toString()); + URLArtifactProcessorExtensionPoint artifactProcessors = + registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + ExtensibleURLArtifactProcessor processor = new ExtensibleURLArtifactProcessor(artifactProcessors); + Object model = processor.read(null, uri, location, new ProcessorContext(monitor)); + artifact.setModel(model); + return artifact; + } + + @SuppressWarnings("unchecked") + public <T> T loadDocument(URI uri, URL location, Monitor monitor) throws ContributionReadException { + start(); + Object model = artifactProcessor.read(null, uri, location, new ProcessorContext(monitor)); + return (T) model; + } + + public <T> T loadXMLDocument(URL document, Monitor monitor) throws XMLStreamException, ContributionReadException { + start(); + XMLStreamReader reader = staxHelper.createXMLStreamReader(document); + reader.nextTag(); + ValidatingXMLInputFactory.setMonitor(reader, monitor); + try { + return loadXMLElement(reader, monitor); + } finally { + reader.close(); + } + } + + public void saveXMLDocument(Object model, Writer writer, Monitor monitor) throws XMLStreamException, + ContributionWriteException { + start(); + XMLStreamWriter streamWriter = staxHelper.createXMLStreamWriter(writer); + staxProcessor.write(model, streamWriter, new ProcessorContext(monitor)); + } + + public void saveXMLElement(Object model, XMLStreamWriter writer, Monitor monitor) + throws XMLStreamException, ContributionWriteException { + start(); + staxProcessor.write(model, writer, new ProcessorContext(monitor)); + } + + @SuppressWarnings("unchecked") + public <T> T loadXMLElement(XMLStreamReader reader, Monitor monitor) throws ContributionReadException, + XMLStreamException { + start(); + return (T)staxProcessor.read(reader, new ProcessorContext(monitor)); + } + + public <T> T loadXMLDocument(Reader document, Monitor monitor) throws XMLStreamException, ContributionReadException { + start(); + XMLStreamReader reader = staxHelper.createXMLStreamReader(document); + ValidatingXMLInputFactory.setMonitor(reader, monitor); + reader.nextTag(); + try { + return loadXMLElement(reader, monitor); + } finally { + reader.close(); + } + } + + public Contribution loadContribution(URI uri, URL location, Monitor monitor) throws ContributionReadException { + start(); + ProcessorContext context = new ProcessorContext(monitor); + // Load the contribution + Contribution contribution = contributionProcessor.read(null, uri, location, context); + return contribution; + } + + public ProcessorContext createProcessorContext() { + start(); + return new ProcessorContext(monitorFactory.createMonitor()); + } + + public BuilderContext createBuilderContext() { + start(); + return new BuilderContext(monitorFactory.createMonitor()); + } + + public boolean isSchemaValidationEnabled() { + return schemaValidationEnabled; + } + + public void setSchemaValidationEnabled(boolean schemaValidationEnabled) { + this.schemaValidationEnabled = schemaValidationEnabled; + } + +} diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java index 06ada62a25..1c2ea6b921 100644 --- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java @@ -29,52 +29,28 @@ import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; -import java.util.Collections; 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 java.util.logging.Level; import java.util.logging.Logger; import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; 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.assembly.builder.BuilderContext; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.common.java.io.IOHelper; -import org.apache.tuscany.sca.common.xml.stax.StAXHelper; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.ContributionFactory; -import org.apache.tuscany.sca.contribution.DefaultImport; -import org.apache.tuscany.sca.contribution.Export; -import org.apache.tuscany.sca.contribution.Import; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ExtendedURLArtifactProcessor; 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.contribution.processor.URLArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint; -import org.apache.tuscany.sca.contribution.resolver.DefaultImportModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; @@ -84,12 +60,8 @@ import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; 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.definitions.Definitions; -import org.apache.tuscany.sca.definitions.DefinitionsFactory; -import org.apache.tuscany.sca.definitions.util.DefinitionsUtil; -import org.apache.tuscany.sca.definitions.xml.DefinitionsExtensionPoint; -import org.apache.tuscany.sca.extensibility.ServiceDeclaration; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; +import org.apache.tuscany.sca.deployment.Deployer; +import org.apache.tuscany.sca.deployment.impl.DeployerImpl; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.monitor.Problem; @@ -113,20 +85,9 @@ public class NodeFactoryImpl extends NodeFactory { protected boolean inited; protected Map<Object, Node> nodes = new ConcurrentHashMap<Object, Node>(); - private AssemblyFactory assemblyFactory; - private CompositeBuilder compositeBuilder; - private StAXArtifactProcessor<Composite> compositeProcessor; - private ContributionFactory contributionFactory; - private ExtendedURLArtifactProcessor<Contribution> contributionProcessor; - protected ExtensionPointRegistry extensionPoints; - private XMLInputFactory inputFactory; - protected FactoryExtensionPoint modelFactories; - private ModelResolverExtensionPoint modelResolvers; + protected Deployer deployer; + protected ExtensionPointRegistry registry; protected ProxyFactory proxyFactory; - private Contribution systemContribution; - private Definitions systemDefinitions; - private StAXArtifactProcessorExtensionPoint xmlProcessors; - protected MonitorFactory monitorFactory; @@ -153,33 +114,13 @@ public class NodeFactoryImpl extends NodeFactory { nodes.put(getNodeKey(configuration), node); } - /** - * @param <T> - * @param factory - * @return - * @throws Exception - */ - private <T> T getFactory(Class<T> factory) throws Exception { - ServiceDeclaration sd = ServiceDiscovery.getInstance().getServiceDeclaration(factory.getName()); - if (sd != null) { - return factory.cast(sd.loadClass().newInstance()); - } else { - return factory.cast(factory.getMethod("newInstance").invoke(null)); - } - } - @Override public NodeConfiguration loadConfiguration(InputStream xml, URL base) { try { init(); - StAXHelper helper = StAXHelper.getInstance(extensionPoints); - XMLStreamReader reader = helper.createXMLStreamReader(xml); - StAXArtifactProcessorExtensionPoint processors = - extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - StAXArtifactProcessor processor = processors.getProcessor(NodeConfiguration.class); - reader.nextTag(); - NodeConfiguration config = (NodeConfiguration)processor.read(reader, new ProcessorContext(extensionPoints)); - xml.close(); + InputStreamReader reader = new InputStreamReader(xml, "UTF-8"); + ProcessorContext context = deployer.createProcessorContext(); + NodeConfiguration config = deployer.loadXMLDocument(reader, context.getMonitor()); if (base != null && config != null) { // Resolve the contribution location against the node.xml for (ContributionConfiguration c : config.getContributions()) { @@ -197,20 +138,6 @@ public class NodeFactoryImpl extends NodeFactory { } } - private File toFile(URL url) { - if("file".equalsIgnoreCase(url.getProtocol())) { - try { - return new File(url.toURI()); - } catch(URISyntaxException e) { - return new File(url.getPath()); - } catch(IllegalArgumentException e) { - // Hack for file:./a.txt or file:../a/c.wsdl - return new File(url.getPath()); - } - } - return null; - } - public Map<Object, Node> getNodes() { return nodes; } @@ -226,81 +153,12 @@ public class NodeFactoryImpl extends NodeFactory { node.destroy(); } nodes.clear(); - extensionPoints.stop(); + deployer.stop(); + registry.stop(); inited = false; } } - protected static String getSystemProperty(final String name) { - return AccessController.doPrivileged(new PrivilegedAction<String>() { - public String run() { - return System.getProperty(name); - } - }); - } - - private static void warning(Monitor monitor, String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(NodeImpl.class.getName(), "node-impl-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); - monitor.problem(problem); - } - } - - /** - * Analyze a contribution and add its dependencies to the given dependency set. - */ - private void addContributionDependencies(Contribution contribution, List<Contribution> contributions, List<Contribution> dependencies, Set<Contribution> set, Monitor monitor) { - - // Go through the contribution imports - for (Import import_: contribution.getImports()) { - boolean resolved = false; - - // Go through all contribution candidates and their exports - List<Export> matchingExports = new ArrayList<Export>(); - for (Contribution dependency: contributions) { - if (dependency == contribution) { - // Do not self import - continue; - } - for (Export export: dependency.getExports()) { - - // If an export from a contribution matches the import in hand - // add that contribution to the dependency set - if (import_.match(export)) { - resolved = true; - matchingExports.add(export); - - if (!set.contains(dependency)) { - set.add(dependency); - dependencies.add(dependency); - - // Now add the dependencies of that contribution - addContributionDependencies(dependency, contributions, dependencies, set, monitor); - } // end if - } // end if - } // end for - } // end for - - if (resolved) { - // Initialize the import's model resolver with a delegating model - // resolver which will delegate to the matching exports - import_.setModelResolver(new DefaultImportModelResolver(matchingExports)); - - } else { - // Record import resolution issue - if (!(import_ instanceof DefaultImport)) { - // Add the (empty) matchingExports List and report a warning - import_.setModelResolver(new DefaultImportModelResolver(matchingExports)); - Monitor.error(monitor, - this, - "node-impl-validation-messages", - "UnresolvedImport", - import_); - } - } // end if - } - } - /** * Analyze problems reported by the artifact processors and builders. * @@ -325,78 +183,21 @@ public class NodeFactoryImpl extends NodeFactory { private boolean attachDeploymentComposite(Contribution contribution, Reader xml, String location, boolean attached, ProcessorContext context) throws XMLStreamException, ContributionReadException { - XMLStreamReader reader = inputFactory.createXMLStreamReader(xml); - reader.nextTag(); // Read the composite model - Composite composite = (Composite)compositeProcessor.read(reader, context); - reader.close(); - - // Create an artifact for the deployment composite - Artifact artifact = contributionFactory.createArtifact(); - String uri = composite.getName().getLocalPart() + ".composite"; - artifact.setURI(uri); - // Set the location to avoid NPE - if (location == null) { - location = uri; - } - artifact.setLocation(location); - artifact.setModel(composite); - artifact.setUnresolved(false); - // Add it to the contribution - contribution.getArtifacts().add(artifact); + Composite composite = deployer.loadXMLDocument(xml, context.getMonitor()); // Replace the deployable composites with the deployment composites // Clear the deployable composites if it's the first deployment composite + deployer.attachDeploymentComposite(contribution, composite, attached); if (!attached) { - contribution.getDeployables().clear(); attached = true; - } - contribution.getDeployables().add(composite); - + } return attached; } - private void buildDependencies(Contribution contribution, List<Contribution> contributions, Monitor monitor) { - contribution.getDependencies().clear(); - - List<Contribution> dependencies = new ArrayList<Contribution>(); - Set<Contribution> set = new HashSet<Contribution>(); - - dependencies.add(contribution); - set.add(contribution); - addContributionDependencies(contribution, contributions, dependencies, set, monitor); - - Collections.reverse(dependencies); - - contribution.getDependencies().addAll(dependencies); - } - - /** - * Pre-resolve phase for contributions, to set up handling of imports and exports prior to full resolution - * @param contributions - the contributions to preresolve - * @param resolver - the ModelResolver to use - * @throws ContributionResolveException - */ - private void contributionsPreresolve( List<Contribution> contributions, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - - for( Contribution contribution : contributions ) { - contributionProcessor.preResolve(contribution, resolver, context); - } // end for - } // end method contributionsPreresolve - public ExtensionPointRegistry getExtensionPoints() { - return extensionPoints; - } - - protected boolean isSchemaValidationEnabled() { - String enabled = getSystemProperty(ValidationSchemaExtensionPoint.class.getName() + ".enabled"); - if (enabled == null) { - enabled = "true"; - } - boolean debug = logger.isLoggable(Level.FINE); - return "true".equals(enabled) || debug; + return registry; } public synchronized void init() { @@ -406,93 +207,37 @@ public class NodeFactoryImpl extends NodeFactory { long start = currentTimeMillis(); // Create extension point registry - extensionPoints = createExtensionPointRegistry(); - extensionPoints.start(); - - // Enable schema validation only of the logger level is FINE or higher - if (isSchemaValidationEnabled()) { - ValidationSchemaExtensionPoint schemas = - extensionPoints.getExtensionPoint(ValidationSchemaExtensionPoint.class); - if (schemas != null) { - schemas.setEnabled(true); - } - } - + registry = createExtensionPointRegistry(); + registry.start(); + // Use the runtime-enabled assembly factory - modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - assemblyFactory = new RuntimeAssemblyFactory(extensionPoints); + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = new RuntimeAssemblyFactory(registry); modelFactories.addFactory(assemblyFactory); + deployer = new DeployerImpl(registry); + + // Enable schema validation only of the logger level is FINE or higher + deployer.setSchemaValidationEnabled(isSchemaValidationEnabled()); + deployer.start(); + // Create a monitor - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); monitorFactory = utilities.getUtility(MonitorFactory.class); // Initialize the Tuscany module activators // The module activators will be started - extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class); - - // Get XML input/output factories - inputFactory = modelFactories.getFactory(XMLInputFactory.class); - - // Get contribution workspace and assembly model factories - contributionFactory = modelFactories.getFactory(ContributionFactory.class); - - // Create XML artifact processors - xmlProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - compositeProcessor = xmlProcessors.getProcessor(Composite.class); - - // Create contribution content processor - URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - contributionProcessor = (ExtendedURLArtifactProcessor<Contribution>) docProcessorExtensions.getProcessor(Contribution.class); - - // Get the model resolvers - modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - - // Get composite builders - BuilderExtensionPoint compositeBuilders = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class); - compositeBuilder = compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); + registry.getExtensionPoint(ModuleActivatorExtensionPoint.class); // Initialize runtime // Get proxy factory - ProxyFactoryExtensionPoint proxyFactories = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class); + ProxyFactoryExtensionPoint proxyFactories = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class); proxyFactory = new ExtensibleProxyFactory(proxyFactories); utilities.getUtility(WorkScheduler.class); - DefinitionsFactory definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class); - systemDefinitions = definitionsFactory.createDefinitions(); - - DefinitionsExtensionPoint definitionsExtensionPoint = extensionPoints.getExtensionPoint(DefinitionsExtensionPoint.class); - Monitor monitor = monitorFactory.createMonitor(); - monitor.pushContext("Extension points definitions"); - try { - for (Definitions defs : definitionsExtensionPoint.getDefinitions()) { - DefinitionsUtil.aggregate(defs, systemDefinitions, monitor); - } - } finally { - monitor.popContext(); - } - - // create a system contribution to hold the definitions. The contribution - // will be extended later with definitions from application contributions - systemContribution = contributionFactory.createContribution(); - systemContribution.setURI("http://tuscany.apache.org/SystemContribution"); - systemContribution.setLocation("http://tuscany.apache.org/SystemContribution"); - ModelResolver modelResolver = new ExtensibleModelResolver(systemContribution, modelResolvers, modelFactories); - systemContribution.setModelResolver(modelResolver); - systemContribution.setUnresolved(true); - - // create an artifact to represent the system defintions and - // add it to the contribution - List<Artifact> artifacts = systemContribution.getArtifacts(); - Artifact artifact = contributionFactory.createArtifact(); - artifact.setURI("http://tuscany.apache.org/SystemContribution/Definitions"); - artifact.setLocation("Derived"); - artifact.setModel(systemDefinitions); - artifacts.add(artifact); - inited = true; if (logger.isLoggable(Level.FINE)) { @@ -504,6 +249,15 @@ public class NodeFactoryImpl extends NodeFactory { protected ExtensionPointRegistry createExtensionPointRegistry() { return new DefaultExtensionPointRegistry(); } + + protected boolean isSchemaValidationEnabled() { + String enabled = getSystemProperty(ValidationSchemaExtensionPoint.class.getName() + ".enabled"); + if (enabled == null) { + enabled = "true"; + } + boolean debug = logger.isLoggable(Level.FINE); + return "true".equals(enabled) || debug; + } protected Composite configureNode(NodeConfiguration configuration, List<Contribution> contributions, ProcessorContext context) throws Throwable { @@ -511,87 +265,13 @@ public class NodeFactoryImpl extends NodeFactory { // Load contributions contributions = loadContributions(configuration, context); } - // Build an aggregated SCA definitions model. Must be done before we try and - // resolve any contributions or composites as they may depend on the full - // definitions.xml picture - - // get all definitions.xml artifacts from contributions and aggregate - // into the system contribution. In turn add a default import into - // each contribution so that for unresolved items the resolution - // processing will look in the system contribution + Monitor monitor = context.getMonitor(); - for (Contribution contribution: contributions) { - monitor.pushContext("Contribution: " + contribution.getURI()); - // aggregate definitions - for (Artifact artifact : contribution.getArtifacts()) { - Object model = artifact.getModel(); - // FIXME: Should we check the artifact URI is META-INF/definitions.xml? - if (model instanceof Definitions) { - monitor.pushContext("Definitions: " + artifact.getLocation()); - DefinitionsUtil.aggregate((Definitions)model, systemDefinitions, monitor); - monitor.popContext(); - } - } - - // create a default import and wire it up to the system contribution - // model resolver. This is the trick that makes the resolution processing - // skip over to the system contribution if resolution is unsuccessful - // in the current contribution - DefaultImport defaultImport = contributionFactory.createDefaultImport(); - defaultImport.setModelResolver(systemContribution.getModelResolver()); - contribution.getImports().add(defaultImport); - monitor.popContext(); - } - - ExtensibleModelResolver modelResolver = new ExtensibleModelResolver(new Contributions(contributions), modelResolvers, modelFactories); - - // now resolve and add the system contribution - contributionProcessor.resolve(systemContribution, modelResolver, context); - contributions.add(systemContribution); - - // TODO - Now we can calculate applicable policy sets for each composite - - // pre-resolve the contributions - contributionsPreresolve(contributions, modelResolver, context); - - // Build the contribution dependencies - Set<Contribution> resolved = new HashSet<Contribution>(); - for (Contribution contribution: contributions) { - buildDependencies(contribution, contributions, monitor); - - // Resolve contributions - for (Contribution dependency: contribution.getDependencies()) { - if (!resolved.contains(dependency)) { - resolved.add(dependency); - contributionProcessor.resolve(dependency, modelResolver, context); - } - } - } - - // Create a top level composite to host our composite - // This is temporary to make the activator happy - Composite domainComposite = assemblyFactory.createComposite(); - domainComposite.setName(Composite.DOMAIN_COMPOSITE); - domainComposite.setURI(Base.SCA11_NS); - - for (Contribution contribution : contributions) { - for (Composite composite : contribution.getDeployables()) { - // Include the node composite in the top-level composite - domainComposite.getIncludes().add(composite); - logger.log(Level.INFO, "Adding composite: " + composite.getName() + " to domain " + getDomainURI()); - } - } - - // TODO - EPR - create a binding map to pass down into the builders - // for use during URI calculation. - Map<QName, List<String>> bindingMap = new HashMap<QName, List<String>>(); + Map<QName, List<String>> bindingBaseURIs = new HashMap<QName, List<String>>(); for (BindingConfiguration config : configuration.getBindings()) { - bindingMap.put(config.getBindingType(), config.getBaseURIs()); + bindingBaseURIs.put(config.getBindingType(), config.getBaseURIs()); } - - // build the top level composite - BuilderContext builderContext = new BuilderContext(systemDefinitions, bindingMap, monitor); - compositeBuilder.build(domainComposite, builderContext); + Composite domainComposite = deployer.build(contributions, bindingBaseURIs, monitor); analyzeProblems(monitor); return domainComposite; @@ -612,7 +292,7 @@ public class NodeFactoryImpl extends NodeFactory { // Load the contribution logger.log(Level.INFO, "Loading contribution: " + contributionURL); - Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL, context); + Contribution contribution = deployer.loadContribution(contributionURI, contributionURL, context.getMonitor()); contributions.add(contribution); boolean attached = false; @@ -655,6 +335,14 @@ public class NodeFactoryImpl extends NodeFactory { return contributions; } + protected static String getSystemProperty(final String name) { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return System.getProperty(name); + } + }); + } + protected static class NodeKey { private String domainURI; private String nodeURI; diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java index 4de400db11..f3172926f1 100644 --- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -114,7 +114,7 @@ public class NodeImpl implements Node, Client { manager.init(); manager.addNode(configuration, this); this.proxyFactory = manager.proxyFactory; - UtilityExtensionPoint utilities = manager.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + UtilityExtensionPoint utilities = manager.registry.getExtensionPoint(UtilityExtensionPoint.class); DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class); EndpointRegistry endpointRegistry = @@ -135,7 +135,7 @@ public class NodeImpl implements Node, Client { domainComposite = manager.configureNode(configuration, contributions, context); this.compositeContext = - new CompositeContextImpl(manager.extensionPoints, endpointRegistry, domainComposite); + new CompositeContextImpl(manager.registry, endpointRegistry, domainComposite); } finally { // Reset the thread context monitor manager.monitorFactory.setContextMonitor(tcm); @@ -207,7 +207,7 @@ public class NodeImpl implements Node, Client { } // end if manager.removeNode(configuration); - manager.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).removeUtility(compositeActivator); + manager.registry.getExtensionPoint(UtilityExtensionPoint.class).removeUtility(compositeActivator); this.compositeActivator = null; this.proxyFactory = null; this.domainComposite = null; @@ -343,7 +343,7 @@ public class NodeImpl implements Node, Client { .getFactory(XMLOutputFactory.class); try { - compositeProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), new ProcessorContext(manager.extensionPoints)); + compositeProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), new ProcessorContext(manager.registry)); } catch(Exception ex) { return ex.toString(); } diff --git a/java/sca/modules/node-impl/src/main/resources/node-impl-validation-messages.properties b/java/sca/modules/node-impl/src/main/resources/org/apache/tuscany/sca/node/impl/node-impl-validation-messages.properties index 0c07a3a30f..0c07a3a30f 100644 --- a/java/sca/modules/node-impl/src/main/resources/node-impl-validation-messages.properties +++ b/java/sca/modules/node-impl/src/main/resources/org/apache/tuscany/sca/node/impl/node-impl-validation-messages.properties |