diff options
Diffstat (limited to 'sca-java-1.x/trunk/samples/domain-management')
20 files changed, 2079 insertions, 0 deletions
diff --git a/sca-java-1.x/trunk/samples/domain-management/README b/sca-java-1.x/trunk/samples/domain-management/README new file mode 100644 index 0000000000..540cbc3bc0 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/README @@ -0,0 +1,170 @@ +Domain Management Sample Tasks +============================== +This sample shows how to use a subset of Tuscany to read contribution metadata, +analyze and resolve contribution dependencies given a set of available contributions. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there first. + +Sample Overview +--------------- + +This sample demonstrates how to use some of the APIs for processing the contributions. +These APIs are currently used under the cover in the domain manager. + +domain-management/ + src/ + main/ + java/ + manager/ + DistributeAndRunComponents.java + DistributeComponents.java + ListComponents.java + ListDependencies.java + ListDeployables.java + WireComponents.java + resources/ + test/ + java/ + services/ + Cart.java + Item.java + ShoppingCartClientImpl.java + ShoppingCartImpl.java + resources/ + assembly/ + assets.xml + client.xml + store.xml + assets/ + META-INF/ + sca-contribution.xml + client/ + META-INF/ + client.composite + store/ + META-INF/ + sca-contribution.xml + store.composite + build.xml + pom.xml + README + +Building the Sample Using Maven +------------------------------------------- + +cd domain-management +mvn + +** Please note that the mvn command will just build the sample and will install the required jar files into the Maven repository. +** In order to run the sample, please see the instructions - "Running the Sample" + +Running the Sample +------------------ + +** Please make sure that sample is built using above build command(s). + +This sample implements following sample domain management tasks: + +1. List deployables in a contribution: + ------------------------------------ + + - This sample reads the SCA metadata for two sample contributions and prints the names of their deployable composites. + + - Use the following command to run the sample: + + On windows do: + java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-domain-management.jar manager.ListDeployables + + On *nix do: + java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-domain-management.jar manager.ListDeployables + + - You should see the following output: + + Deployable: {http://store}store + +2. List contribution dependencies: + -------------------------------- + + - The sample reads the SCA metadata for two sample contributions and prints their dependencies. + + - Use the following command to run the sample: + + On windows do: + java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-domain-management.jar manager.ListDependencies + + On *nix do: + java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-domain-management.jar manager.ListDependencies + + - You should see the following output: + + Contribution: store + dependency: assets + dependency: store + Contribution: assets + dependency: assets + +3. Add deployables to a domain composite and wire them: + ----------------------------------------------------- + + - The sample first reads the SCA metadata for three sample contributions, and resolve the artifacts contained in the contributions, + includes all their deployable composites in a composite model representing an SCA domain, and then + uses several composite builder utilities to configure and assemble and wire them together. + Finally it prints the resulting domain composite model, showing service bindings + configured with the URIs from the nodes hosting them. + + - Use the following command to run the sample: + + On windows do: + java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-domain-management.jar manager.WireComponents + + On *nix do: + java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-domain-management.jar manager.WireComponents + + - You should see the following output: + + <?xml version="1.0" encoding="UTF-8"?> + <composite name="domain" targetNamespace="http://sample" + xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:ns1="http://www.osoa.org/xmlns/sca/1.0"> + <component name="ShoppingCart" uri="ShoppingCart"> + <implementation.java class="services.ShoppingCartImpl"/> + <service name="Cart"> + <ns2:binding.atom name="Cart" uri="/ShoppingCart/Cart" xmlns:ns2="http://tuscany.apache.org/xmlns/sca/1.0"/> + </service> + </component> + <component name="ShoppingCartClient" uri="ShoppingCartClient"> + <implementation.java class="services.ShoppingCartClientImpl"/> + <service name="Cart"> + <ns2:binding.atom name="Cart" uri="/ShoppingCartClient/Cart" xmlns:ns2="http://tuscany.apache.org/xmlns/sca/1.0"/> + </service> + <reference name="cart"> + <ns2:binding.atom name="cart#ShoppingCart/Cart" + uri="/ShoppingCart/Cart" xmlns:ns2="http://tuscany.apache.org/xmlns/sca/1.0"/> + </reference> + </component> + </composite> + +4. List Components: + ----------------- + + - This sample reads the SCA metadata for two sample contributions, and displays their dependencies, reads and resolve + the artifacts contained in the contributions, and finally prints the deployables composites and the components + they declare as well as their main characteristics (showing that their interfaces and implementations are actually resolved). + + - Use the following command to run the sample: + + On windows do: + java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-domain-management.jar manager.ListComponents + + On *nix do: + java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-domain-management.jar manager.ListComponents + + - You should see the following output: + + Deployable: {http://store}store + component: ShoppingCart + componentService: Cart + binding: class org.apache.tuscany.sca.binding.atom.impl.AtomBindingImpl - /ShoppingCart/Cart + implementation: services.ShoppingCartImpl + service: Cart + interface: services.Cart diff --git a/sca-java-1.x/trunk/samples/domain-management/pom.xml b/sca-java-1.x/trunk/samples/domain-management/pom.xml new file mode 100644 index 0000000000..7bdd5f70f9 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/pom.xml @@ -0,0 +1,240 @@ +<?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. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca</artifactId> + <version>1.6-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + <artifactId>sample-domain-management</artifactId> + <name>Apache Tuscany SCA Sample Domain Management Tasks</name> + + <repositories> + <repository> + <id>apache.incubator</id> + <url>http://people.apache.org/repo/m2-incubating-repository</url> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xml</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution-xml</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-workspace</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-workspace-xml</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-workspace-impl</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-node</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-launcher</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-api</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-extensibility</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-monitor</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + <version>2.8.1</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-atom</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution-java</artifactId> + <version>1.6-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution-namespace</artifactId> + <version>1.6-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution-resource</artifactId> + <version>1.6-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-xml</artifactId> + <version>1.6-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface-java-xml</artifactId> + <version>1.6-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-data-api</artifactId> + <version>1.6-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.5</version> + <scope>test</scope> + </dependency> + + </dependencies> + + <build> + <finalName>${artifactId}</finalName> + <plugins> + <plugin> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-maven-ant-generator</artifactId> + <version>1.6-SNAPSHOT</version> + <executions> + <execution> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <id>assets</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <descriptors> + <descriptor>src/test/resources/assembly/assets.xml</descriptor> + </descriptors> + <tarLongFileMode>gnu</tarLongFileMode> + <finalName>${artifactId}</finalName> + </configuration> + </execution> + <execution> + <id>store</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <descriptors> + <descriptor>src/test/resources/assembly/store.xml</descriptor> + </descriptors> + <tarLongFileMode>gnu</tarLongFileMode> + <finalName>${artifactId}</finalName> + </configuration> + </execution> + <execution> + <id>client</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <descriptors> + <descriptor>src/test/resources/assembly/client.xml</descriptor> + </descriptors> + <tarLongFileMode>gnu</tarLongFileMode> + <finalName>${artifactId}</finalName> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java new file mode 100644 index 0000000000..83eff15a6a --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java @@ -0,0 +1,329 @@ +/* + * 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 manager; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.TransformerFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.binding.atom.AtomBindingFactory; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.implementation.node.NodeImplementation; +import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory; +import org.apache.tuscany.sca.implementation.node.builder.impl.NodeCompositeBuilderImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.launcher.NodeLauncher; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; +import org.apache.tuscany.sca.workspace.Workspace; +import org.apache.tuscany.sca.workspace.WorkspaceFactory; +import org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder; +import org.apache.tuscany.sca.workspace.builder.impl.ContributionDependencyBuilderImpl; +import org.apache.xml.serialize.OutputFormat; +import org.apache.xml.serialize.XMLSerializer; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +/** + * Sample RunComponents task + * + * Under construction... This sample is similar to the DistributeComponents sample, + * with extra steps to configure SCA runtime nodes with the models, start and stop + * them. + * + * @version $Rev$ $Date$ + */ +public class DistributeAndRunComponents { + private static ExtensionPointRegistry extensionPoints; + private static URLArtifactProcessor<Contribution> contributionProcessor; + private static ModelResolverExtensionPoint modelResolvers; + private static ModelFactoryExtensionPoint modelFactories; + private static WorkspaceFactory workspaceFactory; + private static AssemblyFactory assemblyFactory; + private static XMLOutputFactory outputFactory; + private static DocumentBuilderFactory documentBuilderFactory; + private static TransformerFactory transformerFactory; + private static StAXArtifactProcessor<Object> xmlProcessor; + private static ContributionDependencyBuilder contributionDependencyBuilder; + private static CompositeBuilder domainCompositeBuilder; + private static CompositeBuilder nodeCompositeBuilder; + private static NodeImplementationFactory nodeFactory; + private static AtomBindingFactory atomBindingFactory; + + private static void init() { + + // Create extension point registry + extensionPoints = new DefaultExtensionPointRegistry(); + + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + Monitor monitor = monitorFactory.createMonitor(); + + // Initialize the Tuscany module activators + ModuleActivatorExtensionPoint moduleActivators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class); + for (ModuleActivator activator: moduleActivators.getModuleActivators()) { + activator.start(extensionPoints); + } + + // Get XML input/output factories + modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); + outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); + transformerFactory = modelFactories.getFactory(TransformerFactory.class); + + // Get contribution workspace and assembly model factories + workspaceFactory = modelFactories.getFactory(WorkspaceFactory.class); + assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + nodeFactory = modelFactories.getFactory(NodeImplementationFactory.class); + atomBindingFactory = modelFactories.getFactory(AtomBindingFactory.class); + + // Create XML artifact processors + StAXArtifactProcessorExtensionPoint xmlProcessorExtensions = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + xmlProcessor = new ExtensibleStAXArtifactProcessor(xmlProcessorExtensions, inputFactory, outputFactory, monitor); + + // Create contribution content processor + URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class); + + // Get the model resolvers + modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); + + // Create a contribution dependency builder + contributionDependencyBuilder = new ContributionDependencyBuilderImpl(monitor); + + // Create a composite builder + SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + InterfaceContractMapper contractMapper = utilities.getUtility(InterfaceContractMapper.class); + Map<Binding, Binding> bindingMap = new HashMap<Binding, Binding>(); + domainCompositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, + documentBuilderFactory, transformerFactory, contractMapper, monitor, bindingMap); + + // Create a node composite builder + nodeCompositeBuilder = new NodeCompositeBuilderImpl(assemblyFactory, scaBindingFactory, + documentBuilderFactory, transformerFactory, contractMapper, null, monitor, bindingMap); + } + + + public static void main(String[] args) throws Exception { + init(); + + // Create workspace model + Workspace workspace = workspaceFactory.createWorkspace(); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); + + // Read the sample store contribution + URI storeURI = URI.create("store"); + URL storeURL = new File("./target/sample-domain-management-store.jar").toURI().toURL(); + Contribution storeContribution = contributionProcessor.read(null, storeURI, storeURL); + workspace.getContributions().add(storeContribution); + + // Read the sample assets contribution + URI assetsURI = URI.create("assets"); + URL assetsURL = new File("./target/sample-domain-management-assets.jar").toURI().toURL(); + Contribution assetsContribution = contributionProcessor.read(null, assetsURI, assetsURL); + workspace.getContributions().add(assetsContribution); + + // Read the sample client contribution + URI clientURI = URI.create("client"); + URL clientURL = new File("./target/sample-domain-management-client.jar").toURI().toURL(); + Contribution clientContribution = contributionProcessor.read(null, clientURI, clientURL); + workspace.getContributions().add(clientContribution); + + // Build the contribution dependencies + Map<Contribution, List<Contribution>> contributionDependencies = new HashMap<Contribution, List<Contribution>>(); + Set<Contribution> resolved = new HashSet<Contribution>(); + for (Contribution contribution: workspace.getContributions()) { + List<Contribution> dependencies = contributionDependencyBuilder.buildContributionDependencies(contribution, workspace); + + // Resolve contributions + for (Contribution dependency: dependencies) { + if (!resolved.contains(dependency)) { + resolved.add(dependency); + contributionProcessor.resolve(dependency, workspace.getModelResolver()); + } + } + + contributionDependencies.put(contribution, dependencies); + } + + // Create a set of nodes, and assign the sample deployables to them + Map<Component, List<Contribution>> nodeDependencies = new HashMap<Component, List<Contribution>>(); + Composite cloudComposite = assemblyFactory.createComposite(); + cloudComposite.setName(new QName("http://sample", "cloud")); + int nodeID = 8100; + for (Contribution contribution: workspace.getContributions()) { + for (Composite deployable: contribution.getDeployables()) { + + // Create a node + Component node = assemblyFactory.createComponent(); + node.setName("Node" + nodeID); + cloudComposite.getComponents().add(node); + + // Add default binding configuration to the node, our samples use + // Atom bindings so here we're just creating default Atom binding + // configurations, but all the other binding types can be configured + // like that too + ComponentService nodeService = assemblyFactory.createComponentService(); + Binding binding = atomBindingFactory.createAtomBinding(); + binding.setURI("http://localhost:" + (8100 + nodeID)); + nodeService.getBindings().add(binding); + node.getServices().add(nodeService); + + // Assign a deployable to the node + NodeImplementation nodeImplementation = nodeFactory.createNodeImplementation(); + nodeImplementation.setComposite(deployable); + node.setImplementation(nodeImplementation); + + // Keep track of what contributions will be needed by the node + nodeDependencies.put(node, contributionDependencies.get(contribution)); + + nodeID++; + } + } + + // Print the model describing the nodes that we just built + System.out.println("cloud.composite"); + System.out.println(print(cloudComposite)); + + // Build the nodes, this will apply their default binding configuration to the + // composites assigned to them + nodeCompositeBuilder.build(cloudComposite); + + // Create a composite model for the domain + Composite domainComposite = assemblyFactory.createComposite(); + domainComposite.setName(new QName("http://sample", "domain")); + + // Add all deployables to it, normally the domain administrator would select + // the deployables to include + domainComposite.getIncludes().addAll(workspace.getDeployables()); + + // Build the domain composite and wire the components included in it + domainCompositeBuilder.build(domainComposite); + + // Print out the resulting domain composite + System.out.println("domain.composite"); + System.out.println(print(domainComposite)); + + // Now start our SCA nodes + List<SCANode> runtimeNodes = new ArrayList<SCANode>(); + NodeLauncher launcher = NodeLauncher.newInstance(); + for (Component node: cloudComposite.getComponents()) { + + // Create a composite containing the components that we want to run + // on the node + Composite runnable = assemblyFactory.createComposite(); + runnable.setName(new QName("http://sample", node.getName())); + NodeImplementation nodeImplementation = (NodeImplementation)node.getImplementation(); + for (Component component: nodeImplementation.getComposite().getComponents()) { + for (Component configured: domainComposite.getComponents()) { + if (configured.getName().equals(component.getName())) { + runnable.getComponents().add(configured); + break; + } + } + } + + // Create the SCA node, give it the composite and the list of contributions + // to use + List<Contribution> dependencies = nodeDependencies.get(node); + org.apache.tuscany.sca.node.launcher.Contribution[] contributions = new org.apache.tuscany.sca.node.launcher.Contribution[dependencies.size()]; + for (int c =0, n = dependencies.size(); c < n; c++) { + Contribution dependency = dependencies.get(c); + contributions[c] = new org.apache.tuscany.sca.node.launcher.Contribution(dependency.getURI(), dependency.getLocation()); + } + SCANode runtimeNode = launcher.createNode("http://sample/" + node.getName(), print(runnable), contributions); + + // Start the node + runtimeNode.start(); + runtimeNodes.add(runtimeNode); + } + + System.out.println("Nodes are running, press enter to stop..."); + System.in.read(); + + for (SCANode runtimeNode: runtimeNodes) { + runtimeNode.stop(); + } + } + + private static String print(Composite composite) throws XMLStreamException, ContributionWriteException, ParserConfigurationException, SAXException, IOException { + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bos); + xmlProcessor.write(composite, writer); + + // Parse and write again to pretty format it + DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document document = documentBuilder.parse(new ByteArrayInputStream(bos.toByteArray())); + OutputFormat format = new OutputFormat(); + format.setIndenting(true); + format.setIndent(2); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + XMLSerializer serializer = new XMLSerializer(out, format); + serializer.serialize(document); + return out.toString(); + } +} diff --git a/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/DistributeComponents.java b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/DistributeComponents.java new file mode 100644 index 0000000000..090cd02f43 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/DistributeComponents.java @@ -0,0 +1,289 @@ +/* + * 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 manager; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.TransformerFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.binding.atom.AtomBindingFactory; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.implementation.node.NodeImplementation; +import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory; +import org.apache.tuscany.sca.implementation.node.builder.impl.NodeCompositeBuilderImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; +import org.apache.tuscany.sca.workspace.Workspace; +import org.apache.tuscany.sca.workspace.WorkspaceFactory; +import org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder; +import org.apache.tuscany.sca.workspace.builder.impl.ContributionDependencyBuilderImpl; +import org.apache.xml.serialize.OutputFormat; +import org.apache.xml.serialize.XMLSerializer; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +/** + * Sample DistributeComponents task + * + * This sample shows how to use a subset of Tuscany to read contribution + * metadata, analyze and resolve contribution dependencies, read and resolve + * the artifacts that they contribute (in particular implementation artifacts, + * interfaces, composites, componentTypes etc.) and assembe and wire the + * deployable composites together in a composite model representing an SCA + * domain composite. + * + * The difference between this sample and the WireComponents sample is an + * extra step to allocate deployable composites to SCA nodes. SCA nodes allow + * you to provide default configuration for the deploayable composites allocated + * to them, for example default binding configuration. + * + * The sample first reads the SCA metadata for three sample contributions, + * reads and resolve the artifacts contained in the contributions, includes all their + * deployable composites in a composite model representing an SCA domain, then + * uses several composite builder utilities to configure them as specified in the + * SCA nodes hosting them and assemble and wire them together. + * Finally it prints the resulting domain composite model, showing service bindings + * configured with the URIs from the nodes hosting them. + * + * @version $Rev$ $Date$ + */ +public class DistributeComponents { + private static ExtensionPointRegistry extensionPoints; + private static URLArtifactProcessor<Contribution> contributionProcessor; + private static ModelResolverExtensionPoint modelResolvers; + private static ModelFactoryExtensionPoint modelFactories; + private static WorkspaceFactory workspaceFactory; + private static AssemblyFactory assemblyFactory; + private static XMLOutputFactory outputFactory; + private static DocumentBuilderFactory documentBuilderFactory; + private static TransformerFactory transformerFactory; + private static StAXArtifactProcessor<Object> xmlProcessor; + private static ContributionDependencyBuilder contributionDependencyBuilder; + private static CompositeBuilder domainCompositeBuilder; + private static CompositeBuilder nodeCompositeBuilder; + private static NodeImplementationFactory nodeFactory; + private static AtomBindingFactory atomBindingFactory; + + private static void init() { + + // Create extension point registry + extensionPoints = new DefaultExtensionPointRegistry(); + + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + Monitor monitor = monitorFactory.createMonitor(); + + // Initialize the Tuscany module activators + ModuleActivatorExtensionPoint moduleActivators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class); + for (ModuleActivator activator: moduleActivators.getModuleActivators()) { + activator.start(extensionPoints); + } + + // Get XML input/output factories + modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); + outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); + transformerFactory = modelFactories.getFactory(TransformerFactory.class); + + // Get contribution workspace and assembly model factories + workspaceFactory = modelFactories.getFactory(WorkspaceFactory.class); + assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + nodeFactory = modelFactories.getFactory(NodeImplementationFactory.class); + atomBindingFactory = modelFactories.getFactory(AtomBindingFactory.class); + + // Create XML artifact processors + StAXArtifactProcessorExtensionPoint xmlProcessorExtensions = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + xmlProcessor = new ExtensibleStAXArtifactProcessor(xmlProcessorExtensions, inputFactory, outputFactory, monitor); + + // Create contribution content processor + URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class); + + // Get the model resolvers + modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); + + // Create a contribution dependency builder + contributionDependencyBuilder = new ContributionDependencyBuilderImpl(monitor); + + // Create a composite builder + SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + InterfaceContractMapper contractMapper = utilities.getUtility(InterfaceContractMapper.class); + Map<Binding, Binding> bindingMap = new HashMap<Binding, Binding>(); + domainCompositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, + documentBuilderFactory, transformerFactory, contractMapper, monitor, bindingMap); + + // Create a node composite builder + nodeCompositeBuilder = new NodeCompositeBuilderImpl(assemblyFactory, scaBindingFactory, + documentBuilderFactory, transformerFactory, contractMapper, null, monitor, bindingMap); + } + + + public static void main(String[] args) throws Exception { + init(); + + // Create workspace model + Workspace workspace = workspaceFactory.createWorkspace(); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); + + // Read the sample store contribution + URI storeURI = URI.create("store"); + URL storeURL = new File("./target/sample-domain-management-store.jar").toURI().toURL(); + Contribution storeContribution = contributionProcessor.read(null, storeURI, storeURL); + workspace.getContributions().add(storeContribution); + + // Read the sample assets contribution + URI assetsURI = URI.create("assets"); + URL assetsURL = new File("./target/sample-domain-management-assets.jar").toURI().toURL(); + Contribution assetsContribution = contributionProcessor.read(null, assetsURI, assetsURL); + workspace.getContributions().add(assetsContribution); + + // Read the sample client contribution + URI clientURI = URI.create("client"); + URL clientURL = new File("./target/sample-domain-management-client.jar").toURI().toURL(); + Contribution clientContribution = contributionProcessor.read(null, clientURI, clientURL); + workspace.getContributions().add(clientContribution); + + // Build the contribution dependencies + Set<Contribution> resolved = new HashSet<Contribution>(); + for (Contribution contribution: workspace.getContributions()) { + List<Contribution> dependencies = contributionDependencyBuilder.buildContributionDependencies(contribution, workspace); + + // Resolve contributions + for (Contribution dependency: dependencies) { + if (!resolved.contains(dependency)) { + resolved.add(dependency); + contributionProcessor.resolve(dependency, workspace.getModelResolver()); + } + } + } + + // Create a set of nodes, and assign the sample deployables to them + Composite cloudComposite = assemblyFactory.createComposite(); + cloudComposite.setName(new QName("http://sample", "cloud")); + for (int i = 0, n = workspace.getDeployables().size(); i < n; i++) { + + // Create a node + Component node = assemblyFactory.createComponent(); + node.setName("Node" + i); + cloudComposite.getComponents().add(node); + + // Add default binding configuration to the node, our samples use + // Atom bindings so here we're just creating default Atom binding + // configurations, but all the other binding types can be configured + // like that too + ComponentService nodeService = assemblyFactory.createComponentService(); + Binding binding = atomBindingFactory.createAtomBinding(); + binding.setURI("http://localhost:" + (8100 + i)); + nodeService.getBindings().add(binding); + node.getServices().add(nodeService); + + // Assign a deployable to the node + NodeImplementation nodeImplementation = nodeFactory.createNodeImplementation(); + Composite deployable = workspace.getDeployables().get(i); + nodeImplementation.setComposite(deployable); + node.setImplementation(nodeImplementation); + } + + // Print the model describing the nodes that we just built + System.out.println("cloud.composite"); + print(cloudComposite); + System.out.println(); + + // Build the nodes, this will apply their default binding configuration to the + // composites assigned to them + nodeCompositeBuilder.build(cloudComposite); + + // Create a composite model for the domain + Composite domainComposite = assemblyFactory.createComposite(); + domainComposite.setName(new QName("http://sample", "domain")); + + // Add all deployables to it, normally the domain administrator would select + // the deployables to include + domainComposite.getIncludes().addAll(workspace.getDeployables()); + + // Build the domain composite and wire the components included in it + domainCompositeBuilder.build(domainComposite); + + // Print out the resulting domain composite + System.out.println("domain.composite"); + print(domainComposite); + } + + private static void print(Composite composite) throws XMLStreamException, ContributionWriteException, ParserConfigurationException, SAXException, IOException { + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bos); + xmlProcessor.write(composite, writer); + + // Parse and write again to pretty format it + DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document document = documentBuilder.parse(new ByteArrayInputStream(bos.toByteArray())); + OutputFormat format = new OutputFormat(); + format.setIndenting(true); + format.setIndent(2); + XMLSerializer serializer = new XMLSerializer(System.out, format); + serializer.serialize(document); + } +} diff --git a/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/ListComponents.java b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/ListComponents.java new file mode 100644 index 0000000000..7b3950833a --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/ListComponents.java @@ -0,0 +1,158 @@ +/* + * 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 manager; + +import java.io.File; +import java.net.URI; +import java.net.URL; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +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.ModuleActivator; +import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.workspace.Workspace; +import org.apache.tuscany.sca.workspace.WorkspaceFactory; +import org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder; +import org.apache.tuscany.sca.workspace.builder.impl.ContributionDependencyBuilderImpl; + +/** + * Sample ListComponents task. + * + * This sample shows how to use subset of Tuscany to read contribution + * metadata, analyze and resolve contribution dependencies, read and resolve + * the artifacts that they contribute (in particular implementation artifacts, + * interfaces, composites and componentTypes). + * + * The sample first reads the SCA metadata for two sample contributions, then displays + * their dependencies, reads and resolve the artifacts contained in the contributions, + * and finally prints the deployables composites and the components they declare as + * well as their main characteristics (showing that their interfaces and implementations + * for example are actually resolved). + * + * @version $Rev$ $Date$ + */ +public class ListComponents { + private static ExtensionPointRegistry extensionPoints; + private static URLArtifactProcessor<Contribution> contributionProcessor; + private static ModelResolverExtensionPoint modelResolvers; + private static ModelFactoryExtensionPoint modelFactories; + private static WorkspaceFactory workspaceFactory; + private static ContributionDependencyBuilder contributionDependencyBuilder; + + private static void init() { + + // Create extension point registry + extensionPoints = new DefaultExtensionPointRegistry(); + + // Initialize the Tuscany module activators + ModuleActivatorExtensionPoint moduleActivators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class); + for (ModuleActivator activator: moduleActivators.getModuleActivators()) { + activator.start(extensionPoints); + } + + // Get workspace contribution factory + modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + workspaceFactory = modelFactories.getFactory(WorkspaceFactory.class); + + // Create contribution content processor + URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class); + + // Get the model resolvers + modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); + + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + Monitor monitor = monitorFactory.createMonitor(); + + // Create a contribution dependency builder + contributionDependencyBuilder = new ContributionDependencyBuilderImpl(monitor); + } + + + public static void main(String[] args) throws Exception { + init(); + + // Create workspace model + Workspace workspace = workspaceFactory.createWorkspace(); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); + + // Read the sample store contribution + URI storeURI = URI.create("store"); + URL storeURL = new File("./target/sample-domain-management-store.jar").toURI().toURL(); + Contribution storeContribution = contributionProcessor.read(null, storeURI, storeURL); + workspace.getContributions().add(storeContribution); + + // Read the sample assets contribution + URI assetsURI = URI.create("assets"); + URL assetsURL = new File("./target/sample-domain-management-assets.jar").toURI().toURL(); + Contribution assetsContribution = contributionProcessor.read(null, assetsURI, assetsURL); + workspace.getContributions().add(assetsContribution); + + // Build the store contribution dependencies + List<Contribution> dependencies = contributionDependencyBuilder.buildContributionDependencies(storeContribution, workspace); + + // Resolve the contributions + for (Contribution contribution: dependencies) { + contributionProcessor.resolve(contribution, workspace.getModelResolver()); + } + + // List the components declared in the deployables found in the + // contribution, their services, bindings, interfaces, and implementations + for (Composite deployable: storeContribution.getDeployables()) { + System.out.println("Deployable: " + deployable.getName()); + for (Component component: deployable.getComponents()) { + System.out.println(" component: " + component.getName()); + for (ComponentService componentService: component.getServices()) { + System.out.println(" componentService: " + componentService.getName()); + for (Binding binding: componentService.getBindings()) { + System.out.println(" binding: " + binding.getClass() + " - " + binding.getURI()); + } + } + Implementation implementation = component.getImplementation(); + System.out.println(" implementation: " + implementation); + for (Service service: implementation.getServices()) { + System.out.println(" service: " + service.getName()); + InterfaceContract contract = service.getInterfaceContract(); + System.out.println(" interface: " + contract.getInterface()); + } + } + } + } + +} diff --git a/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/ListDependencies.java b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/ListDependencies.java new file mode 100644 index 0000000000..1bf8124682 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/ListDependencies.java @@ -0,0 +1,108 @@ +/* + * 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 manager; + +import java.io.File; +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.workspace.Workspace; +import org.apache.tuscany.sca.workspace.WorkspaceFactory; +import org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder; +import org.apache.tuscany.sca.workspace.builder.impl.ContributionDependencyBuilderImpl; + +/** + * Sample ListDependencies task. + * + * This sample shows how to use a subset of Tuscany to read contribution + * metadata, analyze and resolve contribution dependencies given a set of + * available contributions. + * + * The sample reads the SCA metadata for two sample contributions then + * prints their dependencies. + * + * @version $Rev$ $Date$ + */ +public class ListDependencies { + + private static URLArtifactProcessor<Contribution> contributionProcessor; + private static WorkspaceFactory workspaceFactory; + private static ContributionDependencyBuilder contributionDependencyBuilder; + + private static void init() throws Exception { + + // Create extension point registry + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + + // Get contribution, workspace and assembly model factories + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + workspaceFactory = modelFactories.getFactory(WorkspaceFactory.class); + + // Create contribution info processor + URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class); + + // Create a monitor + UtilityExtensionPoint services = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = services.getUtility(MonitorFactory.class); + Monitor monitor = monitorFactory.createMonitor(); + + // Create a contribution dependency builder + contributionDependencyBuilder = new ContributionDependencyBuilderImpl(monitor); + } + + + public static void main(String[] args) throws Exception { + init(); + + // Create workspace model + Workspace workspace = workspaceFactory.createWorkspace(); + + // Read the contribution info for the sample contribution + URI storeURI = URI.create("store"); + URL storeURL = new File("./target/sample-domain-management-store.jar").toURI().toURL(); + Contribution storeContribution = (Contribution)contributionProcessor.read(null, storeURI, storeURL); + workspace.getContributions().add(storeContribution); + + // Read the contribution info for the assets contribution + URI assetsURI = URI.create("assets"); + URL assetsURL = new File("./target/sample-domain-management-assets.jar").toURI().toURL(); + Contribution assetsContribution = contributionProcessor.read(null, assetsURI, assetsURL); + workspace.getContributions().add(assetsContribution); + + // List the contribution dependencies of each contribution + for (Contribution contribution: workspace.getContributions()) { + System.out.println("Contribution: " + contribution.getURI()); + for (Contribution dependency: contributionDependencyBuilder.buildContributionDependencies(contribution, workspace)) { + System.out.println(" dependency: " + dependency.getURI()); + } + } + } + +} diff --git a/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/ListDeployables.java b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/ListDeployables.java new file mode 100644 index 0000000000..f5f0b9c655 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/ListDeployables.java @@ -0,0 +1,73 @@ +/* + * 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 manager; + +import java.io.File; +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * Sample ListDeployables task. + * + * This sample shows how to use a subset of Tuscany to read contribution + * metadata. + * + * The sample reads the SCA metadata for two sample contributions then + * prints the names of their deployable composites. + * + * @version $Rev$ $Date$ + */ +public class ListDeployables { + + private static URLArtifactProcessor<Contribution> contributionProcessor; + + private static void init() { + + // Create extension point registry + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + + // Create contribution info processor + URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class); + } + + public static void main(String[] args) throws Exception { + init(); + + // Read the contribution info for the sample contribution + URI uri = URI.create("store"); + URL url = new File("./target/sample-domain-management-store.jar").toURI().toURL(); + Contribution contribution = contributionProcessor.read(null, uri, url); + + // List the deployables in the contribution + for (Composite deployable: contribution.getDeployables()) { + System.out.println("Deployable: " + deployable.getName()); + } + + } + +} diff --git a/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/WireComponents.java b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/WireComponents.java new file mode 100644 index 0000000000..16cda9d3e7 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/main/java/manager/WireComponents.java @@ -0,0 +1,218 @@ +/* + * 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 manager; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.net.URI; +import java.net.URL; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.TransformerFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +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.ModuleActivator; +import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; +import org.apache.tuscany.sca.workspace.Workspace; +import org.apache.tuscany.sca.workspace.WorkspaceFactory; +import org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder; +import org.apache.tuscany.sca.workspace.builder.impl.ContributionDependencyBuilderImpl; +import org.apache.xml.serialize.OutputFormat; +import org.apache.xml.serialize.XMLSerializer; +import org.w3c.dom.Document; + +/** + * Sample WireComponents task. + * + * This sample shows how to use a subset of Tuscany to read contribution + * metadata, analyze and resolve contribution dependencies, read and resolve + * the artifacts that they contribute (in particular implementation artifacts, + * interfaces, composites, componentTypes etc.) and assembe and wire the + * deployable composites together in a composite model representing an SCA + * domain composite. + * + * The sample first reads the SCA metadata for three sample contributions, + * reads and resolve the artifacts contained in the contributions, includes all their + * deployable composites in a composite model representing an SCA domain, then + * uses a composite builder utility to assemble and wire the composites together. + * Finally it prints the resulting domain composite model. + * + * @version $Rev$ $Date$ + */ +public class WireComponents { + private static ExtensionPointRegistry extensionPoints; + private static URLArtifactProcessor<Contribution> contributionProcessor; + private static ModelResolverExtensionPoint modelResolvers; + private static ModelFactoryExtensionPoint modelFactories; + private static WorkspaceFactory workspaceFactory; + private static AssemblyFactory assemblyFactory; + private static XMLOutputFactory outputFactory; + private static DocumentBuilderFactory documentBuilderFactory; + private static TransformerFactory transformerFactory; + private static StAXArtifactProcessor<Object> xmlProcessor; + private static ContributionDependencyBuilder contributionDependencyBuilder; + private static CompositeBuilder domainCompositeBuilder; + + private static void init() { + + // Create extension point registry + extensionPoints = new DefaultExtensionPointRegistry(); + + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + Monitor monitor = monitorFactory.createMonitor(); + + // Initialize the Tuscany module activators + ModuleActivatorExtensionPoint moduleActivators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class); + for (ModuleActivator activator: moduleActivators.getModuleActivators()) { + activator.start(extensionPoints); + } + + // Get XML input/output factories + modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); + outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); + transformerFactory = modelFactories.getFactory(TransformerFactory.class); + + // Get contribution workspace and assembly model factories + workspaceFactory = modelFactories.getFactory(WorkspaceFactory.class); + assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + + // Create XML artifact processors + StAXArtifactProcessorExtensionPoint xmlProcessorExtensions = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + xmlProcessor = new ExtensibleStAXArtifactProcessor(xmlProcessorExtensions, inputFactory, outputFactory, monitor); + + // Create contribution content processor + URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class); + + // Get the model resolvers + modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); + + // Create a contribution dependency builder + contributionDependencyBuilder = new ContributionDependencyBuilderImpl(monitor); + + // Create a composite builder + SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + InterfaceContractMapper contractMapper = utilities.getUtility(InterfaceContractMapper.class); + domainCompositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, + documentBuilderFactory, transformerFactory, contractMapper, monitor); + + } + + + public static void main(String[] args) throws Exception { + init(); + + // Create workspace model + Workspace workspace = workspaceFactory.createWorkspace(); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); + + // Read the sample store contribution + URI storeURI = URI.create("store"); + URL storeURL = new File("./target/sample-domain-management-store.jar").toURI().toURL(); + Contribution storeContribution = contributionProcessor.read(null, storeURI, storeURL); + workspace.getContributions().add(storeContribution); + + // Read the sample assets contribution + URI assetsURI = URI.create("assets"); + URL assetsURL = new File("./target/sample-domain-management-assets.jar").toURI().toURL(); + Contribution assetsContribution = contributionProcessor.read(null, assetsURI, assetsURL); + workspace.getContributions().add(assetsContribution); + + // Read the sample client contribution + URI clientURI = URI.create("client"); + URL clientURL = new File("./target/sample-domain-management-client.jar").toURI().toURL(); + Contribution clientContribution = contributionProcessor.read(null, clientURI, clientURL); + workspace.getContributions().add(clientContribution); + + // Build the contribution dependencies + Set<Contribution> resolved = new HashSet<Contribution>(); + for (Contribution contribution: workspace.getContributions()) { + List<Contribution> dependencies = contributionDependencyBuilder.buildContributionDependencies(contribution, workspace); + + // Resolve contributions + for (Contribution dependency: dependencies) { + if (!resolved.contains(dependency)) { + resolved.add(dependency); + contributionProcessor.resolve(contribution, workspace.getModelResolver()); + } + } + } + + // Create a composite model for the domain + Composite domainComposite = assemblyFactory.createComposite(); + domainComposite.setName(new QName("http://sample", "domain")); + + // Add all deployables to it, normally the domain administrator would select + // the deployables to include + domainComposite.getIncludes().addAll(workspace.getDeployables()); + + // Build the domain composite and wire the components included in it + domainCompositeBuilder.build(domainComposite); + + // Print out the resulting domain composite + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bos); + xmlProcessor.write(domainComposite, writer); + + // Parse and write again to pretty format it + DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document document = documentBuilder.parse(new ByteArrayInputStream(bos.toByteArray())); + OutputFormat format = new OutputFormat(); + format.setIndenting(true); + format.setIndent(2); + XMLSerializer serializer = new XMLSerializer(System.out, format); + serializer.serialize(document); + } + +} diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/Cart.java b/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/Cart.java new file mode 100644 index 0000000000..9e6226d963 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/Cart.java @@ -0,0 +1,28 @@ +/* + * 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 services; + +import org.apache.tuscany.sca.data.collection.Collection; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Cart extends Collection<String, Item> { + +} diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/Item.java b/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/Item.java new file mode 100644 index 0000000000..81cefcdbef --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/Item.java @@ -0,0 +1,66 @@ +/* + * 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 services; + + +public class Item { + private String name; + private String price; + private String origin; + + public Item() { + } + + public Item(String name, String price, String origin) { + this.name = name; + this.price = price; + this.origin = origin; + } + + public Item(String name, String price) { + this.name = name; + this.price = price; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + + public String getOrigin() { + return origin; + } + + public void setOrigin(String origin) { + this.origin = origin; + } + +} diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/ShoppingCartClientImpl.java b/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/ShoppingCartClientImpl.java new file mode 100644 index 0000000000..c32853b3a9 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/ShoppingCartClientImpl.java @@ -0,0 +1,57 @@ +/* + * 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 services; + +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class ShoppingCartClientImpl implements Cart { + + @Reference + public Cart cart; + + public Entry<String, Item>[] getAll() { + return cart.getAll(); + } + + public Item get(String key) throws NotFoundException { + return cart.get(key); + } + + public String post(String key, Item item) { + return cart.post(key, item); + } + + public void put(String key, Item item) throws NotFoundException { + cart.put(key, item); + } + + public void delete(String key) throws NotFoundException { + cart.delete(key); + } + + public Entry<String, Item>[] query(String queryString) { + return cart.query(queryString); + } + +} diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/ShoppingCartImpl.java b/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/ShoppingCartImpl.java new file mode 100644 index 0000000000..30abfe77a0 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/java/services/ShoppingCartImpl.java @@ -0,0 +1,100 @@ +/* + * 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 services; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class ShoppingCartImpl implements Cart { + + private Map<String, Item> cart; + + @Init + public void init() { + cart = new HashMap<String, Item>(); + } + + public Entry<String, Item>[] getAll() { + Entry<String, Item>[] entries = new Entry[cart.size()]; + int i = 0; + for (Map.Entry<String, Item> e: cart.entrySet()) { + entries[i++] = new Entry<String, Item>(e.getKey(), e.getValue()); + } + return entries; + } + + public Item get(String key) throws NotFoundException { + Item item = cart.get(key); + if (item == null) { + throw new NotFoundException(key); + } else { + return item; + } + } + + public String post(String key, Item item) { + if (key == null) { + key ="cart-" + UUID.randomUUID().toString(); + } + cart.put(key, item); + return key; + } + + public void put(String key, Item item) throws NotFoundException { + if (!cart.containsKey(key)) { + throw new NotFoundException(key); + } + cart.put(key, item); + } + + public void delete(String key) throws NotFoundException { + if (key == null || key.equals("")) { + cart.clear(); + } else { + Item item = cart.remove(key); + if (item == null) + throw new NotFoundException(key); + } + } + + public Entry<String, Item>[] query(String queryString) { + List<Entry<String, Item>> entries = new ArrayList<Entry<String,Item>>(); + if (queryString.startsWith("name=")) { + String name = queryString.substring(5); + for (Map.Entry<String, Item> e: cart.entrySet()) { + Item item = e.getValue(); + if (item.getName().equals(name)) { + entries.add(new Entry<String, Item>(e.getKey(), e.getValue())); + } + } + } + return entries.toArray(new Entry[entries.size()]); + } + +} diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assembly/assets.xml b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assembly/assets.xml new file mode 100644 index 0000000000..10693a89e6 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assembly/assets.xml @@ -0,0 +1,38 @@ +<?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. +--> +<assembly> + <id>assets</id> + <includeBaseDirectory>false</includeBaseDirectory> + <formats> + <format>jar</format> + </formats> + + <fileSets> + <fileSet> + <directory>target/test-classes/assets</directory> + <outputDirectory>/</outputDirectory> + </fileSet> + <fileSet> + <directory>target/test-classes/services</directory> + <outputDirectory>/services</outputDirectory> + </fileSet> + </fileSets> + +</assembly> diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assembly/client.xml b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assembly/client.xml new file mode 100644 index 0000000000..5b34693bee --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assembly/client.xml @@ -0,0 +1,34 @@ +<?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. +--> +<assembly> + <id>client</id> + <includeBaseDirectory>false</includeBaseDirectory> + <formats> + <format>jar</format> + </formats> + + <fileSets> + <fileSet> + <directory>target/test-classes/client</directory> + <outputDirectory>/</outputDirectory> + </fileSet> + </fileSets> + +</assembly> diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assembly/store.xml b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assembly/store.xml new file mode 100644 index 0000000000..d19b7eb161 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assembly/store.xml @@ -0,0 +1,34 @@ +<?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. +--> +<assembly> + <id>store</id> + <includeBaseDirectory>false</includeBaseDirectory> + <formats> + <format>jar</format> + </formats> + + <fileSets> + <fileSet> + <directory>target/test-classes/store</directory> + <outputDirectory>/</outputDirectory> + </fileSet> + </fileSets> + +</assembly> diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assets/META-INF/sca-contribution.xml b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assets/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..33fe814c3a --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/assets/META-INF/sca-contribution.xml @@ -0,0 +1,22 @@ +<?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. +--> +<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"> + <export.java package="services"/> +</contribution>
\ No newline at end of file diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/resources/client/META-INF/sca-contribution.xml b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/client/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..14e1cdb672 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/client/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ +<?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. +--> +<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:s="http://store"> + <import.java package="services"/> + <deployable composite="s:client"/> +</contribution>
\ No newline at end of file diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/resources/client/client.composite b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/client/client.composite new file mode 100644 index 0000000000..1279b319c4 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/client/client.composite @@ -0,0 +1,35 @@ +<?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"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0" + targetNamespace="http://store" + name="client"> + + <component name="ShoppingCartClient">
+ <implementation.java class="services.ShoppingCartClientImpl"/> + <service name="Cart"> + <t:binding.atom uri="/ShoppingCartClient/Cart"/> + </service> + <reference name="cart" target="ShoppingCart"> + <t:binding.atom/> + </reference>
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/resources/store/META-INF/sca-contribution.xml b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/store/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..52348106f2 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/store/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ +<?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. +--> +<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:s="http://store"> + <import.java package="services"/> + <deployable composite="s:store"/> +</contribution>
\ No newline at end of file diff --git a/sca-java-1.x/trunk/samples/domain-management/src/test/resources/store/store.composite b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/store/store.composite new file mode 100644 index 0000000000..d4f18771d8 --- /dev/null +++ b/sca-java-1.x/trunk/samples/domain-management/src/test/resources/store/store.composite @@ -0,0 +1,32 @@ +<?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"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0" + targetNamespace="http://store" + name="store"> + + <component name="ShoppingCart">
+ <implementation.java class="services.ShoppingCartImpl"/>
+ <service name="Cart">
+ <t:binding.atom uri="/ShoppingCart/Cart"/>
+ </service>
+ </component>
+
+</composite>
|