tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sl...@apache.org
Subject svn commit: r739953 - in /tuscany/java/sca/modules: assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ node-impl/META-INF/ node-impl/src/main/java/org/apache/tuscany/...
Date Mon, 02 Feb 2009 10:01:26 GMT
Author: slaws
Date: Mon Feb  2 10:01:25 2009
New Revision: 739953

URL: http://svn.apache.org/viewvc?rev=739953&view=rev
Log:
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. 

Added:
    tuscany/java/sca/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
Modified:
    tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java
    tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
    tuscany/java/sca/modules/node-impl/META-INF/MANIFEST.MF
    tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java

Modified: tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java?rev=739953&r1=739952&r2=739953&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java
(original)
+++ tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java
Mon Feb  2 10:01:25 2009
@@ -90,9 +90,11 @@
 
     public Composite read(URI uri, InputStream scdlStream) throws ContributionReadException
{
         try {
+/*            
             if (scaDefnSink != null ) {
                 fillDomainPolicySets(scaDefnSink);
             }
+*/            
             
             Composite composite = null;
             
@@ -172,6 +174,10 @@
         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 @@
             scaDefnsCount = scaDefnsSink.size();
         }
     }
+    */
 }

Modified: tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java?rev=739953&r1=739952&r2=739953&view=diff
==============================================================================
--- tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
(original)
+++ tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
Mon Feb  2 10:01:25 2009
@@ -22,6 +22,11 @@
 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 @@
  */
 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 @@
             
         } 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;
         }

Modified: tuscany/java/sca/modules/node-impl/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl/META-INF/MANIFEST.MF?rev=739953&r1=739952&r2=739953&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl/META-INF/MANIFEST.MF (original)
+++ tuscany/java/sca/modules/node-impl/META-INF/MANIFEST.MF Mon Feb  2 10:01:25 2009
@@ -30,11 +30,13 @@
  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",

Modified: tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java?rev=739953&r1=739952&r2=739953&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
(original)
+++ tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
Mon Feb  2 10:01:25 2009
@@ -49,6 +49,7 @@
 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.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.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 @@
     private List<ModuleActivator> moduleActivators = new ArrayList<ModuleActivator>();
     private CompositeActivator compositeActivator;
     private WorkScheduler workScheduler;
+    private Contribution systemContribution;
     private Definitions systemDefinitions;
 
     /** 
@@ -305,7 +312,6 @@
         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 @@
         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
-        
-//        // 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);
-//        }
+        // 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 
+            
+        
 //
 //        // Configure a resolver for the system definitions
 //        ModelResolver definitionsResolver = new DefaultModelResolver();
@@ -429,6 +455,39 @@
             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 @@
         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 @@
         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

Added: tuscany/java/sca/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver?rev=739953&view=auto
==============================================================================
--- tuscany/java/sca/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
(added)
+++ tuscany/java/sca/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
Mon Feb  2 10:01:25 2009
@@ -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



Mime
View raw message