You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2007/09/03 01:20:04 UTC
svn commit: r572188 - in
/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml:
BaseArtifactProcessor.java ComponentTypeProcessor.java
CompositeProcessor.java ConstrainingTypeProcessor.java XAttr.java
Author: jsdelfino
Date: Sun Sep 2 16:20:03 2007
New Revision: 572188
URL: http://svn.apache.org/viewvc?rev=572188&view=rev
Log:
Fixed artifact processors to write correct SCA assembly XML. Also simplified and cleaned up the reading of properties.
Modified:
incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseArtifactProcessor.java
incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java
incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java
incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/XAttr.java
Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseArtifactProcessor.java?rev=572188&r1=572187&r2=572188&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseArtifactProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseArtifactProcessor.java Sun Sep 2 16:20:03 2007
@@ -33,10 +33,12 @@
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.dom.DOMSource;
import org.apache.tuscany.sca.assembly.AbstractContract;
import org.apache.tuscany.sca.assembly.AbstractProperty;
@@ -49,8 +51,8 @@
import org.apache.tuscany.sca.assembly.Contract;
import org.apache.tuscany.sca.assembly.Implementation;
import org.apache.tuscany.sca.assembly.Multiplicity;
-import org.apache.tuscany.sca.assembly.Property;
import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
@@ -67,6 +69,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* A base class with utility methods for the other artifact processors in this module.
@@ -79,11 +82,7 @@
protected AssemblyFactory assemblyFactory;
protected PolicyFactory policyFactory;
protected StAXArtifactProcessor<Object> extensionProcessor;
-
- private static final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
- static {
- domFactory.setNamespaceAware(true);
- }
+ private DocumentBuilderFactory documentBuilderFactory;
/**
* Construcst a new BaseArtifactProcessor.
@@ -219,25 +218,38 @@
* @param attachPoint
* @param reader
*/
- protected void readIntents(IntentAttachPoint attachPoint, XMLStreamReader reader) {
+ protected void readIntents(Object attachPoint, XMLStreamReader reader) {
readIntents(attachPoint, null, reader);
}
/**
+ * Write policy intents
+ * @param attachPoint
+ */
+ protected XAttr writeIntents(Object attachPoint) {
+ return writeIntents(attachPoint, null);
+ }
+
+ /**
* Read policy intents associated with an operation.
* @param attachPoint
* @param operation
* @param reader
*/
- protected void readIntents(IntentAttachPoint attachPoint, Operation operation, XMLStreamReader reader) {
+ protected void readIntents(Object attachPoint, Operation operation, XMLStreamReader reader) {
+ if (!(attachPoint instanceof IntentAttachPoint))
+ return;
+ IntentAttachPoint intentAttachPoint = (IntentAttachPoint)attachPoint;
String value = reader.getAttributeValue(null, Constants.REQUIRES);
if (value != null) {
- List<Intent> requiredIntents = attachPoint.getRequiredIntents();
+ List<Intent> requiredIntents = intentAttachPoint.getRequiredIntents();
for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
QName qname = getQNameValue(reader, tokens.nextToken());
Intent intent = policyFactory.createIntent();
intent.setName(qname);
if (operation != null) {
+ //FIXME Don't we need to handle intent specification
+ // on an operation basis?
//intent.getOperations().add(operation);
}
requiredIntents.add(intent);
@@ -246,33 +258,97 @@
}
/**
+ * Write policy intents associated with an operation.
+ * @param attachPoint
+ * @param operation
+ */
+ protected XAttr writeIntents(Object attachPoint, Operation operation) {
+ if (!(attachPoint instanceof IntentAttachPoint)) {
+ return null;
+ }
+ IntentAttachPoint intentAttachPoint = (IntentAttachPoint)attachPoint;
+ List<QName> qnames = new ArrayList<QName>();
+ for (Intent intent: intentAttachPoint.getRequiredIntents()) {
+ qnames.add(intent.getName());
+ }
+ return new XAttr(Constants.REQUIRES, qnames);
+ }
+
+ /**
* Reads policy intents and policy sets.
* @param attachPoint
* @param reader
*/
protected void readPolicies(Object attachPoint, XMLStreamReader reader) {
- if (attachPoint instanceof PolicySetAttachPoint) {
- readPolicies((PolicySetAttachPoint)attachPoint, null, reader);
- }
+ readPolicies(attachPoint, null, reader);
}
/**
+ * Writes policy intents and policy sets.
+ * @param attachPoint
+ */
+ protected XAttr writePolicySets(Object attachPoint) {
+ return writePolicySets(attachPoint, null);
+ }
+
+ /**
+ * Write policy sets associated with an operation.
+ * @param attachPoint
+ * @param operation
+ */
+ protected XAttr writePolicySets(Object attachPoint, Operation operation) {
+ if (!(attachPoint instanceof PolicySetAttachPoint)) {
+ return null;
+ }
+ PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint;
+ List<QName> qnames = new ArrayList<QName>();
+ for (PolicySet policySet: policySetAttachPoint.getPolicySets()) {
+ qnames.add(policySet.getName());
+ }
+ return new XAttr(Constants.POLICY_SETS, qnames);
+ }
+
+ /**
* Reads policy intents and policy sets associated with an operation.
* @param attachPoint
* @param operation
* @param reader
*/
- protected void readPolicies(PolicySetAttachPoint attachPoint, Operation operation, XMLStreamReader reader) {
+ protected void readPolicies(Object attachPoint, Operation operation, XMLStreamReader reader) {
readIntents(attachPoint, operation, reader);
+ readPolicySets(attachPoint, operation, reader);
+ }
+ /**
+ * Reads policy sets.
+ * @param attachPoint
+ * @param reader
+ */
+ protected void readPolicySets(Object attachPoint, XMLStreamReader reader) {
+ readPolicySets(attachPoint, null, reader);
+ }
+
+ /**
+ * Reads policy sets associated with an operation.
+ * @param attachPoint
+ * @param operation
+ * @param reader
+ */
+ protected void readPolicySets(Object attachPoint, Operation operation, XMLStreamReader reader) {
+ if (!(attachPoint instanceof PolicySetAttachPoint)) {
+ return;
+ }
+ PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint;
String value = reader.getAttributeValue(null, Constants.POLICY_SETS);
if (value != null) {
- List<PolicySet> policySets = attachPoint.getPolicySets();
+ List<PolicySet> policySets = policySetAttachPoint.getPolicySets();
for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
QName qname = getQNameValue(reader, tokens.nextToken());
PolicySet policySet = policyFactory.createPolicySet();
policySet.setName(qname);
if (operation != null) {
+ //FIXME Don't we need to handle policySet specification
+ // on an operation basis?
//policySet.getOperations().add(operation);
}
policySets.add(policySet);
@@ -286,7 +362,7 @@
* @param reader
*/
protected void readTargets(Reference reference, XMLStreamReader reader) {
- String value = reader.getAttributeValue(null, Constants.TARGET);
+ String value = reader.getAttributeValue(null, TARGET);
ComponentService target = null;
if (value != null) {
for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
@@ -297,6 +373,19 @@
}
}
}
+
+ /**
+ * Write a list of targets into an attribute
+ * @param reference
+ * @return
+ */
+ protected XAttr writeTargets(Reference reference) {
+ List<String> targets = new ArrayList<String>();
+ for (Service target: reference.getTargets()) {
+ targets.add(target.getName());
+ }
+ return new XAttr(TARGET, targets);
+ }
/**
* Read a multiplicity attribute.
@@ -319,8 +408,8 @@
* @param reader
* @return
*/
- protected ConstrainingType getConstrainingType(XMLStreamReader reader) {
- QName constrainingTypeName = getQName(reader, "constrainingType");
+ protected ConstrainingType readConstrainingType(XMLStreamReader reader) {
+ QName constrainingTypeName = getQName(reader, Constants.CONSTRAINING_TYPE);
if (constrainingTypeName != null) {
ConstrainingType constrainingType = assemblyFactory.createConstrainingType();
constrainingType.setName(constrainingTypeName);
@@ -333,36 +422,19 @@
/**
* Reads an abstract property element.
- * @param prop
+ * @param property
* @param reader
* @throws XMLStreamException
* @throws ContributionReadException
*/
- protected void readAbstractProperty(AbstractProperty prop, XMLStreamReader reader) throws XMLStreamException,
- ContributionReadException {
- prop.setName(getString(reader, "name"));
- prop.setMany(getBoolean(reader, "many"));
- prop.setMustSupply(getBoolean(reader, "mustSupply"));
- prop.setXSDElement(getQName(reader, "element"));
- prop.setXSDType(getQName(reader, "type"));
- try {
- Document value = readPropertyValue(reader, prop.getXSDType());
- prop.setValue(value);
- } catch (ParserConfigurationException e) {
- throw new ContributionReadException(e);
- }
- }
-
- /**
- * Reads a property element.
- * @param prop
- * @param reader
- * @throws XMLStreamException
- * @throws ContributionReadException
- */
- protected void readProperty(Property prop, XMLStreamReader reader) throws XMLStreamException,
- ContributionReadException {
- readAbstractProperty(prop, reader);
+ protected void readAbstractProperty(AbstractProperty property, XMLStreamReader reader)
+ throws XMLStreamException, ContributionReadException {
+
+ property.setName(getString(reader, NAME));
+ property.setMany(getBoolean(reader, MANY));
+ property.setMustSupply(getBoolean(reader, MUST_SUPPLY));
+ property.setXSDElement(getQName(reader, ELEMENT));
+ property.setXSDType(getQName(reader, TYPE));
}
/**
@@ -588,53 +660,46 @@
}
/**
- * Write an SCA abstract property declaration.
- * @param writer
- * @param prop
- */
- protected void writeAbstractProperty(XMLStreamWriter writer, AbstractProperty prop) throws XMLStreamException {
- }
-
- /**
- * Write an SCA property declaration.
- * @param writer
- * @param prop
- */
- protected void writeProperty(XMLStreamWriter writer, Property prop) throws XMLStreamException {
- writeAbstractProperty(writer, prop);
- }
-
- /**
* Returns a constrainingType attribute.
* @param componentType
* @return
*/
- protected QName getConstrainingTypeAttr(ComponentType componentType) {
+ protected XAttr writeConstrainingType(ComponentType componentType) {
ConstrainingType constrainingType = componentType.getConstrainingType();
if (constrainingType != null)
- return constrainingType.getName();
+ return new XAttr(Constants.CONSTRAINING_TYPE, constrainingType.getName());
else
return null;
}
/**
* Read a property value into a DOM document.
- * @param reader
+ * @param element
* @param type
+ * @param reader
* @return
* @throws XMLStreamException
* @throws ContributionReadException
* @throws ParserConfigurationException
*/
- protected Document readPropertyValue(XMLStreamReader reader, QName type) throws XMLStreamException,
- ParserConfigurationException {
+ protected Document readPropertyValue(QName element, QName type, XMLStreamReader reader)
+ throws XMLStreamException, ContributionReadException {
- Document doc = createDocument();
+ Document document;
+ try {
+ if (documentBuilderFactory == null) {
+ documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ }
+ document = documentBuilderFactory.newDocumentBuilder().newDocument();
+ } catch (ParserConfigurationException e) {
+ throw new ContributionReadException(e);
+ }
// root element has no namespace and local name "value"
- Element root = doc.createElementNS(null, "value");
+ Element root = document.createElementNS(null, "value");
if (type != null) {
- org.w3c.dom.Attr xsi = doc.createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi");
+ org.w3c.dom.Attr xsi = document.createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi");
xsi.setValue(W3C_XML_SCHEMA_INSTANCE_NS_URI);
root.setAttributeNodeNS(xsi);
@@ -645,23 +710,14 @@
declareNamespace(root, prefix, type.getNamespaceURI());
- org.w3c.dom.Attr xsiType = doc.createAttributeNS(W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:type");
+ org.w3c.dom.Attr xsiType = document.createAttributeNS(W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:type");
xsiType.setValue(prefix + ":" + type.getLocalPart());
root.setAttributeNodeNS(xsiType);
}
- doc.appendChild(root);
+ document.appendChild(root);
loadElement(reader, root);
- return doc;
- }
-
- /**
- * Create a new DOM document.
- * @return
- * @throws ContributionReadException
- */
- private Document createDocument() throws ParserConfigurationException {
- return domFactory.newDocumentBuilder().newDocument();
+ return document;
}
/**
@@ -815,5 +871,68 @@
policySets.clear();
policySets.addAll(resolvedPolicySets);
}
-
+
+ /**
+ * Write the value of a property
+ * @param document
+ * @param element
+ * @param type
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void writePropertyValue(Object propertyValue, QName element, QName type, XMLStreamWriter writer) throws XMLStreamException {
+
+ if (propertyValue instanceof Document) {
+ Document document = (Document)propertyValue;
+ NodeList nodeList = document.getDocumentElement().getChildNodes();
+
+ for (int item = 0; item < nodeList.getLength(); ++item) {
+ if (nodeList.item(item).getNodeType() == Node.ELEMENT_NODE) {
+ XMLStreamReader reader =
+ XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(nodeList.item(item)));
+
+ while (reader.hasNext()) {
+ switch (reader.next()) {
+ case XMLStreamConstants.START_ELEMENT:
+ QName name = reader.getName();
+ writer.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI());
+
+ int namespaces = reader.getNamespaceCount();
+ for (int i = 0; i < namespaces; i++) {
+ String prefix = reader.getNamespacePrefix(i);
+ String ns = reader.getNamespaceURI(i);
+ writer.writeNamespace(prefix, ns);
+ }
+
+ if (!"".equals(name.getNamespaceURI())) {
+ writer.writeNamespace(name.getPrefix(), name.getNamespaceURI());
+ }
+
+ // add the attributes for this element
+ namespaces = reader.getAttributeCount();
+ for (int i = 0; i < namespaces; i++) {
+ String ns = reader.getAttributeNamespace(i);
+ String prefix = reader.getAttributePrefix(i);
+ String qname = reader.getAttributeLocalName(i);
+ String value = reader.getAttributeValue(i);
+
+ writer.writeAttribute(prefix, ns, qname, value);
+ }
+
+ break;
+ case XMLStreamConstants.CDATA:
+ writer.writeCData(reader.getText());
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ writer.writeCharacters(reader.getText());
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ writer.writeEndElement();
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
}
Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java?rev=572188&r1=572187&r2=572188&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java Sun Sep 2 16:20:03 2007
@@ -22,16 +22,12 @@
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
-import java.util.ArrayList;
-import java.util.List;
-
import javax.xml.namespace.QName;
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.Base;
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.Callback;
import org.apache.tuscany.sca.assembly.ComponentType;
@@ -47,8 +43,10 @@
import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
import org.apache.tuscany.sca.policy.PolicyFactory;
import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.w3c.dom.Document;
/**
* A componentType processor.
@@ -89,8 +87,7 @@
// Read a <componentType>
componentType = assemblyFactory.createComponentType();
- componentType.setConstrainingType(getConstrainingType(reader));
- readPolicies(componentType, reader);
+ componentType.setConstrainingType(readConstrainingType(reader));
} else if (Constants.SERVICE_QNAME.equals(name)) {
@@ -102,6 +99,7 @@
readPolicies(service, reader);
} else if (Constants.REFERENCE_QNAME.equals(name)) {
+
// Read a <reference>
reference = assemblyFactory.createReference();
contract = reference;
@@ -116,8 +114,13 @@
// Read a <property>
property = assemblyFactory.createProperty();
+ readAbstractProperty(property, reader);
readPolicies(property, reader);
- readProperty(property, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
+ property.setValue(value);
+
componentType.getProperties().add(property);
} else if (Constants.IMPLEMENTATION_QNAME.equals(name)) {
@@ -210,31 +213,21 @@
return componentType;
}
- public void validate(ComponentType componentType, List<Base> problems) {
- if (problems == null) {
- problems = new ArrayList<Base>();
- }
- validatePropertyDefinitions(componentType.getProperties(), problems);
- }
-
- public void validatePropertyDefinitions(List<Property> properties, List<Base> problems) {
- for(Property aProperty : properties) {
- if (aProperty.isMustSupply() && aProperty.getValue() != null) {
- problems.add(aProperty);
- }
- }
- }
-
public void write(ComponentType componentType, XMLStreamWriter writer) throws ContributionWriteException {
try {
+ // Write <componentType> element
writeStartDocument(writer, COMPONENT_TYPE,
- new XAttr(CONSTRAINING_TYPE, getConstrainingTypeAttr(componentType)));
+ writeConstrainingType(componentType));
+ // Write <service> elements
for (Service service : componentType.getServices()) {
- writeStart(writer, SERVICE, new XAttr(NAME, service.getName()));
+ writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
+ writeIntents(service), writePolicySets(service));
- extensionProcessor.write(service.getInterfaceContract(), writer);
+ if (service.getInterfaceContract() != null) {
+ extensionProcessor.write(service.getInterfaceContract(), writer);
+ }
for (Binding binding: service.getBindings()) {
extensionProcessor.write(binding, writer);
@@ -242,7 +235,7 @@
if (service.getCallback() != null) {
Callback callback = service.getCallback();
- writeStart(writer, CALLBACK);
+ writeStart(writer, CALLBACK, writeIntents(callback), writePolicySets(callback));
for (Binding binding: callback.getBindings()) {
extensionProcessor.write(binding, writer);
@@ -253,20 +246,21 @@
writeEnd(writer);
}
-
+
for (Object extension: service.getExtensions()) {
extensionProcessor.write(extension, writer);
}
writeEnd(writer);
}
-
+
+ // Write <reference> elements
for (Reference reference : componentType.getReferences()) {
- // TODO handle multivalued target attribute
- String target = reference.getTargets().isEmpty() ? null : reference.getTargets().get(0).getName();
+
writeStart(writer, REFERENCE,
new XAttr(NAME, reference.getName()),
- new XAttr(TARGET, target));
+ writeTargets(reference),
+ writeIntents(reference), writePolicySets(reference));
extensionProcessor.write(reference.getInterfaceContract(), writer);
@@ -276,7 +270,8 @@
if (reference.getCallback() != null) {
Callback callback = reference.getCallback();
- writeStart(writer, CALLBACK);
+ writeStart(writer, CALLBACK,
+ writeIntents(callback), writePolicySets(callback));
for (Binding binding: callback.getBindings()) {
extensionProcessor.write(binding, writer);
@@ -295,20 +290,51 @@
writeEnd(writer);
}
+ // Write <property> elements
for (Property property : componentType.getProperties()) {
- writeStart(writer, PROPERTY, new XAttr(NAME, property.getName()));
+ writeStart(writer,
+ PROPERTY,
+ new XAttr(NAME, property.getName()),
+ new XAttr(MUST_SUPPLY, property.isMustSupply()),
+ new XAttr(MANY, property.isMany()),
+ new XAttr(TYPE, property.getXSDType()),
+ new XAttr(ELEMENT, property.getXSDElement()),
+ writeIntents(property));
- for (Object extension: property.getExtensions()) {
+ // Write property value
+ writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);
+
+ // Write extensions
+ for (Object extension : property.getExtensions()) {
extensionProcessor.write(extension, writer);
}
-
+
writeEnd(writer);
}
+ // Write extension elements
if (componentType instanceof Extensible) {
for (Object extension: ((Extensible)componentType).getExtensions()) {
extensionProcessor.write(extension, writer);
}
+ }
+
+ // Write <implementation> elements if the componentType has
+ // any intents or policySets
+ boolean writeImplementation = false;
+ if (componentType instanceof IntentAttachPoint) {
+ if (!((IntentAttachPoint)componentType).getRequiredIntents().isEmpty()) {
+ writeImplementation = true;
+ }
+ }
+ if (componentType instanceof PolicySetAttachPoint) {
+ if (!((PolicySetAttachPoint)componentType).getPolicySets().isEmpty()) {
+ writeImplementation = true;
+ }
+ }
+ if (writeImplementation) {
+ writeStart(writer, IMPLEMENTATION,
+ writeIntents(componentType), writePolicySets(componentType));
}
writeEndDocument(writer);
Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java?rev=572188&r1=572187&r2=572188&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java Sun Sep 2 16:20:03 2007
@@ -22,15 +22,15 @@
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import java.util.ArrayList;
+import java.util.List;
import java.util.StringTokenizer;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.dom.DOMSource;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Binding;
@@ -62,8 +62,6 @@
import org.apache.tuscany.sca.policy.PolicyFactory;
import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
/**
* A composite processor.
@@ -133,7 +131,7 @@
composite.setAutowire(getBoolean(reader, AUTOWIRE));
}
composite.setLocal(getBoolean(reader, LOCAL));
- composite.setConstrainingType(getConstrainingType(reader));
+ composite.setConstrainingType(readConstrainingType(reader));
readPolicies(composite, reader);
} else if (INCLUDE_QNAME.equals(name)) {
@@ -224,20 +222,31 @@
} else if (PROPERTY_QNAME.equals(name)) {
if (component != null) {
+
// Read a <component><property>
componentProperty = assemblyFactory.createComponentProperty();
property = componentProperty;
componentProperty.setSource(getString(reader, SOURCE));
componentProperty.setFile(getString(reader, FILE));
readPolicies(property, reader);
- readProperty(componentProperty, reader);
+ readAbstractProperty(componentProperty, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
+ property.setValue(value);
+
component.getProperties().add(componentProperty);
} else {
// Read a <composite><property>
property = assemblyFactory.createProperty();
readPolicies(property, reader);
- readProperty(property, reader);
+ readAbstractProperty(property, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
+ property.setValue(value);
+
composite.getProperties().add(property);
}
@@ -249,7 +258,7 @@
if (isSet(reader, AUTOWIRE)) {
component.setAutowire(getBoolean(reader, AUTOWIRE));
}
- component.setConstrainingType(getConstrainingType(reader));
+ component.setConstrainingType(readConstrainingType(reader));
composite.getComponents().add(component);
readPolicies(component, reader);
@@ -409,310 +418,270 @@
}
}
- public void writeComponentReference(ComponentReference reference, XMLStreamWriter writer)
- throws XMLStreamException, ContributionWriteException {
- // TODO handle multivalued target attribute
- String target = reference.getTargets().isEmpty() ? null : reference.getTargets().get(0).getName();
- Boolean autowire = reference.getAutowire();
- XAttr autowireAttr = autowire == null ? null : new XAttr(AUTOWIRE, autowire.toString());
- writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()), new XAttr(TARGET, target), autowireAttr);
-
- extensionProcessor.write(reference.getInterfaceContract(), writer);
-
- for (Binding binding : reference.getBindings()) {
- extensionProcessor.write(binding, writer);
- }
-
- if (reference.getCallback() != null) {
- Callback callback = reference.getCallback();
- writeStart(writer, CALLBACK);
-
- for (Binding binding : callback.getBindings()) {
- extensionProcessor.write(binding, writer);
- }
- for (Object extension : callback.getExtensions()) {
- extensionProcessor.write(extension, writer);
- }
-
- writeEnd(writer);
- }
-
- for (Object extension : reference.getExtensions()) {
- extensionProcessor.write(extension, writer);
- }
-
- writeEnd(writer);
- }
-
- public void writeCompositeService(Service service, XMLStreamWriter writer) throws ContributionWriteException,
- XMLStreamException {
- CompositeService compositeService = (CompositeService)service;
- Component promotedComponent = compositeService.getPromotedComponent();
- ComponentService promotedService = compositeService.getPromotedService();
- String promote;
- if (promotedService != null) {
- if (promotedService.getName() != null) {
- promote = promotedComponent.getName() + '/' + promotedService.getService();
- } else {
- promote = promotedComponent.getName();
- }
- } else {
- promote = null;
- }
- writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), new XAttr(PROMOTE, promote));
-
- extensionProcessor.write(service.getInterfaceContract(), writer);
-
- for (Binding binding : service.getBindings()) {
- extensionProcessor.write(binding, writer);
- }
-
- if (service.getCallback() != null) {
- Callback callback = service.getCallback();
- writeStart(writer, CALLBACK);
-
- for (Binding binding : callback.getBindings()) {
- extensionProcessor.write(binding, writer);
- }
- for (Object extension : callback.getExtensions()) {
- extensionProcessor.write(extension, writer);
- }
-
- writeEnd(writer);
- }
-
- for (Object extension : service.getExtensions()) {
- extensionProcessor.write(extension, writer);
- }
-
- writeEnd(writer);
- }
-
- public void writeComponentService(ComponentService service, XMLStreamWriter writer)
- throws ContributionWriteException, XMLStreamException {
- writeStart(writer, SERVICE, new XAttr(NAME, service.getName()));
-
- extensionProcessor.write(service.getInterfaceContract(), writer);
-
- for (Binding binding : service.getBindings()) {
- extensionProcessor.write(binding, writer);
- }
-
- if (service.getCallback() != null) {
- Callback callback = service.getCallback();
- writeStart(writer, CALLBACK);
-
- for (Binding binding : callback.getBindings()) {
- extensionProcessor.write(binding, writer);
- }
- for (Object extension : callback.getExtensions()) {
- extensionProcessor.write(extension, writer);
- }
-
- writeEnd(writer);
- }
-
- for (Object extension : service.getExtensions()) {
- extensionProcessor.write(extension, writer);
- }
-
- writeEnd(writer);
- }
-
- public void writeComponent(Composite composite, Component component, XMLStreamWriter writer)
- throws ContributionWriteException, XMLStreamException {
- Boolean autowire = component.getAutowire();
- XAttr autowireAttr = autowire == null ? null : new XAttr(AUTOWIRE, autowire.toString());
-
- writeStart(writer, COMPONENT, new XAttr(NAME, component.getName()), autowireAttr);
-
- for (ComponentService service : component.getServices()) {
- writeComponentService(service, writer);
- }
-
- for (ComponentReference reference : component.getReferences()) {
- writeComponentReference(reference, writer);
- }
-
- for (ComponentProperty property : component.getProperties()) {
- writeProperty(property, writer);
- }
-
- // Write the component implementation
- Implementation implementation = component.getImplementation();
- if (implementation instanceof Composite) {
- writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, composite.getName()));
- writeEnd(writer);
- } else {
- extensionProcessor.write(component.getImplementation(), writer);
- }
-
- writeEnd(writer);
- }
-
- public void writeCompositeReference(Reference reference, XMLStreamWriter writer) throws ContributionWriteException,
- XMLStreamException {
- //TODO handle multivalued promote attribute
- CompositeReference compositeReference = (CompositeReference)reference;
- String promote;
- if (!compositeReference.getPromotedReferences().isEmpty())
- promote = compositeReference.getPromotedReferences().get(0).getName();
- else
- promote = null;
- writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()), new XAttr(PROMOTE, promote));
-
- extensionProcessor.write(reference.getInterfaceContract(), writer);
-
- for (Binding binding : reference.getBindings()) {
- extensionProcessor.write(binding, writer);
- }
-
- if (reference.getCallback() != null) {
- Callback callback = reference.getCallback();
- writeStart(writer, CALLBACK);
-
- for (Binding binding : callback.getBindings()) {
- extensionProcessor.write(binding, writer);
- }
- for (Object extension : callback.getExtensions()) {
- extensionProcessor.write(extension, writer);
- }
-
- writeEnd(writer);
- }
-
- for (Object extension : reference.getExtensions()) {
- extensionProcessor.write(extension, writer);
- }
-
- writeEnd(writer);
- }
-
- public void writeProperty(Property property, XMLStreamWriter writer) throws XMLStreamException,
- ContributionWriteException {
-
- if (property instanceof ComponentProperty) {
- ComponentProperty componentProperty = (ComponentProperty)property;
- writeStart(writer,
- PROPERTY,
- new XAttr(NAME, componentProperty.getName()),
- new XAttr(MUST_SUPPLY, componentProperty.isMustSupply()),
- new XAttr(MANY, componentProperty.isMany()),
- new XAttr(TYPE, componentProperty.getXSDType()),
- new XAttr(ELEMENT, componentProperty.getXSDElement()),
- new XAttr(SOURCE, componentProperty.getSource()),
- new XAttr(FILE, componentProperty.getFile()));
-
- } else {
- writeStart(writer,
- PROPERTY,
- new XAttr(NAME, property.getName()),
- new XAttr(MUST_SUPPLY, property.isMustSupply()),
- new XAttr(MANY, property.isMany()),
- new XAttr(TYPE, property.getXSDType()),
- new XAttr(ELEMENT, property.getXSDElement()));
-
- }
-
- if (property.getValue() != null && property.getValue() instanceof Document) {
- try {
- Document document = (Document)property.getValue();
- NodeList nodeList = document.getDocumentElement().getChildNodes();
-
- for (int count = 0; count < nodeList.getLength(); ++count) {
- if (nodeList.item(count).getNodeType() == Node.ELEMENT_NODE) {
- XMLStreamReader reader =
- XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(nodeList.item(count)));
- writeElement(reader, writer);
- }
- }
- } catch (Exception e) {
- throw new ContributionWriteException(e);
- }
- }
-
- for (Object extension : property.getExtensions()) {
- extensionProcessor.write(extension, writer);
- }
-
- writeEnd(writer);
- }
-
- private void writeElement(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- while (reader.hasNext()) {
- switch (reader.next()) {
- case XMLStreamConstants.START_ELEMENT:
- QName name = reader.getName();
- writer.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI());
-
- int count = reader.getNamespaceCount();
- for (int i = 0; i < count; i++) {
- String prefix = reader.getNamespacePrefix(i);
- String ns = reader.getNamespaceURI(i);
- writer.writeNamespace(prefix, ns);
- }
-
- if (!"".equals(name.getNamespaceURI())) {
- writer.writeNamespace(name.getPrefix(), name.getNamespaceURI());
- }
-
- // add the attributes for this element
- count = reader.getAttributeCount();
- for (int i = 0; i < count; i++) {
- String ns = reader.getAttributeNamespace(i);
- String prefix = reader.getAttributePrefix(i);
- String qname = reader.getAttributeLocalName(i);
- String value = reader.getAttributeValue(i);
-
- writer.writeAttribute(prefix, ns, qname, value);
- }
-
- break;
- case XMLStreamConstants.CDATA:
- writer.writeCData(reader.getText());
- break;
- case XMLStreamConstants.CHARACTERS:
- writer.writeCharacters(reader.getText());
- break;
- case XMLStreamConstants.END_ELEMENT:
- writer.writeEndElement();
- break;
- }
- }
- }
-
public void write(Composite composite, XMLStreamWriter writer) throws ContributionWriteException {
try {
- Boolean autowire = composite.getAutowire();
- XAttr autowireAttr = autowire == null ? null : new XAttr(AUTOWIRE, autowire.toString());
-
+ // Write <composite> element
writeStartDocument(writer,
COMPOSITE,
- new XAttr(CONSTRAINING_TYPE, getConstrainingTypeAttr(composite)),
+ writeConstrainingType(composite),
new XAttr(TARGET_NAMESPACE, composite.getName().getNamespaceURI()),
new XAttr(NAME, composite.getName().getLocalPart()),
- autowireAttr);
+ new XAttr(AUTOWIRE, composite.getAutowire()),
+ writeIntents(composite),
+ writePolicySets(composite));
+ // Write <service> elements
for (Service service : composite.getServices()) {
- writeCompositeService(service, writer);
+ CompositeService compositeService = (CompositeService)service;
+ Component promotedComponent = compositeService.getPromotedComponent();
+ ComponentService promotedService = compositeService.getPromotedService();
+ String promote;
+ if (promotedService != null) {
+ if (promotedService.getName() != null) {
+ promote = promotedComponent.getName() + '/' + promotedService.getService();
+ } else {
+ promote = promotedComponent.getName();
+ }
+ } else {
+ promote = null;
+ }
+ writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), new XAttr(PROMOTE, promote),
+ writeIntents(service), writePolicySets(service));
+
+ // Write service interface
+ extensionProcessor.write(service.getInterfaceContract(), writer);
+
+ // Write bindings
+ for (Binding binding : service.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write <callback> element
+ if (service.getCallback() != null) {
+ Callback callback = service.getCallback();
+ writeStart(writer, CALLBACK, writeIntents(callback), writePolicySets(callback));
+
+ // Write callback bindings
+ for (Binding binding : callback.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write extensions
+ for (Object extension : callback.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write extensions
+ for (Object extension : service.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
}
+ // Write <component> elements
for (Component component : composite.getComponents()) {
- writeComponent(composite, component, writer);
+ writeStart(writer, COMPONENT, new XAttr(NAME, component.getName()),
+ new XAttr(AUTOWIRE, component.getAutowire()),
+ writeIntents(component), writePolicySets(component));
+
+ // Write <service> elements
+ for (ComponentService service : component.getServices()) {
+ writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
+ writeIntents(service), writePolicySets(service));
+
+ // Write service interface
+ extensionProcessor.write(service.getInterfaceContract(), writer);
+
+ // Write bindings
+ for (Binding binding : service.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write <callback> element
+ if (service.getCallback() != null) {
+ Callback callback = service.getCallback();
+ writeStart(writer, CALLBACK, writeIntents(callback), writePolicySets(callback));
+
+ // Write bindings
+ for (Binding binding : callback.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write extensions
+ for (Object extension : callback.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write extensions
+ for (Object extension : service.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <reference> elements
+ for (ComponentReference reference : component.getReferences()) {
+ writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
+ new XAttr(AUTOWIRE, reference.getAutowire()),
+ writeTargets(reference),
+ writeIntents(reference), writePolicySets(reference));
+
+ // Write reference interface
+ extensionProcessor.write(reference.getInterfaceContract(), writer);
+
+ // Write bindings
+ for (Binding binding : reference.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write callback
+ if (reference.getCallback() != null) {
+ Callback callback = reference.getCallback();
+ writeStart(writer, CALLBACK, writeIntents(callback), writePolicySets(callback));
+
+ // Write callback bindings
+ for (Binding binding : callback.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write extensions
+ for (Object extensions : callback.getExtensions()) {
+ extensionProcessor.write(extensions, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write extensions
+ for (Object extensions : reference.getExtensions()) {
+ extensionProcessor.write(extensions, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <property> elements
+ for (ComponentProperty property : component.getProperties()) {
+ writeStart(writer,
+ PROPERTY,
+ new XAttr(NAME, property.getName()),
+ new XAttr(MUST_SUPPLY, property.isMustSupply()),
+ new XAttr(MANY, property.isMany()),
+ new XAttr(TYPE, property.getXSDType()),
+ new XAttr(ELEMENT, property.getXSDElement()),
+ new XAttr(SOURCE, property.getSource()),
+ new XAttr(FILE, property.getFile()),
+ writeIntents(property), writePolicySets(property));
+
+ // Write property value
+ writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);
+
+ // Write extensions
+ for (Object extension : property.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write the component implementation
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, composite.getName()));
+ writeEnd(writer);
+ } else {
+ extensionProcessor.write(component.getImplementation(), writer);
+ }
+
+ writeEnd(writer);
}
+ // Write <reference> elements
for (Reference reference : composite.getReferences()) {
- writeCompositeReference(reference, writer);
+ CompositeReference compositeReference = (CompositeReference)reference;
+
+ // Write list of promoted references
+ List<String> promote = new ArrayList<String>();
+ for (ComponentReference promoted: compositeReference.getPromotedReferences()) {
+ promote.add(promoted.getName());
+ }
+
+ // Write <reference> element
+ writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
+ new XAttr(PROMOTE, promote),
+ writeIntents(reference), writePolicySets(reference));
+
+ // Write reference interface
+ extensionProcessor.write(reference.getInterfaceContract(), writer);
+
+ // Write bindings
+ for (Binding binding : reference.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write <callback> element
+ if (reference.getCallback() != null) {
+ Callback callback = reference.getCallback();
+ writeStart(writer, CALLBACK);
+
+ // Write callback bindings
+ for (Binding binding : callback.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write extensions
+ for (Object extension : callback.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write extensions
+ for (Object extension : reference.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
}
+ // Write <property> elements
for (Property property : composite.getProperties()) {
- writeProperty(property, writer);
+ writeStart(writer,
+ PROPERTY,
+ new XAttr(NAME, property.getName()),
+ new XAttr(MUST_SUPPLY, property.isMustSupply()),
+ new XAttr(MANY, property.isMany()),
+ new XAttr(TYPE, property.getXSDType()),
+ new XAttr(ELEMENT, property.getXSDElement()),
+ writeIntents(property), writePolicySets(property));
+
+ // Write property value
+ writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);
+
+ // Write extensions
+ for (Object extension : property.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
}
+ // Write <wire> elements
for (Wire wire : composite.getWires()) {
writeStart(writer, WIRE, new XAttr(SOURCE, wire.getSource().getName()), new XAttr(TARGET, wire
.getTarget().getName()));
+
+ // Write extensions
for (Object extension : wire.getExtensions()) {
extensionProcessor.write(extension, writer);
}
Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java?rev=572188&r1=572187&r2=572188&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java Sun Sep 2 16:20:03 2007
@@ -41,9 +41,10 @@
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.w3c.dom.Document;
/**
- * A contrainingType content handler.
+ * A constrainingType processor.
*
* @version $Rev$ $Date$
*/
@@ -107,6 +108,11 @@
// Read a <property>
abstractProperty = assemblyFactory.createAbstractProperty();
readAbstractProperty(abstractProperty, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(abstractProperty.getXSDElement(), abstractProperty.getXSDType(), reader);
+ abstractProperty.setValue(value);
+
constrainingType.getProperties().add(abstractProperty);
readIntents(abstractProperty, reader);
@@ -168,12 +174,17 @@
public void write(ConstrainingType constrainingType, XMLStreamWriter writer) throws ContributionWriteException {
try {
+ // Write <constrainingType> element
writeStartDocument(writer, CONSTRAINING_TYPE,
new XAttr(TARGET_NAMESPACE, constrainingType.getName().getNamespaceURI()),
- new XAttr(NAME, constrainingType.getName().getLocalPart()));
+ new XAttr(NAME, constrainingType.getName().getLocalPart()),
+ writeIntents(constrainingType));
+ // Write <service> elements
for (AbstractService service : constrainingType.getServices()) {
- writeStart(writer, SERVICE, new XAttr(NAME, service.getName()));
+ writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
+ writeIntents(service));
+
extensionProcessor.write(service.getInterfaceContract(), writer);
for (Object extension: service.getExtensions()) {
@@ -182,10 +193,12 @@
writeEnd(writer);
}
-
+
+ // Write <reference> elements
for (AbstractReference reference : constrainingType.getReferences()) {
- writeStart(writer, REFERENCE,
- new XAttr(NAME, reference.getName()));
+ writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
+ writeIntents(reference));
+
extensionProcessor.write(reference.getInterfaceContract(), writer);
for (Object extension: reference.getExtensions()) {
@@ -195,16 +208,29 @@
writeEnd(writer);
}
- for (AbstractProperty property : constrainingType.getProperties()) {
- writeStart(writer, PROPERTY, new XAttr(NAME, property.getName()));
+ // Write <property> elements
+ for (AbstractProperty abstractProperty : constrainingType.getProperties()) {
+ writeStart(writer,
+ PROPERTY,
+ new XAttr(NAME, abstractProperty.getName()),
+ new XAttr(MUST_SUPPLY, abstractProperty.isMustSupply()),
+ new XAttr(MANY, abstractProperty.isMany()),
+ new XAttr(TYPE, abstractProperty.getXSDType()),
+ new XAttr(ELEMENT, abstractProperty.getXSDElement()),
+ writeIntents(abstractProperty));
+
+ // Write property value
+ writePropertyValue(abstractProperty.getValue(), abstractProperty.getXSDElement(), abstractProperty.getXSDType(), writer);
- for (Object extension: property.getExtensions()) {
+ // Write extensions
+ for (Object extension : abstractProperty.getExtensions()) {
extensionProcessor.write(extension, writer);
}
-
+
writeEnd(writer);
}
+ // Write extension elements
for (Object extension: constrainingType.getExtensions()) {
extensionProcessor.write(extension, writer);
}
Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/XAttr.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/XAttr.java?rev=572188&r1=572187&r2=572188&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/XAttr.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/XAttr.java Sun Sep 2 16:20:03 2007
@@ -19,6 +19,8 @@
package org.apache.tuscany.sca.assembly.xml;
+import java.util.List;
+
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
@@ -43,21 +45,29 @@
}
public XAttr(String name, String value) {
- this.name = name;
- this.value = value;
+ this(null, name, value);
}
- public XAttr(String uri, String name, boolean value) {
+ public XAttr(String uri, String name, List values) {
this.uri = uri;
this.name = name;
- this.value = value;
+ this.value = values;
+ }
+
+ public XAttr(String name, List values) {
+ this(null, name, values);
}
- public XAttr(String name, boolean value) {
+ public XAttr(String uri, String name, Boolean value) {
+ this.uri = uri;
this.name = name;
this.value = value;
}
+ public XAttr(String name, Boolean value) {
+ this(null, name, value);
+ }
+
public XAttr(String uri, String name, QName value) {
this.uri = uri;
this.name = name;
@@ -65,8 +75,7 @@
}
public XAttr(String name, QName value) {
- this.name = name;
- this.value = value;
+ this(null, name, value);
}
/**
@@ -75,7 +84,7 @@
* @param value
* @return
*/
- protected String writeQNameValue(XMLStreamWriter writer, QName qname) throws XMLStreamException {
+ private String writeQNameValue(XMLStreamWriter writer, QName qname) throws XMLStreamException {
if (qname != null) {
String prefix = qname.getPrefix();
String uri = qname.getNamespaceURI();
@@ -109,7 +118,7 @@
* @param value
* @return
*/
- protected void writeQNamePrefix(XMLStreamWriter writer, QName qname) throws XMLStreamException {
+ private void writeQNamePrefix(XMLStreamWriter writer, QName qname) throws XMLStreamException {
if (qname != null) {
String prefix = qname.getPrefix();
String uri = qname.getNamespaceURI();
@@ -132,25 +141,60 @@
}
void write(XMLStreamWriter writer) throws XMLStreamException {
- if (value != null) {
- String str;
- if (value instanceof QName) {
- str = writeQNameValue(writer, (QName)value);
- } else {
- str = String.valueOf(value);
+ String str;
+ if (value instanceof QName) {
+
+ // Write a QName
+ str = writeQNameValue(writer, (QName)value);
+
+ } else if (value instanceof List) {
+
+ // Write a list
+ List values = (List)value;
+ if (values.isEmpty()) {
+ return;
}
- if (uri != null && !uri.equals(Constants.SCA10_NS)) {
- writer.writeAttribute(uri, name, str);
- } else {
- writer.writeAttribute(name,str);
+ StringBuffer buffer = new StringBuffer();
+ for (Object v: values) {
+ if (buffer.length() != 0) {
+ buffer.append(' ');
+ }
+ if (v instanceof QName) {
+ buffer.append(writeQNameValue(writer, (QName)v));
+ } else {
+ buffer.append(String.valueOf(v));
+ }
}
+ str = buffer.toString();
+
+ } else {
+
+ // Write a string
+ if (value == null) {
+ return;
+ }
+ str = String.valueOf(value);
+ }
+ if (uri != null && !uri.equals(Constants.SCA10_NS)) {
+ writer.writeAttribute(uri, name, str);
+ } else {
+ writer.writeAttribute(name,str);
}
}
void writePrefix(XMLStreamWriter writer) throws XMLStreamException {
- if (value != null) {
- if (value instanceof QName) {
- writeQNamePrefix(writer, (QName)value);
+ if (value instanceof QName) {
+
+ // Write prefix for a single QName value
+ writeQNamePrefix(writer, (QName)value);
+
+ } else if (value instanceof List) {
+
+ // Write prefixes for a list of QNames
+ for (Object v: (List)value) {
+ if (v instanceof QName) {
+ writeQNamePrefix(writer, (QName)v);
+ }
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org