You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2007/06/19 22:12:48 UTC

svn commit: r548839 [2/2] - in /incubator/tuscany/java/sca/modules/distributed: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/sca/ src/main/java/org/apac...

Added: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntimeBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntimeBuilder.java?view=auto&rev=548839
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntimeBuilder.java (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntimeBuilder.java Tue Jun 19 13:12:46 2007
@@ -0,0 +1,164 @@
+/*
+ * 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.distributed.host.impl;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.xml.ComponentTypeDocumentProcessor;
+import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor;
+import org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor;
+import org.apache.tuscany.sca.assembly.xml.CompositeProcessor;
+import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeDocumentProcessor;
+import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl;
+import org.apache.tuscany.sca.contribution.processor.DefaultPackageProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensiblePackageProcessor;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessor;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.impl.FolderContributionProcessor;
+import org.apache.tuscany.sca.contribution.processor.impl.JarContributionProcessor;
+import org.apache.tuscany.sca.contribution.service.ContributionRepository;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.contribution.service.impl.ContributionRepositoryImpl;
+import org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl;
+import org.apache.tuscany.sca.contribution.service.impl.PackageTypeDescriberImpl;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.ExtensibleWireProcessor;
+import org.apache.tuscany.sca.core.invocation.JDKProxyService;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.runtime.ActivationException;
+import org.apache.tuscany.sca.core.runtime.CompositeActivator;
+import org.apache.tuscany.sca.core.runtime.CompositeActivatorImpl;
+import org.apache.tuscany.sca.core.runtime.RuntimeSCABindingProviderFactory;
+import org.apache.tuscany.sca.core.scope.CompositeScopeContainerFactory;
+import org.apache.tuscany.sca.core.scope.RequestScopeContainerFactory;
+import org.apache.tuscany.sca.core.scope.ScopeRegistryImpl;
+import org.apache.tuscany.sca.core.scope.StatelessScopeContainerFactory;
+import org.apache.tuscany.sca.core.work.Jsr237WorkScheduler;
+import org.apache.tuscany.sca.distributed.node.impl.NodeDocumentProcessor;
+import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntimeBuilder;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.provider.DefaultProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.runtime.DefaultWireProcessorExtensionPoint;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
+import org.apache.tuscany.sca.scope.ScopeContainerFactory;
+import org.apache.tuscany.sca.scope.ScopeRegistry;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+import commonj.work.WorkManager;
+
+/**
+ * This is almost exactly the same as the really small runtime builder
+ * except that it loads the topology document processor when the contribution
+ * service is created. This is really just a place holder for whatever runtime
+ * options are required to run and manage the node. 
+ *
+ */
+public class NodeServiceRuntimeBuilder extends ReallySmallRuntimeBuilder {
+
+
+    /**
+     * Create the contribution service used by this domain.
+     * 
+     * @throws ActivationException
+     */
+    public static ContributionService createContributionService(ExtensionPointRegistry registry,
+                                                                AssemblyFactory assemblyFactory,
+                                                                PolicyFactory policyFactory,
+                                                                InterfaceContractMapper mapper)
+        throws ActivationException {
+
+        XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
+
+        // Create STAX artifact processor extension point
+        DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint();
+        registry.addExtensionPoint(staxProcessors);
+
+        // Create and register STAX processors for SCA assembly XML
+        ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, xmlFactory,
+                                                                                            XMLOutputFactory
+                                                                                                .newInstance());
+        staxProcessors.addArtifactProcessor(new CompositeProcessor(assemblyFactory, policyFactory, mapper,
+                                                                   staxProcessor));
+        staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessor));
+        staxProcessors
+            .addArtifactProcessor(new ConstrainingTypeProcessor(assemblyFactory, policyFactory, staxProcessor));
+
+        // Create URL artifact processor extension point
+        // FIXME use the interface instead of the class
+        DefaultURLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint();
+        registry.addExtensionPoint(documentProcessors);
+
+        // Create and register document processors for SCA assembly XML
+        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+        documentProcessors.addArtifactProcessor(new NodeDocumentProcessor(staxProcessor, inputFactory));
+        //documentProcessors.addArtifactProcessor(new CompositeDocumentProcessor(staxProcessor, inputFactory));
+        documentProcessors.addArtifactProcessor(new ComponentTypeDocumentProcessor(staxProcessor, inputFactory));
+        documentProcessors.addArtifactProcessor(new ConstrainingTypeDocumentProcessor(staxProcessor, inputFactory));
+
+        // Create contribution package processor extension point
+        PackageTypeDescriberImpl describer = new PackageTypeDescriberImpl();
+        PackageProcessorExtensionPoint packageProcessors = new DefaultPackageProcessorExtensionPoint();
+        PackageProcessor packageProcessor = new ExtensiblePackageProcessor(packageProcessors, describer);
+        registry.addExtensionPoint(packageProcessors);
+
+        // Register base package processors
+        packageProcessors.addPackageProcessor(new JarContributionProcessor());
+        packageProcessors.addPackageProcessor(new FolderContributionProcessor());
+
+        // Create a contribution repository
+        ContributionRepository repository;
+        try {
+            repository = new ContributionRepositoryImpl("target");
+        } catch (IOException e) {
+            throw new ActivationException(e);
+        }
+
+        ContributionFactory contributionFactory = new ContributionFactoryImpl();
+        ExtensibleURLArtifactProcessor documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors);
+        ContributionService contributionService = new ContributionServiceImpl(repository, packageProcessor,
+                                                                              documentProcessor, assemblyFactory,
+                                                                              contributionFactory, xmlFactory);
+        return contributionService;
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntimeBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntimeBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/ComponentRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/ComponentRegistry.java?view=auto&rev=548839
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/ComponentRegistry.java (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/ComponentRegistry.java Tue Jun 19 13:12:46 2007
@@ -0,0 +1,61 @@
+/*
+ * 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.distributed.node;
+
+import java.util.List;
+
+
+/**
+ * Represents the mapping between components and runtime nodes.
+ * 
+ * TBD - just a place holder at the moment
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentRegistry {
+    
+    /**
+     * Retrieves the name of the node that is responsible for running
+     * the named component
+     *  
+     * @param componentName the string name for the component of interest
+     * @return node name
+     */
+    public String getComponentNode(String componentName);
+    
+    
+    /**
+     * Sets the name of the node that is responsible for running
+     * the named component
+     *  
+     * @param componentName the string name for the component of interest
+     * @return node name
+     */
+    public void setComponentNode(String componentName, String nodeName);
+    
+    /**
+     * Loop through all the components in the model getting all the 
+     * component names for the specified node name
+     * 
+     * @param nodeName
+     * @return
+     */
+    public List<String> getComponentsForNode(String nodeName);    
+}

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/ComponentRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/ComponentRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/DefaultComponentRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/DefaultComponentRegistry.java?view=auto&rev=548839
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/DefaultComponentRegistry.java (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/DefaultComponentRegistry.java Tue Jun 19 13:12:46 2007
@@ -0,0 +1,83 @@
+/*
+ * 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.distributed.node.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * Represents the mapping between components and runtime nodes.
+ * 
+ * TBD - just a place holder at the moment
+ *
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+public class DefaultComponentRegistry {
+    
+    /**
+     * A map of component name to node name
+     */
+    private HashMap<String, String> components = new HashMap<String, String>();
+    
+    /**
+     * Retrieves the name of the node that is responsible for running
+     * the named component
+     *  
+     * @param componentName the string name for the component of interest
+     * @return node name
+     */
+    public String getComponentNode(String componentName){
+        return components.get(componentName);
+    }
+    
+    /**
+     * Sets the name of the node that is responsible for running
+     * the named component
+     *  
+     * @param componentName the string name for the component of interest
+     * @return node name
+     */
+    public void setComponentNode(String componentName, String nodeName){
+        components.put(componentName, nodeName);
+    }
+    
+    /**
+     * Loop through all the components in the model getting all the 
+     * component names for the specified node name
+     * 
+     * @param nodeName
+     * @return
+     */
+    public List<String> getComponentsForNode(String nodeName) {
+        List<String> componentList = new ArrayList<String>();
+        
+        for (String componentName : components.keySet()) {
+            if (components.get(componentName).equals(nodeName)) {
+                componentList.add(componentName);
+            }
+        }
+        
+        return componentList;
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/DefaultComponentRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/DefaultComponentRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeDocumentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeDocumentProcessor.java?view=auto&rev=548839
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeDocumentProcessor.java (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeDocumentProcessor.java Tue Jun 19 13:12:46 2007
@@ -0,0 +1,94 @@
+/*
+ * 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.distributed.node.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.topology.xml.BaseArtifactProcessor;
+
+/**
+ * A composite processor.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class NodeDocumentProcessor extends BaseArtifactProcessor implements URLArtifactProcessor<Composite> {
+    private XMLInputFactory inputFactory;
+
+    /**
+     * Construct a new composite processor
+     * @param assemblyFactory
+     * @param policyFactory
+     * @param staxProcessor
+     */
+    public NodeDocumentProcessor(StAXArtifactProcessor staxProcessor, XMLInputFactory inputFactory) {
+        super(null, null, staxProcessor);
+        this.inputFactory = inputFactory;
+    }
+
+    public Composite read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+        InputStream urlStream = null;
+        try {
+            urlStream = url.openStream();
+            XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream);
+            reader.nextTag();
+            Composite composite = (Composite)extensionProcessor.read(reader);
+            return composite;
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionReadException(e);
+        } catch (IOException e) {
+            throw new ContributionReadException(e);
+        } finally {
+            try {
+                if (urlStream != null) {
+                    urlStream.close();
+                    urlStream = null;
+                }
+            } catch (IOException ioe) {
+                //ignore
+            }
+        }
+    }
+    
+    public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException {
+        extensionProcessor.resolve(composite, resolver);
+    }
+
+    public String getArtifactType() {
+        return ".node";
+    }
+    
+    public Class<Composite> getModelType() {
+        return Composite.class;
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeDocumentProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeDocumentProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/distributed/src/test/java/ReadDocumentTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/test/java/ReadDocumentTestCase.java?view=auto&rev=548839
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/test/java/ReadDocumentTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/test/java/ReadDocumentTestCase.java Tue Jun 19 13:12:46 2007
@@ -0,0 +1,98 @@
+/*
+ * 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.    
+ */
+
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.xml.ComponentTypeDocumentProcessor;
+import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor;
+import org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor;
+import org.apache.tuscany.sca.assembly.xml.CompositeProcessor;
+import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeDocumentProcessor;
+import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.distributed.node.impl.NodeDocumentProcessor;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ * Test reading SCA XML assembly documents.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ReadDocumentTestCase extends TestCase {
+
+    private ExtensibleURLArtifactProcessor documentProcessor;
+    private TestModelResolver resolver; 
+
+    public void setUp() throws Exception {
+        AssemblyFactory factory = new DefaultAssemblyFactory();
+        PolicyFactory policyFactory = new DefaultPolicyFactory();
+        InterfaceContractMapper mapper = new InterfaceContractMapperImpl();
+        
+        URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint();
+        documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); 
+        
+        // Create Stax processors
+        DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint();
+        ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance());
+        staxProcessors.addArtifactProcessor(new CompositeProcessor(factory, policyFactory, mapper, staxProcessor));
+        staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(factory, policyFactory, staxProcessor));
+        staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor));
+        
+        // Create document processors
+        XMLInputFactory inputFactory = XMLInputFactory.newInstance(); 
+        documentProcessors.addArtifactProcessor(new NodeDocumentProcessor(staxProcessor, inputFactory));
+        documentProcessors.addArtifactProcessor(new ComponentTypeDocumentProcessor(staxProcessor, inputFactory));
+        documentProcessors.addArtifactProcessor(new ConstrainingTypeDocumentProcessor(staxProcessor, inputFactory));
+
+        resolver = new TestModelResolver(getClass().getClassLoader());
+    }
+
+    public void tearDown() throws Exception {
+        documentProcessor = null;
+        resolver = null;
+    }
+
+    public void testResolveNode() throws Exception {
+        
+        URL url = getClass().getResource("default.node");
+        Composite runtime = (Composite)documentProcessor.read(null, null, url);
+        assertNotNull(runtime);
+        resolver.addModel(runtime);
+        
+        documentProcessor.resolve(runtime, resolver);
+        
+        assertEquals(runtime.getComponents().get(0).getName(), "ComponentRegistry");
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/distributed/src/test/java/ReadDocumentTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/distributed/src/test/java/ReadDocumentTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/distributed/src/test/java/TestModelResolver.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/test/java/TestModelResolver.java?view=auto&rev=548839
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/test/java/TestModelResolver.java (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/test/java/TestModelResolver.java Tue Jun 19 13:12:46 2007
@@ -0,0 +1,44 @@
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+
+/**
+ * A default implementation of an artifact resolver, based on a map.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestModelResolver implements ModelResolver {
+    private static final long serialVersionUID = -7826976465762296634L;
+    
+    private Map<Object, Object> map = new HashMap<Object, Object>();
+    
+    public TestModelResolver(ClassLoader classLoader) {
+    }
+
+    public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+        Object resolved = map.get(unresolved);
+        if (resolved != null) {
+            
+            // Return the resolved object
+            return modelClass.cast(resolved);
+            
+        } else {
+            
+            // Return the unresolved object
+            return unresolved;
+        }
+    }
+    
+    public void addModel(Object resolved) {
+        map.put(resolved, resolved);
+    }
+    
+    public Object removeModel(Object resolved) {
+        return map.remove(resolved);
+    }
+    
+}

Propchange: incubator/tuscany/java/sca/modules/distributed/src/test/java/TestModelResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/distributed/src/test/java/TestModelResolver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/distributed/src/test/resources/default.node
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/test/resources/default.node?view=auto&rev=548839
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/test/resources/default.node (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/test/resources/default.node Tue Jun 19 13:12:46 2007
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+
+
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+           name="nodeA">
+    <component name="ComponentRegistry">
+        <implementation.java class="org.apache.tuscany.sca.distributed.node.impl.DefaultComponentRegistry"/>
+    </component>  
+</composite>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org