summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java79
-rw-r--r--java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java2
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java8
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.java16
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.java2
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.java11
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java7
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.java2
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java12
9 files changed, 115 insertions, 24 deletions
diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java
index 4c00e8bc71..c3c1ba7f42 100644
--- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java
+++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java
@@ -21,6 +21,8 @@ package org.apache.tuscany.sca.assembly.xml;
import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI;
import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import static org.apache.tuscany.sca.assembly.xml.Constants.ELEMENT;
import static org.apache.tuscany.sca.assembly.xml.Constants.MANY;
import static org.apache.tuscany.sca.assembly.xml.Constants.MULTIPLICITY;
@@ -28,9 +30,12 @@ import static org.apache.tuscany.sca.assembly.xml.Constants.MUST_SUPPLY;
import static org.apache.tuscany.sca.assembly.xml.Constants.NAME;
import static org.apache.tuscany.sca.assembly.xml.Constants.ONE_N;
import static org.apache.tuscany.sca.assembly.xml.Constants.ONE_ONE;
+import static org.apache.tuscany.sca.assembly.xml.Constants.PROPERTY_QNAME;
import static org.apache.tuscany.sca.assembly.xml.Constants.SCA11_NS;
import static org.apache.tuscany.sca.assembly.xml.Constants.TARGET;
import static org.apache.tuscany.sca.assembly.xml.Constants.TYPE;
+import static org.apache.tuscany.sca.assembly.xml.Constants.VALUE;
+import static org.apache.tuscany.sca.assembly.xml.Constants.VALUE_QNAME;
import static org.apache.tuscany.sca.assembly.xml.Constants.ZERO_N;
import static org.apache.tuscany.sca.assembly.xml.Constants.ZERO_ONE;
@@ -62,7 +67,6 @@ import org.apache.tuscany.sca.assembly.ConstrainingType;
import org.apache.tuscany.sca.assembly.Contract;
import org.apache.tuscany.sca.assembly.Extensible;
import org.apache.tuscany.sca.assembly.Extension;
-import org.apache.tuscany.sca.assembly.ExtensionFactory;
import org.apache.tuscany.sca.assembly.Implementation;
import org.apache.tuscany.sca.assembly.Multiplicity;
import org.apache.tuscany.sca.assembly.Reference;
@@ -96,7 +100,6 @@ import org.w3c.dom.NodeList;
abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor {
protected AssemblyFactory assemblyFactory;
- protected ExtensionFactory extensionFactory;
protected PolicyFactory policyFactory;
protected StAXArtifactProcessor<Object> extensionProcessor;
protected PolicySubjectProcessor policyProcessor;
@@ -110,13 +113,11 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor {
*/
@SuppressWarnings("unchecked")
protected BaseAssemblyProcessor(AssemblyFactory assemblyFactory,
- ExtensionFactory extensionFactory,
PolicyFactory policyFactory,
DocumentBuilderFactory documentBuilderFactory,
StAXArtifactProcessor extensionProcessor,
Monitor monitor) {
this.assemblyFactory = assemblyFactory;
- this.extensionFactory = extensionFactory;
this.policyFactory = policyFactory;
this.documentBuilderFactory = documentBuilderFactory;
this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor;
@@ -133,7 +134,6 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor {
StAXArtifactProcessor staxProcessor,
Monitor monitor) {
this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
- this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class);
this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
this.documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class);
this.extensionProcessor = (StAXArtifactProcessor<Object>)staxProcessor;
@@ -324,6 +324,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor {
property.setMustSupply(getBoolean(reader, MUST_SUPPLY));
property.setXSDElement(getQName(reader, ELEMENT));
property.setXSDType(getQName(reader, TYPE));
+
}
/**
@@ -429,6 +430,68 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor {
return null;
}
+ protected List<Extension> readPropertyValue(XMLStreamReader reader) throws XMLStreamException,
+ ContributionReadException {
+ List<Extension> values = new ArrayList<Extension>();
+ QName name = reader.getName(); // Should be sca:property
+
+ // SCA 1.1 supports the @value for simple types
+ String valueAttr = getString(reader, VALUE);
+ if (valueAttr != null) {
+ Extension ext = assemblyFactory.createExtension();
+ ext.setValue(valueAttr);
+ ext.setQName(VALUE_QNAME);
+ ext.setAttribute(true);
+ values.add(ext);
+ }
+
+ boolean isTextForProperty = true;
+ StringBuffer text = new StringBuffer();
+
+ int event = reader.getEventType();
+ while (true) {
+ switch (event) {
+ case START_ELEMENT:
+ name = reader.getName();
+ if (PROPERTY_QNAME.equals(name)) {
+ isTextForProperty = true;
+ continue;
+ }
+ isTextForProperty = false;
+ // Read <value>
+ if (VALUE_QNAME.equals(name)) {
+ Object value = extensionProcessor.read(reader);
+ // Assume the value is the XMLStreamReader for the content
+ Extension ext = assemblyFactory.createExtension();
+ ext.setValue(value);
+ ext.setQName(name);
+ values.add(ext);
+ } else {
+ // Global elements
+ // FIXME: do we want to check if the element mataches property.element
+ Object value = extensionProcessor.read(reader);
+ Extension ext = assemblyFactory.createExtension();
+ ext.setValue(value);
+ ext.setQName(name);
+ values.add(ext);
+ }
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ case XMLStreamConstants.CDATA:
+ if (isTextForProperty) {
+ text.append(reader.getText());
+ }
+ break;
+ case END_ELEMENT:
+ name = reader.getName();
+ if (PROPERTY_QNAME.equals(name)) {
+ return values;
+ }
+ break;
+ }
+ }
+ }
+
/**
* Read a property value into a DOM document.
* @param element
@@ -441,7 +504,6 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor {
*/
protected Document readPropertyValue(QName element, QName type, XMLStreamReader reader) throws XMLStreamException,
ContributionReadException {
-
Document document;
try {
if (documentBuilderFactory == null) {
@@ -703,7 +765,10 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor {
if (attributeValue instanceof Extension) {
attributeExtension = (Extension)attributeValue;
} else {
- attributeExtension = extensionFactory.createExtension(attributeName, attributeValue, true);
+ attributeExtension = assemblyFactory.createExtension();
+ attributeExtension.setQName(attributeName);
+ attributeExtension.setAttribute(true);
+ attributeExtension.setValue(attributeValue);
}
estensibleElement.getAttributeExtensions().add(attributeExtension);
}
diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java
index 7222ae19ff..b952ea363f 100644
--- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java
+++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java
@@ -73,6 +73,8 @@ public interface Constants {
QName BINDING_SCA_QNAME = new QName(Constants.SCA11_NS, BINDING_SCA);
String NAME = "name";
+ String VALUE = "value";
+ QName VALUE_QNAME = new QName(SCA11_NS, VALUE);
String TARGET_NAMESPACE = "targetNamespace";
String LOCAL = "local";
String AUTOWIRE = "autowire";
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java
index 7963f05a0a..cfba7bdc8d 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.assembly;
+
/**
* A factory for the assembly model
*
@@ -146,6 +147,13 @@ public interface AssemblyFactory {
Wire createWire();
/**
+ * Create an Extension
+ * @return
+ */
+ Extension createExtension();
+
+
+ /**
* Create a new endpoint
*
* @return a new endpoint
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.java
index 2ed02e214b..e6e8eaf90a 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.java
@@ -23,14 +23,18 @@ import javax.xml.namespace.QName;
import org.apache.tuscany.sca.assembly.impl.ExtensionImpl;
+/**
+ * @deprecated
+ */
+@Deprecated
public class DefaultExtensionFactory implements ExtensionFactory {
- public Extension createExtension() {
- return new ExtensionImpl();
- }
+ public Extension createExtension() {
+ return new ExtensionImpl();
+ }
- public Extension createExtension(QName name, Object value, boolean isAttribute) {
- return new ExtensionImpl(name, value, isAttribute);
- }
+ public Extension createExtension(QName name, Object value, boolean isAttribute) {
+ return new ExtensionImpl(name, value, isAttribute);
+ }
}
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.java
index ca37c93e8a..4d5b1a2ecd 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.java
@@ -61,5 +61,5 @@ public interface Extension {
* Set whether or not the extension is an attribute
* @param value
*/
- void setIsAttribute(boolean isAttribute);
+ void setAttribute(boolean isAttribute);
}
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.java
index 214cf59748..20b480d762 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.java
@@ -19,10 +19,13 @@
package org.apache.tuscany.sca.assembly;
import javax.xml.namespace.QName;
-
+/**
+ * @deprecated Use AssemblyFactory directly
+ */
+@Deprecated
public interface ExtensionFactory {
- Extension createExtension();
-
- Extension createExtension(QName qName, Object value, boolean isAttribute);
+ Extension createExtension();
+
+ Extension createExtension(QName qName, Object value, boolean isAttribute);
}
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java
index bd999d77c5..e9939a2d2c 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java
@@ -35,6 +35,7 @@ import org.apache.tuscany.sca.assembly.CompositeService;
import org.apache.tuscany.sca.assembly.ConstrainingType;
import org.apache.tuscany.sca.assembly.Endpoint2;
import org.apache.tuscany.sca.assembly.EndpointReference2;
+import org.apache.tuscany.sca.assembly.Extension;
import org.apache.tuscany.sca.assembly.Property;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.Service;
@@ -114,7 +115,11 @@ public abstract class AssemblyFactoryImpl implements AssemblyFactory {
public Wire createWire() {
return new WireImpl();
}
-
+
+ public Extension createExtension() {
+ return new ExtensionImpl();
+ }
+
public Endpoint2 createEndpoint() {
return new Endpoint2Impl();
}
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.java
index 3aad253a03..9befad9f2b 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.java
@@ -56,7 +56,7 @@ public class ExtensionImpl implements Extension {
return isAttribute;
}
- public void setIsAttribute(boolean isAttribute) {
+ public void setAttribute(boolean isAttribute) {
this.isAttribute = isAttribute;
}
}
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java
index e27ac9fcab..aad7747522 100644
--- a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java
@@ -23,8 +23,8 @@ 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.Extension;
-import org.apache.tuscany.sca.assembly.ExtensionFactory;
import org.apache.tuscany.sca.contribution.Constants;
import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
@@ -43,10 +43,10 @@ import org.apache.tuscany.sca.monitor.Monitor;
public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements StAXAttributeProcessor<Extension> {
private static final QName ANY_ATTRIBUTE = new QName(Constants.XMLSCHEMA_NS, "anyAttribute");
- private ExtensionFactory extensionFactory;
+ private AssemblyFactory assemblyFactory;
public AnyAttributeProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
- this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class);
+ this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
}
public QName getArtifactType() {
@@ -59,7 +59,11 @@ public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements
public Extension read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
String attributeValue = reader.getAttributeValue(attributeName.getNamespaceURI(), attributeName.getLocalPart());
- return extensionFactory.createExtension(attributeName, attributeValue, true);
+ Extension ext = assemblyFactory.createExtension();
+ ext.setQName(attributeName);
+ ext.setAttribute(true);
+ ext.setValue(attributeValue);
+ return ext;
}
public void write(Extension attributeExtension, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {