summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/node-impl/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-21 07:03:47 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-21 07:03:47 +0000
commitab6904bc2f622129bc548391745b08eb0c219e57 (patch)
tree5c7599119182bfa8e65c0d6605e933396aedffd2 /java/sca/modules/node-impl/src
parent8d70ef6d556ad29b93d5d40e91c4c9304638c9e9 (diff)
Fix svn:eol-style and svn:keywords properties for java/xml files
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@796166 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/node-impl/src')
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java320
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java480
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/XMLStreamSerializer.java574
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Contributions.java320
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java2
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManager.java130
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManagerMBean.java60
-rw-r--r--java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java166
-rw-r--r--java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java76
-rw-r--r--java/sca/modules/node-impl/src/test/resources/HelloWorld.composite60
-rw-r--r--java/sca/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml108
11 files changed, 1148 insertions, 1148 deletions
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java
index d3d0c5d077..162670363a 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java
@@ -1,160 +1,160 @@
-/*
- * 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 static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
-
-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.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.ContributionConfiguration;
-import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
-import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory;
-
-/**
- * Implements a StAX artifact processor for configured node implementations.
- *
- * @version $Rev: 704156 $ $Date: 2008-10-13 09:31:59 -0700 (Mon, 13 Oct 2008) $
- */
-public class NodeConfigurationATOMProcessor extends BaseStAXArtifactProcessor implements
- StAXArtifactProcessor<NodeConfiguration> {
-
- private static final String ATOM_NS = "http://www.w3.org/2005/Atom";
- private static final QName FEED_QNAME = new QName(ATOM_NS, "feed");
- private static final QName ENTRY_QNAME = new QName(ATOM_NS, "entry");
- private static final QName ID_QNAME = new QName(ATOM_NS, "id");
- private static final QName LINK_QNAME = new QName(ATOM_NS, "link");
- private static final QName CONTENT_QNAME = new QName(ATOM_NS, "content");
- private static final String HREF = "href";
-
- private NodeConfigurationFactory factory;
-
- public NodeConfigurationATOMProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
- this.factory = modelFactories.getFactory(NodeConfigurationFactory.class);
- }
-
- public QName getArtifactType() {
- return null;
- }
-
- public Class<NodeConfiguration> getModelType() {
- // Returns the type of model processed by this processor
- return NodeConfiguration.class;
- }
-
- public NodeConfiguration read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
-
- NodeConfiguration config = factory.createNodeConfiguration();
-
- // Read a feed containing links to the composite and the contributions assigned to
- // the node
- ContributionConfiguration contribution = null;
- boolean id = false;
- QName name = null;
-
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
-
- case START_ELEMENT:
- name = reader.getName();
-
- if (ENTRY_QNAME.equals(name)) {
-
- // Read an <entry>
- contribution = factory.createContributionConfiguration();
- } else if (ID_QNAME.equals(name)) {
-
- // Read an <id>
- id = true;
-
- } else if (LINK_QNAME.equals(name)) {
-
- // Read a <link>
- String href = getString(reader, HREF);
-
- if (contribution != null) {
- contribution.setLocation(href);
- }
- } else if (CONTENT_QNAME.equals(name)) {
- // Read a <content>
- } else if (FEED_QNAME.equals(name)) {
- // Read a <feed>
- }
- break;
-
- case XMLStreamConstants.CHARACTERS:
-
- // Read characters inside an <id> element
- if (id) {
- if (contribution != null) {
- contribution.setURI(reader.getText());
- }
- }
- break;
-
- case END_ELEMENT:
- name = reader.getName();
-
- // Clear current state when reading reaching end element
- if (ENTRY_QNAME.equals(name)) {
- if (contribution != null) {
- config.getContributions().add(contribution);
- }
-
- contribution = null;
-
- } else if (ID_QNAME.equals(name)) {
- id = false;
-
- } else if (FEED_QNAME.equals(name)) {
-
- // We've reached the end of the feed
- return config;
- }
- break;
- }
-
- // Read the next element
- if (reader.hasNext()) {
- reader.next();
- }
- }
- return config;
- }
-
- public void resolve(NodeConfiguration implementation, ModelResolver resolver) throws ContributionResolveException {
- }
-
- public void write(NodeConfiguration implementation, XMLStreamWriter writer) throws ContributionWriteException,
- XMLStreamException {
- }
-}
+/*
+ * 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 static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+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.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.ContributionConfiguration;
+import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
+import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory;
+
+/**
+ * Implements a StAX artifact processor for configured node implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeConfigurationATOMProcessor extends BaseStAXArtifactProcessor implements
+ StAXArtifactProcessor<NodeConfiguration> {
+
+ private static final String ATOM_NS = "http://www.w3.org/2005/Atom";
+ private static final QName FEED_QNAME = new QName(ATOM_NS, "feed");
+ private static final QName ENTRY_QNAME = new QName(ATOM_NS, "entry");
+ private static final QName ID_QNAME = new QName(ATOM_NS, "id");
+ private static final QName LINK_QNAME = new QName(ATOM_NS, "link");
+ private static final QName CONTENT_QNAME = new QName(ATOM_NS, "content");
+ private static final String HREF = "href";
+
+ private NodeConfigurationFactory factory;
+
+ public NodeConfigurationATOMProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.factory = modelFactories.getFactory(NodeConfigurationFactory.class);
+ }
+
+ public QName getArtifactType() {
+ return null;
+ }
+
+ public Class<NodeConfiguration> getModelType() {
+ // Returns the type of model processed by this processor
+ return NodeConfiguration.class;
+ }
+
+ public NodeConfiguration read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+
+ NodeConfiguration config = factory.createNodeConfiguration();
+
+ // Read a feed containing links to the composite and the contributions assigned to
+ // the node
+ ContributionConfiguration contribution = null;
+ boolean id = false;
+ QName name = null;
+
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+
+ case START_ELEMENT:
+ name = reader.getName();
+
+ if (ENTRY_QNAME.equals(name)) {
+
+ // Read an <entry>
+ contribution = factory.createContributionConfiguration();
+ } else if (ID_QNAME.equals(name)) {
+
+ // Read an <id>
+ id = true;
+
+ } else if (LINK_QNAME.equals(name)) {
+
+ // Read a <link>
+ String href = getString(reader, HREF);
+
+ if (contribution != null) {
+ contribution.setLocation(href);
+ }
+ } else if (CONTENT_QNAME.equals(name)) {
+ // Read a <content>
+ } else if (FEED_QNAME.equals(name)) {
+ // Read a <feed>
+ }
+ break;
+
+ case XMLStreamConstants.CHARACTERS:
+
+ // Read characters inside an <id> element
+ if (id) {
+ if (contribution != null) {
+ contribution.setURI(reader.getText());
+ }
+ }
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+
+ // Clear current state when reading reaching end element
+ if (ENTRY_QNAME.equals(name)) {
+ if (contribution != null) {
+ config.getContributions().add(contribution);
+ }
+
+ contribution = null;
+
+ } else if (ID_QNAME.equals(name)) {
+ id = false;
+
+ } else if (FEED_QNAME.equals(name)) {
+
+ // We've reached the end of the feed
+ return config;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+ return config;
+ }
+
+ public void resolve(NodeConfiguration implementation, ModelResolver resolver) throws ContributionResolveException {
+ }
+
+ public void write(NodeConfiguration implementation, XMLStreamWriter writer) throws ContributionWriteException,
+ XMLStreamException {
+ }
+}
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java
index fb16cf461d..31f21ee09f 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java
@@ -1,240 +1,240 @@
-/*
- * 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.io.StringReader;
-import java.io.StringWriter;
-import java.util.StringTokenizer;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-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.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<NodeConfiguration> {
- 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 BASE_URI = new QName(SCA11_TUSCANY_NS, "baseURI");
- 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 NodeConfigurationFactory nodeConfigurationFactory;
- private XMLInputFactory xmlInputFactory;
- private XMLOutputFactory xmlOutputFactory;
-
- public NodeConfigurationProcessor(FactoryExtensionPoint modelFactories,
- StAXArtifactProcessor processor,
- Monitor monitor) {
- this.nodeConfigurationFactory = modelFactories.getFactory(NodeConfigurationFactory.class);
- this.processor = processor;
- this.xmlInputFactory = modelFactories.getFactory(XMLInputFactory.class);
- this.xmlOutputFactory = modelFactories.getFactory(XMLOutputFactory.class);
- }
-
- public NodeConfigurationProcessor(NodeConfigurationFactory nodeConfigurationFactory,
- XMLInputFactory xmlInputFactory,
- XMLOutputFactory xmlOutputFactory) {
- super();
- this.nodeConfigurationFactory = nodeConfigurationFactory;
- this.xmlInputFactory = xmlInputFactory;
- this.xmlOutputFactory = xmlOutputFactory;
- }
-
- public QName getArtifactType() {
- // Returns the QName of the XML element processed by this processor
- return NODE;
- }
-
- public Class<NodeConfiguration> 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;
- BindingConfiguration binding = 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)) {
- 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(BASE_URI.equals(name)) {
- // We also support <baseURI> element
- String baseURI = reader.getElementText();
- if (baseURI != null && binding != null) {
- baseURI = baseURI.trim();
- binding.addBaseURI(baseURI);
- }
- // getElementText() moves the event to END_ELEMENT
- continue;
- } else if (COMPOSITE.equals(name)) {
- /*
- Object model = processor.read(reader);
- if (model instanceof Composite) {
- // FIXME: We need to capture the text here
- // composite.setComposite((Composite)model);
- }
- */
- StringWriter sw = new StringWriter();
- XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(sw);
- new XMLStreamSerializer().serialize(reader, writer);
- writer.flush();
- composite.setContent(sw.toString());
- }
- break;
-
- case END_ELEMENT:
- name = reader.getName();
- if (NODE.equals(name)) {
- return node;
- } else if (CONTRIBUTION.equals(name)) {
- contribution = null;
- } else if (DEPLOYMENT_COMPOSITE.equals(name)) {
- composite = null;
- } else if (BINDING.equals(name)) {
- binding = 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()));
- for (DeploymentComposite dc : c.getDeploymentComposites()) {
- writeStart(writer,
- DEPLOYMENT_COMPOSITE.getNamespaceURI(),
- DEPLOYMENT_COMPOSITE.getLocalPart(),
- new XAttr("location", dc.getLocation()),
- new XAttr("contribution", dc.getContributionURI()));
- if (dc.getContent() != null) {
- XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(new StringReader(dc.getContent()));
- reader.nextTag(); // Move to the first element
- new XMLStreamSerializer().serialize(reader, writer);
- reader.close();
- }
- writeEnd(writer);
- }
- 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);
- }
-}
+/*
+ * 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.io.StringReader;
+import java.io.StringWriter;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+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.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$ $Date$
+ */
+public class NodeConfigurationProcessor extends BaseStAXArtifactProcessor implements
+ StAXArtifactProcessor<NodeConfiguration> {
+ 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 BASE_URI = new QName(SCA11_TUSCANY_NS, "baseURI");
+ 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 NodeConfigurationFactory nodeConfigurationFactory;
+ private XMLInputFactory xmlInputFactory;
+ private XMLOutputFactory xmlOutputFactory;
+
+ public NodeConfigurationProcessor(FactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor processor,
+ Monitor monitor) {
+ this.nodeConfigurationFactory = modelFactories.getFactory(NodeConfigurationFactory.class);
+ this.processor = processor;
+ this.xmlInputFactory = modelFactories.getFactory(XMLInputFactory.class);
+ this.xmlOutputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+ }
+
+ public NodeConfigurationProcessor(NodeConfigurationFactory nodeConfigurationFactory,
+ XMLInputFactory xmlInputFactory,
+ XMLOutputFactory xmlOutputFactory) {
+ super();
+ this.nodeConfigurationFactory = nodeConfigurationFactory;
+ this.xmlInputFactory = xmlInputFactory;
+ this.xmlOutputFactory = xmlOutputFactory;
+ }
+
+ public QName getArtifactType() {
+ // Returns the QName of the XML element processed by this processor
+ return NODE;
+ }
+
+ public Class<NodeConfiguration> 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;
+ BindingConfiguration binding = 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)) {
+ 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(BASE_URI.equals(name)) {
+ // We also support <baseURI> element
+ String baseURI = reader.getElementText();
+ if (baseURI != null && binding != null) {
+ baseURI = baseURI.trim();
+ binding.addBaseURI(baseURI);
+ }
+ // getElementText() moves the event to END_ELEMENT
+ continue;
+ } else if (COMPOSITE.equals(name)) {
+ /*
+ Object model = processor.read(reader);
+ if (model instanceof Composite) {
+ // FIXME: We need to capture the text here
+ // composite.setComposite((Composite)model);
+ }
+ */
+ StringWriter sw = new StringWriter();
+ XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(sw);
+ new XMLStreamSerializer().serialize(reader, writer);
+ writer.flush();
+ composite.setContent(sw.toString());
+ }
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+ if (NODE.equals(name)) {
+ return node;
+ } else if (CONTRIBUTION.equals(name)) {
+ contribution = null;
+ } else if (DEPLOYMENT_COMPOSITE.equals(name)) {
+ composite = null;
+ } else if (BINDING.equals(name)) {
+ binding = 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()));
+ for (DeploymentComposite dc : c.getDeploymentComposites()) {
+ writeStart(writer,
+ DEPLOYMENT_COMPOSITE.getNamespaceURI(),
+ DEPLOYMENT_COMPOSITE.getLocalPart(),
+ new XAttr("location", dc.getLocation()),
+ new XAttr("contribution", dc.getContributionURI()));
+ if (dc.getContent() != null) {
+ XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(new StringReader(dc.getContent()));
+ reader.nextTag(); // Move to the first element
+ new XMLStreamSerializer().serialize(reader, writer);
+ reader.close();
+ }
+ writeEnd(writer);
+ }
+ 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/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/XMLStreamSerializer.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/XMLStreamSerializer.java
index 38d8215cb2..1ddf25953d 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/XMLStreamSerializer.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/XMLStreamSerializer.java
@@ -1,287 +1,287 @@
-/*
- * 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 javax.xml.namespace.NamespaceContext;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-/**
- * The XMLStreamSerializer pulls events from the XMLStreamReader and dumps into the XMLStreamWriter
- *
- * @version $Rev: 656146 $ $Date: 2008-05-14 01:22:08 -0700 (Wed, 14 May 2008) $
- */
-public class XMLStreamSerializer implements XMLStreamConstants {
- public static final String NAMESPACE_PREFIX = "ns";
- private static int namespaceSuffix;
-
- /*
- * The behavior of the Serializer is such that it returns when it encounters the starting element for the second
- * time. The depth variable tracks the depth of the Serializer and tells it when to return. Note that it is assumed
- * that this Serialization starts on an Element.
- */
-
- /**
- * Field depth
- */
- private int depth;
-
- /**
- * Generates a unique namespace prefix that is not in the scope of the NamespaceContext
- *
- * @param nsCtxt
- * @return string
- */
- private String generateUniquePrefix(NamespaceContext nsCtxt) {
- String prefix = NAMESPACE_PREFIX + namespaceSuffix++;
- // null should be returned if the prefix is not bound!
- while (nsCtxt.getNamespaceURI(prefix) != null) {
- prefix = NAMESPACE_PREFIX + namespaceSuffix++;
- }
-
- return prefix;
- }
-
- /**
- * Method serialize.
- *
- * @param node
- * @param writer
- * @throws XMLStreamException
- */
- public void serialize(XMLStreamReader node, XMLStreamWriter writer) throws XMLStreamException {
- serializeNode(node, writer);
- }
-
- /**
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeAttributes(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- int count = reader.getAttributeCount();
- String prefix;
- String namespaceName;
- String writerPrefix;
- for (int i = 0; i < count; i++) {
- prefix = reader.getAttributePrefix(i);
- namespaceName = reader.getAttributeNamespace(i);
- /*
- * Due to parser implementations returning null as the namespace URI (for the empty namespace) we need to
- * make sure that we deal with a namespace name that is not null. The best way to work around this issue is
- * to set the namespace URI to "" if it is null
- */
- if (namespaceName == null) {
- namespaceName = "";
- }
-
- writerPrefix = writer.getPrefix(namespaceName);
-
- if (!"".equals(namespaceName)) {
- // prefix has already being declared but this particular
- // attrib has a
- // no prefix attached. So use the prefix provided by the
- // writer
- if (writerPrefix != null && (prefix == null || prefix.equals(""))) {
- writer.writeAttribute(writerPrefix, namespaceName, reader.getAttributeLocalName(i), reader
- .getAttributeValue(i));
-
- // writer prefix is available but different from the
- // current
- // prefix of the attrib. We should be declaring the new
- // prefix
- // as a namespace declaration
- } else if (prefix != null && !"".equals(prefix) && !prefix.equals(writerPrefix)) {
- writer.writeNamespace(prefix, namespaceName);
- writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
- .getAttributeValue(i));
-
- // prefix is null (or empty), but the namespace name is
- // valid! it has not
- // being written previously also. So we need to generate
- // a prefix
- // here
- } else if (prefix == null || prefix.equals("")) {
- prefix = generateUniquePrefix(writer.getNamespaceContext());
- writer.writeNamespace(prefix, namespaceName);
- writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
- .getAttributeValue(i));
- } else {
- writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
- .getAttributeValue(i));
- }
- } else {
- // empty namespace is equal to no namespace!
- writer.writeAttribute(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
- }
-
- }
- }
-
- /**
- * Method serializeCData.
- *
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeCData(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- writer.writeCData(reader.getText());
- }
-
- /**
- * Method serializeComment.
- *
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeComment(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- writer.writeComment(reader.getText());
- }
-
- /**
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeElement(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- String prefix = reader.getPrefix();
- String nameSpaceName = reader.getNamespaceURI();
- if (nameSpaceName != null) {
- String writerPrefix = writer.getPrefix(nameSpaceName);
- if (writerPrefix != null) {
- writer.writeStartElement(nameSpaceName, reader.getLocalName());
- } else {
- if (prefix != null) {
- writer.writeStartElement(prefix, reader.getLocalName(), nameSpaceName);
- writer.writeNamespace(prefix, nameSpaceName);
- // writer.setPrefix(prefix, nameSpaceName);
- } else {
- // [rfeng] We need to set default NS 1st before calling writeStateElement
- writer.setDefaultNamespace(nameSpaceName);
- writer.writeStartElement(nameSpaceName, reader.getLocalName());
- writer.writeDefaultNamespace(nameSpaceName);
- }
- }
- } else {
- writer.writeStartElement(reader.getLocalName());
- }
-
- // add the namespaces
- int count = reader.getNamespaceCount();
- String namespacePrefix;
- for (int i = 0; i < count; i++) {
- namespacePrefix = reader.getNamespacePrefix(i);
- // [rfeng] The following is commented out to allow to default ns
- // if (namespacePrefix != null && namespacePrefix.length() == 0) {
- // continue;
- // }
-
- serializeNamespace(namespacePrefix, reader.getNamespaceURI(i), writer);
- }
-
- // add attributes
- serializeAttributes(reader, writer);
-
- }
-
- /**
- * Method serializeEndElement.
- *
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeEndElement(XMLStreamWriter writer) throws XMLStreamException {
- writer.writeEndElement();
- }
-
- /**
- * Method serializeNamespace.
- *
- * @param prefix
- * @param uri
- * @param writer
- * @throws XMLStreamException
- */
- private void serializeNamespace(String prefix, String uri, XMLStreamWriter writer) throws XMLStreamException {
- String prefix1 = writer.getPrefix(uri);
- if (prefix1 == null) {
- writer.writeNamespace(prefix, uri);
- // writer.setPrefix(prefix, uri);
- }
- }
-
- /**
- * Method serializeNode.
- *
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeNode(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- while (true) {
- int event = reader.getEventType();
- if (event == START_ELEMENT) {
- serializeElement(reader, writer);
- depth++;
- } else if (event == ATTRIBUTE) {
- serializeAttributes(reader, writer);
- } else if (event == CHARACTERS) {
- serializeText(reader, writer);
- } else if (event == COMMENT) {
- serializeComment(reader, writer);
- } else if (event == CDATA) {
- serializeCData(reader, writer);
- } else if (event == END_ELEMENT) {
- serializeEndElement(writer);
- depth--;
- } else if (event == START_DOCUMENT) {
- depth++; // if a start document is found then increment
- writer.writeStartDocument();
- // the depth
- } else if (event == END_DOCUMENT) {
- if (depth != 0) {
- depth--; // for the end document - reduce the depth
- }
- writer.writeEndDocument();
- }
- if (depth == 0) {
- break;
- }
- if (reader.hasNext()) {
- reader.next();
- } else {
- break;
- }
- }
- }
-
- /**
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeText(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- writer.writeCharacters(reader.getText());
- }
-}
+/*
+ * 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 javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * The XMLStreamSerializer pulls events from the XMLStreamReader and dumps into the XMLStreamWriter
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLStreamSerializer implements XMLStreamConstants {
+ public static final String NAMESPACE_PREFIX = "ns";
+ private static int namespaceSuffix;
+
+ /*
+ * The behavior of the Serializer is such that it returns when it encounters the starting element for the second
+ * time. The depth variable tracks the depth of the Serializer and tells it when to return. Note that it is assumed
+ * that this Serialization starts on an Element.
+ */
+
+ /**
+ * Field depth
+ */
+ private int depth;
+
+ /**
+ * Generates a unique namespace prefix that is not in the scope of the NamespaceContext
+ *
+ * @param nsCtxt
+ * @return string
+ */
+ private String generateUniquePrefix(NamespaceContext nsCtxt) {
+ String prefix = NAMESPACE_PREFIX + namespaceSuffix++;
+ // null should be returned if the prefix is not bound!
+ while (nsCtxt.getNamespaceURI(prefix) != null) {
+ prefix = NAMESPACE_PREFIX + namespaceSuffix++;
+ }
+
+ return prefix;
+ }
+
+ /**
+ * Method serialize.
+ *
+ * @param node
+ * @param writer
+ * @throws XMLStreamException
+ */
+ public void serialize(XMLStreamReader node, XMLStreamWriter writer) throws XMLStreamException {
+ serializeNode(node, writer);
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeAttributes(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ int count = reader.getAttributeCount();
+ String prefix;
+ String namespaceName;
+ String writerPrefix;
+ for (int i = 0; i < count; i++) {
+ prefix = reader.getAttributePrefix(i);
+ namespaceName = reader.getAttributeNamespace(i);
+ /*
+ * Due to parser implementations returning null as the namespace URI (for the empty namespace) we need to
+ * make sure that we deal with a namespace name that is not null. The best way to work around this issue is
+ * to set the namespace URI to "" if it is null
+ */
+ if (namespaceName == null) {
+ namespaceName = "";
+ }
+
+ writerPrefix = writer.getPrefix(namespaceName);
+
+ if (!"".equals(namespaceName)) {
+ // prefix has already being declared but this particular
+ // attrib has a
+ // no prefix attached. So use the prefix provided by the
+ // writer
+ if (writerPrefix != null && (prefix == null || prefix.equals(""))) {
+ writer.writeAttribute(writerPrefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+
+ // writer prefix is available but different from the
+ // current
+ // prefix of the attrib. We should be declaring the new
+ // prefix
+ // as a namespace declaration
+ } else if (prefix != null && !"".equals(prefix) && !prefix.equals(writerPrefix)) {
+ writer.writeNamespace(prefix, namespaceName);
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+
+ // prefix is null (or empty), but the namespace name is
+ // valid! it has not
+ // being written previously also. So we need to generate
+ // a prefix
+ // here
+ } else if (prefix == null || prefix.equals("")) {
+ prefix = generateUniquePrefix(writer.getNamespaceContext());
+ writer.writeNamespace(prefix, namespaceName);
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+ } else {
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+ }
+ } else {
+ // empty namespace is equal to no namespace!
+ writer.writeAttribute(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
+ }
+
+ }
+ }
+
+ /**
+ * Method serializeCData.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeCData(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeCData(reader.getText());
+ }
+
+ /**
+ * Method serializeComment.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeComment(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeComment(reader.getText());
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeElement(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ String prefix = reader.getPrefix();
+ String nameSpaceName = reader.getNamespaceURI();
+ if (nameSpaceName != null) {
+ String writerPrefix = writer.getPrefix(nameSpaceName);
+ if (writerPrefix != null) {
+ writer.writeStartElement(nameSpaceName, reader.getLocalName());
+ } else {
+ if (prefix != null) {
+ writer.writeStartElement(prefix, reader.getLocalName(), nameSpaceName);
+ writer.writeNamespace(prefix, nameSpaceName);
+ // writer.setPrefix(prefix, nameSpaceName);
+ } else {
+ // [rfeng] We need to set default NS 1st before calling writeStateElement
+ writer.setDefaultNamespace(nameSpaceName);
+ writer.writeStartElement(nameSpaceName, reader.getLocalName());
+ writer.writeDefaultNamespace(nameSpaceName);
+ }
+ }
+ } else {
+ writer.writeStartElement(reader.getLocalName());
+ }
+
+ // add the namespaces
+ int count = reader.getNamespaceCount();
+ String namespacePrefix;
+ for (int i = 0; i < count; i++) {
+ namespacePrefix = reader.getNamespacePrefix(i);
+ // [rfeng] The following is commented out to allow to default ns
+ // if (namespacePrefix != null && namespacePrefix.length() == 0) {
+ // continue;
+ // }
+
+ serializeNamespace(namespacePrefix, reader.getNamespaceURI(i), writer);
+ }
+
+ // add attributes
+ serializeAttributes(reader, writer);
+
+ }
+
+ /**
+ * Method serializeEndElement.
+ *
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeEndElement(XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeEndElement();
+ }
+
+ /**
+ * Method serializeNamespace.
+ *
+ * @param prefix
+ * @param uri
+ * @param writer
+ * @throws XMLStreamException
+ */
+ private void serializeNamespace(String prefix, String uri, XMLStreamWriter writer) throws XMLStreamException {
+ String prefix1 = writer.getPrefix(uri);
+ if (prefix1 == null) {
+ writer.writeNamespace(prefix, uri);
+ // writer.setPrefix(prefix, uri);
+ }
+ }
+
+ /**
+ * Method serializeNode.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeNode(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ while (true) {
+ int event = reader.getEventType();
+ if (event == START_ELEMENT) {
+ serializeElement(reader, writer);
+ depth++;
+ } else if (event == ATTRIBUTE) {
+ serializeAttributes(reader, writer);
+ } else if (event == CHARACTERS) {
+ serializeText(reader, writer);
+ } else if (event == COMMENT) {
+ serializeComment(reader, writer);
+ } else if (event == CDATA) {
+ serializeCData(reader, writer);
+ } else if (event == END_ELEMENT) {
+ serializeEndElement(writer);
+ depth--;
+ } else if (event == START_DOCUMENT) {
+ depth++; // if a start document is found then increment
+ writer.writeStartDocument();
+ // the depth
+ } else if (event == END_DOCUMENT) {
+ if (depth != 0) {
+ depth--; // for the end document - reduce the depth
+ }
+ writer.writeEndDocument();
+ }
+ if (depth == 0) {
+ break;
+ }
+ if (reader.hasNext()) {
+ reader.next();
+ } else {
+ break;
+ }
+ }
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeText(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeCharacters(reader.getText());
+ }
+}
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Contributions.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Contributions.java
index 7dabb471be..6aace875b5 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Contributions.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Contributions.java
@@ -1,160 +1,160 @@
-/*
- * 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.impl;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.assembly.Extension;
-import org.apache.tuscany.sca.contribution.Artifact;
-import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.contribution.Export;
-import org.apache.tuscany.sca.contribution.Import;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-
-/**
- * A Contribution impl wrapping multiple other contributions
- * Currently the sole reason for this is so
- */
-public class Contributions implements Contribution {
-
- private List<Contribution> contributions = new ArrayList<Contribution>();
- private String location;
- private String uri;
- private Object model;
- private byte[] contents;
- private boolean unresolved;
- private ModelResolver modelResolver;
- private List<Contribution> dependencies = new ArrayList<Contribution>();
-
- public Contributions(List<Contribution> contributions) {
- this.contributions = contributions;
- }
-
- public String getLocation() {
- return location;
- }
-
- public Object getModel() {
- return model;
- }
-
- public String getURI() {
- return uri;
- }
-
- public void setLocation(String location) {
- this.location = location;
- }
-
- public void setModel(Object model) {
- this.model = model;
- }
-
- public byte[] getContents() {
- return contents;
- }
-
- public void setContents(byte[] contents) {
- this.contents = contents;
- }
-
- public void setURI(String uri) {
- this.uri = uri;
- }
-
- public boolean isUnresolved() {
- return unresolved;
- }
-
- public void setUnresolved(boolean unresolved) {
- this.unresolved = unresolved;
- }
-
- public List<Contribution> getContributions() {
- return contributions;
- }
-
- public List<Artifact> getArtifacts() {
- return (List<Artifact>)(Object)contributions;
- }
-
- public List<Contribution> getDependencies() {
- return dependencies;
- }
-
- public ClassLoader getClassLoader() {
- //FIXME Remove later
- return null;
- }
-
- public void setClassLoader(ClassLoader classLoader) {
- //FIXME Remove later
- }
-
- public List<Composite> getDeployables() {
- List<Composite> deployables = new ArrayList<Composite>();
- for (Contribution contribution: contributions) {
- deployables.addAll(contribution.getDeployables());
- }
- return deployables;
- }
-
- public List<Export> getExports() {
- List<Export> exports = new ArrayList<Export>();
- for (Contribution contribution: contributions) {
- exports.addAll(contribution.getExports());
- }
- return exports;
- }
-
- public List<Import> getImports() {
- List<Import> imports = new ArrayList<Import>();
- for (Contribution contribution: contributions) {
- imports.addAll(contribution.getImports());
- }
- return imports;
- }
-
- public ModelResolver getModelResolver() {
- return modelResolver;
- }
-
- public void setModelResolver(ModelResolver modelResolver) {
- this.modelResolver = modelResolver;
- }
-
- public List<Extension> getAttributeExtensions() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public List<Object> getExtensions() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Set<String> getTypes() {
- return Collections.emptySet();
- }
-}
+/*
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Extension;
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.Export;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * A Contribution impl wrapping multiple other contributions
+ * Currently the sole reason for this is so
+ */
+public class Contributions implements Contribution {
+
+ private List<Contribution> contributions = new ArrayList<Contribution>();
+ private String location;
+ private String uri;
+ private Object model;
+ private byte[] contents;
+ private boolean unresolved;
+ private ModelResolver modelResolver;
+ private List<Contribution> dependencies = new ArrayList<Contribution>();
+
+ public Contributions(List<Contribution> contributions) {
+ this.contributions = contributions;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public Object getModel() {
+ return model;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public void setModel(Object model) {
+ this.model = model;
+ }
+
+ public byte[] getContents() {
+ return contents;
+ }
+
+ public void setContents(byte[] contents) {
+ this.contents = contents;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+
+ public List<Contribution> getContributions() {
+ return contributions;
+ }
+
+ public List<Artifact> getArtifacts() {
+ return (List<Artifact>)(Object)contributions;
+ }
+
+ public List<Contribution> getDependencies() {
+ return dependencies;
+ }
+
+ public ClassLoader getClassLoader() {
+ //FIXME Remove later
+ return null;
+ }
+
+ public void setClassLoader(ClassLoader classLoader) {
+ //FIXME Remove later
+ }
+
+ public List<Composite> getDeployables() {
+ List<Composite> deployables = new ArrayList<Composite>();
+ for (Contribution contribution: contributions) {
+ deployables.addAll(contribution.getDeployables());
+ }
+ return deployables;
+ }
+
+ public List<Export> getExports() {
+ List<Export> exports = new ArrayList<Export>();
+ for (Contribution contribution: contributions) {
+ exports.addAll(contribution.getExports());
+ }
+ return exports;
+ }
+
+ public List<Import> getImports() {
+ List<Import> imports = new ArrayList<Import>();
+ for (Contribution contribution: contributions) {
+ imports.addAll(contribution.getImports());
+ }
+ return imports;
+ }
+
+ public ModelResolver getModelResolver() {
+ return modelResolver;
+ }
+
+ public void setModelResolver(ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ }
+
+ public List<Extension> getAttributeExtensions() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<Object> getExtensions() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Set<String> getTypes() {
+ return Collections.emptySet();
+ }
+}
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java
index 8bf3ea8b04..3f65d49740 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java
@@ -32,7 +32,7 @@ import org.apache.tuscany.sca.contribution.ContributionFactory;
/**
* NodeUtil
*
- * @version $Rev: $ $Date: $
+ * @version $Rev$ $Date$
*/
public class NodeUtil {
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManager.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManager.java
index 5f44dda7d5..12704a3ee5 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManager.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManager.java
@@ -1,65 +1,65 @@
-/*
- * 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.management;
-
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.apache.tuscany.sca.node.Node;
-import org.apache.tuscany.sca.node.impl.NodeImpl;
-
-/**
- * MBean implementation for the node
- */
-public class NodeManager implements NodeManagerMBean {
- private NodeImpl node;
- private ObjectName name;
-
- public NodeManager(NodeImpl node) {
- this.node = node;
- try {
- this.name = getName(node);
- } catch (MalformedObjectNameException e) {
- // Ignore
- }
- }
-
- public String getURI() {
- return node.getURI();
- }
-
- public String getDomainURI() {
- return node.getConfiguration().getDomainURI();
- }
-
- public ObjectName getName() {
- return name;
- }
-
- private static ObjectName getName(NodeImpl node) throws MalformedObjectNameException {
- String name =
- Node.class.getPackage().getName() + ":type="
- + Node.class.getSimpleName()
- + ",uri="
- + ObjectName.quote(node.getURI());
- return ObjectName.getInstance(name);
-
- }
-}
+/*
+ * 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.management;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.impl.NodeImpl;
+
+/**
+ * MBean implementation for the node
+ */
+public class NodeManager implements NodeManagerMBean {
+ private NodeImpl node;
+ private ObjectName name;
+
+ public NodeManager(NodeImpl node) {
+ this.node = node;
+ try {
+ this.name = getName(node);
+ } catch (MalformedObjectNameException e) {
+ // Ignore
+ }
+ }
+
+ public String getURI() {
+ return node.getURI();
+ }
+
+ public String getDomainURI() {
+ return node.getConfiguration().getDomainURI();
+ }
+
+ public ObjectName getName() {
+ return name;
+ }
+
+ private static ObjectName getName(NodeImpl node) throws MalformedObjectNameException {
+ String name =
+ Node.class.getPackage().getName() + ":type="
+ + Node.class.getSimpleName()
+ + ",uri="
+ + ObjectName.quote(node.getURI());
+ return ObjectName.getInstance(name);
+
+ }
+}
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManagerMBean.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManagerMBean.java
index c25cd0f0ca..3133142c2b 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManagerMBean.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManagerMBean.java
@@ -1,30 +1,30 @@
-/*
- * 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.management;
-
-
-
-/**
- * MBean for NodeImpl
- */
-public interface NodeManagerMBean {
- String getURI();
- String getDomainURI();
-}
+/*
+ * 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.management;
+
+
+
+/**
+ * MBean for NodeImpl
+ */
+public interface NodeManagerMBean {
+ String getURI();
+ String getDomainURI();
+}
diff --git a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java
index f76aabe034..6b5bce2d13 100644
--- a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java
+++ b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java
@@ -1,83 +1,83 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tuscany.sca.node.configuration.xml;
-
-import java.io.InputStream;
-import java.io.StringWriter;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
-import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- *
- */
-public class NodeConfigurationProcessorTestCase {
- private static FactoryExtensionPoint factories;
- private static StAXArtifactProcessor processor;
-
- /**
- * @throws java.lang.Exception
- */
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
- factories = new DefaultFactoryExtensionPoint(registry);
- StAXArtifactProcessorExtensionPoint processors =
- registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- processor = processors.getProcessor(NodeConfiguration.class);
- }
-
- @Test
- public void testRead() throws Exception {
- InputStream is = getClass().getResourceAsStream("/org/apache/tuscany/sca/node/configuration/node1.xml");
- XMLInputFactory xmlInputFactory = factories.getFactory(XMLInputFactory.class);
- XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(is);
- is.close();
- reader.nextTag();
- NodeConfiguration config = (NodeConfiguration) processor.read(reader);
- StringWriter sw = new StringWriter();
- XMLOutputFactory xmlOutputFactory = factories.getFactory(XMLOutputFactory.class);
- XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(sw);
- processor.write(config, writer);
- writer.flush();
- System.out.println(sw.toString());
- }
-
- /**
- * @throws java.lang.Exception
- */
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
-}
+/*
+ * 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 java.io.InputStream;
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class NodeConfigurationProcessorTestCase {
+ private static FactoryExtensionPoint factories;
+ private static StAXArtifactProcessor processor;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
+ factories = new DefaultFactoryExtensionPoint(registry);
+ StAXArtifactProcessorExtensionPoint processors =
+ registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ processor = processors.getProcessor(NodeConfiguration.class);
+ }
+
+ @Test
+ public void testRead() throws Exception {
+ InputStream is = getClass().getResourceAsStream("/org/apache/tuscany/sca/node/configuration/node1.xml");
+ XMLInputFactory xmlInputFactory = factories.getFactory(XMLInputFactory.class);
+ XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(is);
+ is.close();
+ reader.nextTag();
+ NodeConfiguration config = (NodeConfiguration) processor.read(reader);
+ StringWriter sw = new StringWriter();
+ XMLOutputFactory xmlOutputFactory = factories.getFactory(XMLOutputFactory.class);
+ XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(sw);
+ processor.write(config, writer);
+ writer.flush();
+ System.out.println(sw.toString());
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+}
diff --git a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java
index 55e44c04ba..725bce5e09 100644
--- a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java
+++ b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java
@@ -1,38 +1,38 @@
-/*
- * 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.impl;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-
-/**
- *
- */
-public class NodeUtilTestCase {
- @Test
- public void testCreateURI() {
- Assert.assertEquals("/a/b", NodeUtil.createURI("/a/b").toString());
- Assert.assertEquals("/a%20b", NodeUtil.createURI("/a b").toString());
- Assert.assertEquals("file:/a/b", NodeUtil.createURI("file:/a/b").toString());
- Assert.assertEquals("file:/a%20b", NodeUtil.createURI("file:/a b").toString());
- Assert.assertEquals("file:/a%20b", NodeUtil.createURI("file:/a%20b").toString());
- }
-}
+/*
+ * 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.impl;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+/**
+ *
+ */
+public class NodeUtilTestCase {
+ @Test
+ public void testCreateURI() {
+ Assert.assertEquals("/a/b", NodeUtil.createURI("/a/b").toString());
+ Assert.assertEquals("/a%20b", NodeUtil.createURI("/a b").toString());
+ Assert.assertEquals("file:/a/b", NodeUtil.createURI("file:/a/b").toString());
+ Assert.assertEquals("file:/a%20b", NodeUtil.createURI("file:/a b").toString());
+ Assert.assertEquals("file:/a%20b", NodeUtil.createURI("file:/a%20b").toString());
+ }
+}
diff --git a/java/sca/modules/node-impl/src/test/resources/HelloWorld.composite b/java/sca/modules/node-impl/src/test/resources/HelloWorld.composite
index 4c6f1b082f..efe43cbf2f 100644
--- a/java/sca/modules/node-impl/src/test/resources/HelloWorld.composite
+++ b/java/sca/modules/node-impl/src/test/resources/HelloWorld.composite
@@ -1,30 +1,30 @@
-<?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://docs.oasis-open.org/ns/opencsa/sca/200903"
- xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
- targetNamespace="http://sample/composite"
- xmlns:sc="http://sample/composite"
- name="HelloWorld">
-
- <component name="HelloWorld">
- <implementation.java class="hello.HelloWorldImpl"/>
- </component>
-
-</composite>
+<?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://docs.oasis-open.org/ns/opencsa/sca/200903"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://sample/composite"
+ xmlns:sc="http://sample/composite"
+ name="HelloWorld">
+
+ <component name="HelloWorld">
+ <implementation.java class="hello.HelloWorldImpl"/>
+ </component>
+
+</composite>
diff --git a/java/sca/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml b/java/sca/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml
index 40961a22b7..b6e56368ef 100644
--- a/java/sca/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml
+++ b/java/sca/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml
@@ -1,55 +1,55 @@
-<?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.
--->
-<node xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903"
- xmlns="http://tuscany.apache.org/xmlns/sca/1.1"
- xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
- uri="http://sample/nodes/TestNode1"
- domain="http://domain1">
-
- <!-- Configure the base URIs for a given binding -->
- <!-- Each base URI is for a protocol supported by the binding -->
- <binding name="sca:binding.ws" baseURIs="http://localhost:8080/ws https://localhost:8081/ws"/>
- <binding name="tuscany:binding.rmi" baseURIs="rmi://localhost:8080/rmi"/>
- <binding name="tuscany:binding.jsonrpc">
- <baseURI>http://localhost:8080/jsonrpc</baseURI>
- </binding>
-
- <!-- Configure a list of contributions -->
- <contribution uri="http://c1" location="file:///a.jar"/>
- <contribution uri="http://c2" location="http://locahost/repo/b.jar">
- <!-- The deployment composite is optional -->
- <!-- The deployment composite can be defined inline or referenced using a URI -->
- <!-- Can we have more than one deployment composites -->
- <deploymentComposite>
- <sca:composite>
- <sca:component name="Component1"> <!-- first component -->
- <sca:implementation.java class="a.b.Component1Impl"/>
- <sca:reference name="ref1">
- <tuscany:binding.rmi/>
- </sca:reference>
- </sca:component>
- </sca:composite>
- </deploymentComposite>
- </contribution>
- <contribution uri="http://c3" location="http://locahost/repo/c.jar">
- <deploymentComposite location="test/Test.composite">
- </deploymentComposite>
- </contribution>
+<?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.
+-->
+<node xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ xmlns="http://tuscany.apache.org/xmlns/sca/1.1"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ uri="http://sample/nodes/TestNode1"
+ domain="http://domain1">
+
+ <!-- Configure the base URIs for a given binding -->
+ <!-- Each base URI is for a protocol supported by the binding -->
+ <binding name="sca:binding.ws" baseURIs="http://localhost:8080/ws https://localhost:8081/ws"/>
+ <binding name="tuscany:binding.rmi" baseURIs="rmi://localhost:8080/rmi"/>
+ <binding name="tuscany:binding.jsonrpc">
+ <baseURI>http://localhost:8080/jsonrpc</baseURI>
+ </binding>
+
+ <!-- Configure a list of contributions -->
+ <contribution uri="http://c1" location="file:///a.jar"/>
+ <contribution uri="http://c2" location="http://locahost/repo/b.jar">
+ <!-- The deployment composite is optional -->
+ <!-- The deployment composite can be defined inline or referenced using a URI -->
+ <!-- Can we have more than one deployment composites -->
+ <deploymentComposite>
+ <sca:composite>
+ <sca:component name="Component1"> <!-- first component -->
+ <sca:implementation.java class="a.b.Component1Impl"/>
+ <sca:reference name="ref1">
+ <tuscany:binding.rmi/>
+ </sca:reference>
+ </sca:component>
+ </sca:composite>
+ </deploymentComposite>
+ </contribution>
+ <contribution uri="http://c3" location="http://locahost/repo/c.jar">
+ <deploymentComposite location="test/Test.composite">
+ </deploymentComposite>
+ </contribution>
</node> \ No newline at end of file