summaryrefslogtreecommitdiffstats
path: root/java/sca
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-02-02 10:01:25 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-02-02 10:01:25 +0000
commitb88e412e331eeaa9658c21f37c31d4d08a149b12 (patch)
tree9358970ab6c1424c4d6bd3d3a6222c335c6c9bd4 /java/sca
parent8751ca0a45b9343f37161c9f762fb4c485944a5f (diff)
TUSCANY-2801 - Create a SystemContribution to hold data from definitions.xml found in extensions and in application contributions. This change creates a system contribution on the fly in the node and installs a DefaultModelResolver for various policy elements. The default resolver not takes account of any default imports that are available. All application level contributions are linked to the system contribution via a default import that references the system contributions model resolver. Hence policy element resolution will traverse the tree to the system contribution if the element is not resolved locally. We may want to create specific policy resolvers here but this change allows for some experimentation. The next hurdle to getting this to work is to get policy set XPath applied to the assembly model again.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@739953 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca')
-rw-r--r--java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java7
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java23
-rw-r--r--java/sca/modules/node-impl/META-INF/MANIFEST.MF2
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java103
-rw-r--r--java/sca/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver18
5 files changed, 129 insertions, 24 deletions
diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java
index 476a5fe08c..f0ecd22761 100644
--- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java
+++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java
@@ -90,9 +90,11 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements
public Composite read(URI uri, InputStream scdlStream) throws ContributionReadException {
try {
+/*
if (scaDefnSink != null ) {
fillDomainPolicySets(scaDefnSink);
}
+*/
Composite composite = null;
@@ -172,6 +174,10 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements
return Composite.class;
}
+ /*
+ * TODO - remove - definitions information is now aggregated in the
+ * systems definitions contribution and we need to add
+ * applicable policy sets once all composites have been read
private void fillDomainPolicySets(List scaDefnsSink) {
Map<QName, PolicySet> domainPolicySetMap = null;
if ( scaDefnsSink.size() > scaDefnsCount ) {
@@ -196,4 +202,5 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements
scaDefnsCount = scaDefnsSink.size();
}
}
+ */
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
index 597fa6f4a0..5f4b5100c2 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
@@ -22,6 +22,11 @@ package org.apache.tuscany.sca.contribution.resolver;
import java.util.HashMap;
import java.util.Map;
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.DefaultImport;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
/**
* A default implementation of a model resolver based on a map.
@@ -30,11 +35,16 @@ import java.util.Map;
*/
public class DefaultModelResolver implements ModelResolver {
+ private Contribution contribution;
private Map<Object, Object> map = new HashMap<Object, Object>();
public DefaultModelResolver() {
}
+ public DefaultModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) {
+ this.contribution = contribution;
+ }
+
public <T> T resolveModel(Class<T> modelClass, T unresolved) {
Object resolved = map.get(unresolved);
if (resolved != null) {
@@ -44,6 +54,19 @@ public class DefaultModelResolver implements ModelResolver {
} else {
+ // by default try and resolve through a default import
+ // if there is one.
+ if (contribution != null){
+ for (Import _import : contribution.getImports()){
+ if (_import instanceof DefaultImport){
+ resolved = _import.getModelResolver().resolveModel(modelClass, unresolved);
+ if (resolved != unresolved){
+ return modelClass.cast(resolved);
+ }
+ }
+ }
+ }
+
// Return the unresolved object
return unresolved;
}
diff --git a/java/sca/modules/node-impl/META-INF/MANIFEST.MF b/java/sca/modules/node-impl/META-INF/MANIFEST.MF
index 8247f6f433..3970002180 100644
--- a/java/sca/modules/node-impl/META-INF/MANIFEST.MF
+++ b/java/sca/modules/node-impl/META-INF/MANIFEST.MF
@@ -30,11 +30,13 @@ Import-Package: javax.xml.namespace,
org.apache.tuscany.sca.core.assembly;version="2.0.0",
org.apache.tuscany.sca.core.invocation;version="2.0.0",
org.apache.tuscany.sca.definitions;version="2.0.0",
+ org.apache.tuscany.sca.definitions.util;version="2.0.0",
org.apache.tuscany.sca.implementation.node;version="2.0.0",
org.apache.tuscany.sca.monitor;version="2.0.0",
org.apache.tuscany.sca.node;version="2.0.0",
org.apache.tuscany.sca.node.impl;version="2.0.0",
org.apache.tuscany.sca.policy;version="2.0.0",
+ org.apache.tuscany.sca.provider;version="2.0.0",
org.apache.tuscany.sca.runtime;version="2.0.0",
org.apache.tuscany.sca.work;version="2.0.0",
org.apache.tuscany.sca.workspace;version="2.0.0",
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 56a9ee4bbe..d1b92660b4 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
@@ -49,6 +49,7 @@ import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint;
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.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
@@ -69,6 +70,8 @@ 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.implementation.node.ConfiguredNodeImplementation;
import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory;
import org.apache.tuscany.sca.monitor.Monitor;
@@ -78,6 +81,9 @@ import org.apache.tuscany.sca.monitor.Problem.Severity;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.provider.DefinitionsProvider;
+import org.apache.tuscany.sca.provider.DefinitionsProviderException;
+import org.apache.tuscany.sca.provider.DefinitionsProviderExtensionPoint;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
import org.apache.tuscany.sca.work.WorkScheduler;
@@ -121,6 +127,7 @@ public class NodeImpl implements Node, Client {
private List<ModuleActivator> moduleActivators = new ArrayList<ModuleActivator>();
private CompositeActivator compositeActivator;
private WorkScheduler workScheduler;
+ private Contribution systemContribution;
private Definitions systemDefinitions;
/**
@@ -305,7 +312,6 @@ public class NodeImpl implements Node, Client {
assemblyFactory = new RuntimeAssemblyFactory();
modelFactories.addFactory(assemblyFactory);
-
// Create a monitor
UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
@@ -359,23 +365,43 @@ public class NodeImpl implements Node, Client {
compositeActivator = utilities.getUtility(CompositeActivator.class);
workScheduler = utilities.getUtility(WorkScheduler.class);
+
+ // Load the system definitions.xml from all of the loaded extension points
+ DefinitionsProviderExtensionPoint definitionsProviders = extensionPoints.getExtensionPoint(DefinitionsProviderExtensionPoint.class);
+ DefinitionsFactory definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class);
+ systemDefinitions = definitionsFactory.createDefinitions();
- // This is not right, the aggregate algorithm is not right, adding policies to
- // a resolver like that is not correct as these policies won't be seen by the resolvers
- // used by the contributions, and we shouldn't have to use the doc processor to do
- // the resolution, so commenting out for now as it's not critical to get working in
- // the Equinox environment initially
+ // aggregate all the definitions into a single definitions model
+ try {
+ for (DefinitionsProvider definitionsProvider : definitionsProviders.getDefinitionsProviders()) {
+ DefinitionsUtil.aggregate(definitionsProvider.getDefinitions(), systemDefinitions);
+ }
+ } catch (DefinitionsProviderException e) {
+ throw new IllegalStateException(e);
+ }
+
+ // 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("Derived");
+ 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);
+
+ // don't resolve the system contribution until all the application
+ // level definitions have been added
+
-// // Load the system definitions.xml
-// DefinitionsProviderExtensionPoint definitionsProviders = extensionPoints.getExtensionPoint(DefinitionsProviderExtensionPoint.class);
-// systemDefinitions = new DefinitionsImpl();
-// try {
-// for (DefinitionsProvider definitionsProvider : definitionsProviders.getDefinitionsProviders()) {
-// aggregateDefinitions(definitionsProvider.getSCADefinition(), systemDefinitions);
-// }
-// } catch (DefinitionsProviderException e) {
-// throw new IllegalStateException(e);
-// }
//
// // Configure a resolver for the system definitions
// ModelResolver definitionsResolver = new DefaultModelResolver();
@@ -429,6 +455,39 @@ public class NodeImpl implements Node, Client {
workspace.getContributions().add(contribution);
analyzeProblems();
}
+
+ // 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
+ for (Contribution contribution: workspace.getContributions()) {
+ // aggregate definitions
+ for (Artifact artifact : contribution.getArtifacts()) {
+ Object model = artifact.getModel();
+ if (model instanceof Definitions) {
+ DefinitionsUtil.aggregate((Definitions)model, systemDefinitions);
+ }
+ }
+
+ // 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);
+ }
+
+ // now resolve the system contribution and add the contribution
+ // to the workspace
+ contributionProcessor.resolve(systemContribution, workspace.getModelResolver());
+ workspace.getContributions().add(systemContribution);
+
+ // TODO - Now we can calculate applicable policy sets for each composite
// Build the contribution dependencies
Set<Contribution> resolved = new HashSet<Contribution>();
@@ -457,6 +516,9 @@ public class NodeImpl implements Node, Client {
compositeFile.setURI(composite.getURI());
for (Contribution contribution: workspace.getContributions()) {
ModelResolver resolver = contribution.getModelResolver();
+ for (Artifact artifact : contribution.getArtifacts()){
+ logger.log(Level.INFO,"artifact - " + artifact.getURI());
+ }
Artifact resolvedArtifact = resolver.resolveModel(Artifact.class, compositeFile);
if (!resolvedArtifact.isUnresolved() && resolvedArtifact.getModel() instanceof Composite) {
@@ -479,16 +541,9 @@ public class NodeImpl implements Node, Client {
if (!found) {
throw new IllegalArgumentException("Composite not found: " + composite.getURI());
}
-
- // Build an aggregated SCA definitions model
- Definitions definitions = systemDefinitions;
- //definitions = new DefinitionsImpl();
- //for (Definitions definition : ((List<Definitions>)policyDefinitions)) {
- // DefinitionsUtil.aggregateDefinitions(definition, definitions);
- //}
// Build the composite and wire the components included in it
- compositeBuilder.build(composite, definitions, monitor);
+ compositeBuilder.build(composite, systemDefinitions, monitor);
analyzeProblems();
// Create a top level composite to host our composite
diff --git a/java/sca/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/java/sca/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
new file mode 100644
index 0000000000..4daf46c790
--- /dev/null
+++ b/java/sca/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
@@ -0,0 +1,18 @@
+# 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.
+
+org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;model=org.apache.tuscany.sca.policy.Intent