From 9ffd76a9e84f4addb400367d9a2582dffff0d109 Mon Sep 17 00:00:00 2001 From: rfeng Date: Mon, 11 May 2009 22:34:11 +0000 Subject: Add default impl and processor for the node configuration git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@773715 13f79535-47bb-0310-9956-ffa450edef68 --- .../node/configuration/BindingConfiguration.java | 2 +- .../configuration/ContributionConfiguration.java | 22 +++ .../DefaultNodeConfigurationFactory.java | 28 +++ .../node/configuration/DeploymentComposite.java | 29 +++- .../sca/node/configuration/NodeConfiguration.java | 4 +- .../configuration/NodeConfigurationFactory.java | 16 ++ .../impl/BindingConfigurationImpl.java | 48 ++++++ .../impl/ContributionConfigurationImpl.java | 85 +++++++++ .../impl/DeploymentCompositeImpl.java | 67 ++++++++ .../impl/NodeConfigurationFactoryImpl.java | 62 +++++++ .../configuration/impl/NodeConfigurationImpl.java | 63 +++++++ .../xml/NodeConfigurationProcessor.java | 190 +++++++++++++++++++++ .../tuscany/sca/node/configuration/node1.xml | 25 +-- .../tuscany/sca/node/configuration/node2.xml | 5 +- 14 files changed, 624 insertions(+), 22 deletions(-) create mode 100644 java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/DefaultNodeConfigurationFactory.java create mode 100644 java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/BindingConfigurationImpl.java create mode 100644 java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/ContributionConfigurationImpl.java create mode 100644 java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/DeploymentCompositeImpl.java create mode 100644 java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationFactoryImpl.java create mode 100644 java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java create mode 100644 java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/BindingConfiguration.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/BindingConfiguration.java index ecd6ec513f..489a3fd2e3 100644 --- a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/BindingConfiguration.java +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/BindingConfiguration.java @@ -34,7 +34,7 @@ public interface BindingConfiguration { QName getBindingType(); /** - * + * Set the type of the binding * @param type */ void setBindingType(QName type); diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/ContributionConfiguration.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/ContributionConfiguration.java index a408ae0716..7d75cb32ac 100644 --- a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/ContributionConfiguration.java +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/ContributionConfiguration.java @@ -19,6 +19,10 @@ package org.apache.tuscany.sca.node.configuration; +import java.util.List; + +import org.apache.tuscany.sca.contribution.Contribution; + /** * Configuration for an SCA contribution used by the SCA node */ @@ -46,4 +50,22 @@ public interface ContributionConfiguration { * @param location The location of the contribution */ void setLocation(String location); + + /** + * Get the contribution + * @return + */ + Contribution getContribution(); + + /** + * Set the contribution + * @param contribution + */ + void setContribution(Contribution contribution); + + /** + * Get the list of deployment composites that are attached to the contribution + * @return + */ + List getDeploymentComposites(); } diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/DefaultNodeConfigurationFactory.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/DefaultNodeConfigurationFactory.java new file mode 100644 index 0000000000..a14a4ac9eb --- /dev/null +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/DefaultNodeConfigurationFactory.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 org.apache.tuscany.sca.node.configuration; + +import org.apache.tuscany.sca.node.configuration.impl.NodeConfigurationFactoryImpl; + +/** + * Default NodeConfigurationFactory + */ +public class DefaultNodeConfigurationFactory extends NodeConfigurationFactoryImpl { +} diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/DeploymentComposite.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/DeploymentComposite.java index d94c70a759..09bf3ee0ef 100644 --- a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/DeploymentComposite.java +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/DeploymentComposite.java @@ -19,6 +19,9 @@ package org.apache.tuscany.sca.node.configuration; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; + /** * Configuration for a deployment composite */ @@ -42,18 +45,34 @@ public interface DeploymentComposite { */ String getContent(); + /** + * Set the XML content for the composite + * @param compositeXML + */ void setContent(String compositeXML); /** - * Get the URI of the owning contribution + * Get the composite + * @return + */ + Composite getComposite(); + + /** + * Set the composite + * @param composite + */ + void setComposite(Composite composite); + + /** + * Get the contribution that this deployment composite is attached to * @return */ - String getContributionURI(); + Contribution getContribution(); /** - * Set the URI of the owning contribution - * @param contributionURI + * Set the contribution that this deployment composite is attached to + * @param contribution */ - void setContributionURI(String contributionURI); + void setContribution(Contribution contribution); } diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java index bd1d9aebb0..c546b1e412 100644 --- a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java @@ -29,9 +29,9 @@ public interface NodeConfiguration { void setDomainURI(String domainURI); - DeploymentComposite getDeploymentComposite(); + String getURI(); - void setDeploymentComposite(DeploymentComposite deploymentComposite); + void setURI(String uri); List getContributions(); diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfigurationFactory.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfigurationFactory.java index e20fef27c1..ca1afee923 100644 --- a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfigurationFactory.java +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfigurationFactory.java @@ -23,11 +23,27 @@ package org.apache.tuscany.sca.node.configuration; * The factory to create java models related to the node configuration */ public interface NodeConfigurationFactory { + /** + * Create a new instance of NodeConfiguration + * @return + */ NodeConfiguration createNodeConfiguration(); + /** + * Create a new instance of ContributionConfiguration + * @return + */ ContributionConfiguration createContributionConfiguration(); + /** + * Create a new instance of BindingConfiguration + * @return + */ BindingConfiguration createBindingConfiguration(); + /** + * Create a new instance of DeploymentComposite + * @return + */ DeploymentComposite createDeploymentComposite(); } diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/BindingConfigurationImpl.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/BindingConfigurationImpl.java new file mode 100644 index 0000000000..eb5ac2915b --- /dev/null +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/BindingConfigurationImpl.java @@ -0,0 +1,48 @@ +/* + * 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.node.configuration.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.node.configuration.BindingConfiguration; + +/** + * + */ +class BindingConfigurationImpl implements BindingConfiguration { + private QName type; + private List baseURIs = new ArrayList(); + + public List getBaseURIs() { + return baseURIs; + } + + public QName getBindingType() { + return type; + } + + public void setBindingType(QName type) { + this.type = type; + } + +} diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/ContributionConfigurationImpl.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/ContributionConfigurationImpl.java new file mode 100644 index 0000000000..1793a99cc1 --- /dev/null +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/ContributionConfigurationImpl.java @@ -0,0 +1,85 @@ +/* + * 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.node.configuration.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; +import org.apache.tuscany.sca.node.configuration.DeploymentComposite; + +/** + * Configuration for an SCA contribution used by the SCA node + */ +class ContributionConfigurationImpl implements ContributionConfiguration { + private List deploymentComposites = new ArrayList(); + private Contribution contribution; + private String uri; + private String location; + + public Contribution getContribution() { + return contribution; + } + + public void setContribution(Contribution contribution) { + this.contribution = contribution; + } + + /** + * Get the URI of the contribution + * @return The URI of the contribution + */ + public String getURI() { + return uri; + } + + /** + * Set the URI of the contribution + * @param uri The URI of the contribution + */ + public void setURI(String uri) { + this.uri = uri; + } + + /** + * Get the location of the contribution + * @return The location of the contribution + */ + public String getLocation() { + return location; + } + + /** + * Set the location of the contribution + * @param location The location of the contribution + */ + public void setLocation(String location) { + this.location = location; + } + + /** + * Get the list of deployment composites that are attached to the contribution + * @return + */ + public List getDeploymentComposites() { + return deploymentComposites; + } +} diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/DeploymentCompositeImpl.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/DeploymentCompositeImpl.java new file mode 100644 index 0000000000..7113ad0d36 --- /dev/null +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/DeploymentCompositeImpl.java @@ -0,0 +1,67 @@ +/* + * 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.node.configuration.impl; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.node.configuration.DeploymentComposite; + +/** + * Configuration for a deployment composite + */ +class DeploymentCompositeImpl implements DeploymentComposite { + private String location; + private String content; + private Composite composite; + private Contribution contribution; + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Composite getComposite() { + return composite; + } + + public void setComposite(Composite composite) { + this.composite = composite; + } + + public Contribution getContribution() { + return contribution; + } + + public void setContribution(Contribution contribution) { + this.contribution = contribution; + } + +} diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationFactoryImpl.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationFactoryImpl.java new file mode 100644 index 0000000000..96ca3e6199 --- /dev/null +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationFactoryImpl.java @@ -0,0 +1,62 @@ +/* + * 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.node.configuration.impl; + +import org.apache.tuscany.sca.node.configuration.BindingConfiguration; +import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; +import org.apache.tuscany.sca.node.configuration.DeploymentComposite; +import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory; + +/** + * The factory to create java models related to the node configuration + */ +public abstract class NodeConfigurationFactoryImpl implements NodeConfigurationFactory { + /** + * Create a new instance of NodeConfiguration + * @return + */ + public NodeConfigurationImpl createNodeConfiguration() { + return new NodeConfigurationImpl(); + } + + /** + * Create a new instance of ContributionConfiguration + * @return + */ + public ContributionConfiguration createContributionConfiguration() { + return new ContributionConfigurationImpl(); + } + + /** + * Create a new instance of BindingConfiguration + * @return + */ + public BindingConfiguration createBindingConfiguration() { + return new BindingConfigurationImpl(); + } + + /** + * Create a new instance of DeploymentComposite + * @return + */ + public DeploymentComposite createDeploymentComposite() { + return new DeploymentCompositeImpl(); + } +} diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java new file mode 100644 index 0000000000..4f13959ced --- /dev/null +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java @@ -0,0 +1,63 @@ +/* + * 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.node.configuration.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.node.configuration.BindingConfiguration; +import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; + +/** + * + */ +class NodeConfigurationImpl implements NodeConfiguration { + private String uri; + private String domainURI; + private List contributions = new ArrayList(); + private List bindings = new ArrayList(); + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public String getDomainURI() { + return domainURI; + } + + public void setDomainURI(String domainURI) { + this.domainURI = domainURI; + } + + public List getContributions() { + return contributions; + } + + public List getBindings() { + return bindings; + } + + +} diff --git a/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java new file mode 100644 index 0000000000..1d79062c0d --- /dev/null +++ b/java/sca/modules/implementation-node/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java @@ -0,0 +1,190 @@ +/* + * 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.node.configuration.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.node.configuration.BindingConfiguration; +import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; +import org.apache.tuscany.sca.node.configuration.DeploymentComposite; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; +import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory; + +/** + * Implements a StAX artifact processor for node implementations. + * + * @version $Rev: 750323 $ $Date: 2009-03-04 21:52:01 -0800 (Wed, 04 Mar 2009) $ + */ +public class NodeConfigurationProcessor extends BaseStAXArtifactProcessor implements + StAXArtifactProcessor { + private static final String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + private static final QName NODE = new QName(SCA11_TUSCANY_NS, "node"); + private static final QName CONTRIBUTION = new QName(SCA11_TUSCANY_NS, "contribution"); + private static final QName BINDING = new QName(SCA11_TUSCANY_NS, "binding"); + private static final QName DEPLOYMENT_COMPOSITE = new QName(SCA11_TUSCANY_NS, "deploymentComposite"); + + private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; + private static final QName COMPOSITE = new QName(SCA11_NS, "composite"); + + private StAXArtifactProcessor processor; + private AssemblyFactory assemblyFactory; + private NodeConfigurationFactory nodeConfigurationFactory; + + public NodeConfigurationProcessor(FactoryExtensionPoint modelFactories, + StAXArtifactProcessor processor, + Monitor monitor) { + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + this.nodeConfigurationFactory = modelFactories.getFactory(NodeConfigurationFactory.class); + this.processor = processor; + } + + public QName getArtifactType() { + // Returns the QName of the XML element processed by this processor + return NODE; + } + + public Class getModelType() { + // Returns the type of model processed by this processor + return NodeConfiguration.class; + } + + public NodeConfiguration read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + + NodeConfiguration node = null; + ContributionConfiguration contribution = null; + DeploymentComposite composite = null; + + // Skip to end element + while (true) { + int event = reader.getEventType(); + switch (event) { + case XMLStreamConstants.START_ELEMENT: + QName name = reader.getName(); + if (NODE.equals(name)) { + node = nodeConfigurationFactory.createNodeConfiguration(); + node.setURI(reader.getAttributeValue(null, "uri")); + node.setDomainURI(reader.getAttributeValue(null, "domain")); + } else if (CONTRIBUTION.equals(name)) { + contribution = nodeConfigurationFactory.createContributionConfiguration(); + contribution.setURI(reader.getAttributeValue(null, "uri")); + contribution.setLocation(reader.getAttributeValue(null, "location")); + node.getContributions().add(contribution); + } else if (BINDING.equals(name)) { + BindingConfiguration binding = nodeConfigurationFactory.createBindingConfiguration(); + binding.setBindingType(getQName(reader, "name")); + String baseURIs = reader.getAttributeValue(null, "baseURIs"); + if (baseURIs != null) { + StringTokenizer tokenizer = new StringTokenizer(baseURIs); + while (tokenizer.hasMoreTokens()) { + binding.getBaseURIs().add(tokenizer.nextToken()); + } + } + node.getBindings().add(binding); + } else if (DEPLOYMENT_COMPOSITE.equals(name)) { + composite = nodeConfigurationFactory.createDeploymentComposite(); + composite.setLocation(reader.getAttributeValue(null, "location")); + if (contribution != null) { + contribution.getDeploymentComposites().add(composite); + } + } else if (COMPOSITE.equals(name)) { + Object model = processor.read(reader); + if (model instanceof Composite) { + composite.setComposite((Composite)model); + } + } + break; + + case END_ELEMENT: + name = reader.getName(); + if (NODE.equals(name)) { + return node; + } else if (CONTRIBUTION.equals(name)) { + contribution = null; + } + } + if (reader.hasNext()) { + reader.next(); + } else { + break; + } + } + + return node; + } + + public void resolve(NodeConfiguration node, ModelResolver resolver) throws ContributionResolveException { + } + + public void write(NodeConfiguration node, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + + writeStart(writer, + NODE.getNamespaceURI(), + NODE.getLocalPart(), + new XAttr("uri", node.getURI()), + new XAttr("domain", node.getDomainURI())); + + for (ContributionConfiguration c : node.getContributions()) { + writeStart(writer, + CONTRIBUTION.getNamespaceURI(), + CONTRIBUTION.getLocalPart(), + new XAttr("uri", c.getURI()), + new XAttr("location", c.getLocation())); + writeEnd(writer); + } + + for (BindingConfiguration b : node.getBindings()) { + StringBuffer uris = new StringBuffer(); + for (String uri : b.getBaseURIs()) { + uris.append(uri).append(' '); + } + if (uris.length() > 0) { + uris.deleteCharAt(uris.length() - 1); // Remove the trailing space + } else { + uris = null; + } + writeStart(writer, + BINDING.getNamespaceURI(), + BINDING.getLocalPart(), + new XAttr("name", b.getBindingType()), + new XAttr("baseURIs", uris.toString())); + writeEnd(writer); + } + + writeEnd(writer); + } +} diff --git a/java/sca/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml b/java/sca/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml index e96749286d..e4d7925efe 100644 --- a/java/sca/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml +++ b/java/sca/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml @@ -20,19 +20,9 @@ - - - - - - - - - @@ -40,6 +30,17 @@ - + + + + + + + + + + + + \ No newline at end of file diff --git a/java/sca/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/node/configuration/node2.xml b/java/sca/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/node/configuration/node2.xml index 0f5578c8b4..d8781f1b8c 100644 --- a/java/sca/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/node/configuration/node2.xml +++ b/java/sca/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/node/configuration/node2.xml @@ -23,10 +23,11 @@ targetNamespace="http://sample/node" name="TestNode2" domain="http://domain1"> - - + + + \ No newline at end of file -- cgit v1.2.3