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/04/01 10:49:20 UTC
svn commit: r524558 - in
/incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl:
ComponentTypeLoader.java CompositeLoader.java ConstrainingTypeLoader.java
LoaderRegistryImpl.java
Author: jsdelfino
Date: Sun Apr 1 01:49:19 2007
New Revision: 524558
URL: http://svn.apache.org/viewvc?view=rev&rev=524558
Log:
Support end elements and extension elements in componentType and constrainingType loaders.
Modified:
incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/ComponentTypeLoader.java
incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/CompositeLoader.java
incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/ConstrainingTypeLoader.java
incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/LoaderRegistryImpl.java
Modified: incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/ComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/ComponentTypeLoader.java?view=diff&rev=524558&r1=524557&r2=524558
==============================================================================
--- incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/ComponentTypeLoader.java (original)
+++ incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/ComponentTypeLoader.java Sun Apr 1 01:49:19 2007
@@ -19,6 +19,7 @@
package org.apache.tuscany.scdl.stax.impl;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import javax.xml.namespace.QName;
@@ -26,6 +27,7 @@
import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.assembly.model.AssemblyFactory;
+import org.apache.tuscany.assembly.model.Binding;
import org.apache.tuscany.assembly.model.Callback;
import org.apache.tuscany.assembly.model.ComponentService;
import org.apache.tuscany.assembly.model.ComponentType;
@@ -34,6 +36,8 @@
import org.apache.tuscany.assembly.model.Reference;
import org.apache.tuscany.assembly.model.Service;
import org.apache.tuscany.policy.model.PolicyFactory;
+import org.apache.tuscany.sca.idl.Interface;
+import org.apache.tuscany.sca.idl.Operation;
import org.apache.tuscany.scdl.stax.Constants;
import org.apache.tuscany.scdl.stax.Loader;
import org.apache.tuscany.scdl.stax.LoaderRegistry;
@@ -45,9 +49,11 @@
*/
public class ComponentTypeLoader extends BaseLoader implements Loader<ComponentType> {
private AssemblyFactory factory;
+ private LoaderRegistry registry;
/**
* Constructs a new componentType loader.
+ *
* @param factory
* @param policyFactory
* @param registry
@@ -55,6 +61,7 @@
public ComponentTypeLoader(AssemblyFactory factory, PolicyFactory policyFactory, LoaderRegistry registry) {
super(factory, policyFactory);
this.factory = factory;
+ this.registry = registry;
}
public ComponentType load(XMLStreamReader reader) throws XMLStreamException {
@@ -65,7 +72,7 @@
Property property = null;
Callback callback = null;
QName name = null;
-
+
// Read the componentType document
while (reader.hasNext()) {
int event = reader.getEventType();
@@ -74,11 +81,15 @@
name = reader.getName();
if (Constants.COMPONENT_TYPE_QNAME.equals(name)) {
+
+ // Read a <componentType>
componentType = factory.createComponentType();
componentType.setConstrainingType(getConstrainingType(reader));
readPolicies(componentType, reader);
} else if (Constants.SERVICE_QNAME.equals(name)) {
+
+ // Read a <service>
service = factory.createService();
contract = service;
service.setName(getString(reader, Constants.NAME));
@@ -86,6 +97,8 @@
readPolicies(service, reader);
} else if (Constants.REFERENCE_QNAME.equals(name)) {
+
+ // Read a <reference>
reference = factory.createReference();
contract = reference;
reference.setName(getString(reader, Constants.NAME));
@@ -100,22 +113,72 @@
readPolicies(reference, reader);
} else if (Constants.PROPERTY_QNAME.equals(name)) {
+
+ // Read a <property>
property = factory.createProperty();
readProperty(property, reader);
componentType.getProperties().add(property);
readPolicies(property, reader);
} else if (Constants.CALLBACK_QNAME.equals(name)) {
+
+ // Read a <callback>
callback = factory.createCallback();
contract.setCallback(callback);
readPolicies(callback, reader);
+ } else if (OPERATION.equals(name)) {
+
+ // Read an <operation>
+ Operation operation = factory.createOperation();
+ operation.setName(getString(reader, NAME));
+ operation.setUnresolved(true);
+ if (callback != null) {
+ readPolicies(callback, operation, reader);
+ } else {
+ readPolicies(contract, operation, reader);
+ }
+ } else {
+
+ // Read an extension element
+ Object extension = registry.load(reader);
+ if (extension != null) {
+ if (extension instanceof Interface) {
+
+ // <service><interface> and <reference><interface>
+ contract.setInterface((Interface)extension);
+
+ } else if (extension instanceof Binding) {
+
+ // <service><binding> and <reference><binding>
+ contract.getBindings().add((Binding)extension);
+ }
+ }
+ }
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+
+ // Clear current state when reading reaching end element
+ if (SERVICE_QNAME.equals(name)) {
+ service = null;
+ contract = null;
+ } else if (REFERENCE_QNAME.equals(name)) {
+ reference = null;
+ contract = null;
+ } else if (PROPERTY_QNAME.equals(name)) {
+ property = null;
+ } else if (CALLBACK_QNAME.equals(name)) {
+ callback = null;
}
+ break;
}
+
+ // Read the next element
if (reader.hasNext()) {
reader.next();
}
-
}
return componentType;
}
Modified: incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/CompositeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/CompositeLoader.java?view=diff&rev=524558&r1=524557&r2=524558
==============================================================================
--- incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/CompositeLoader.java (original)
+++ incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/CompositeLoader.java Sun Apr 1 01:49:19 2007
@@ -215,17 +215,17 @@
contract.setCallback(callback);
readPolicies(callback, reader);
- } else if (OPERATION.equals(name)) {
-
- // Read an <operation>
- Operation operation = factory.createOperation();
- operation.setName(getString(reader, NAME));
- operation.setUnresolved(true);
- if (callback != null) {
- readPolicies(callback, operation, reader);
- } else {
- readPolicies(contract, operation, reader);
- }
+ } else if (OPERATION.equals(name)) {
+
+ // Read an <operation>
+ Operation operation = factory.createOperation();
+ operation.setName(getString(reader, NAME));
+ operation.setUnresolved(true);
+ if (callback != null) {
+ readPolicies(callback, operation, reader);
+ } else {
+ readPolicies(contract, operation, reader);
+ }
} else {
// Read an extension element
@@ -265,7 +265,7 @@
case END_ELEMENT:
name = reader.getName();
- // Clear current state when reading reaching end element
+ // Clear current state when reading reaching end element
if (SERVICE_QNAME.equals(name)) {
componentService = null;
compositeService = null;
Modified: incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/ConstrainingTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/ConstrainingTypeLoader.java?view=diff&rev=524558&r1=524557&r2=524558
==============================================================================
--- incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/ConstrainingTypeLoader.java (original)
+++ incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/ConstrainingTypeLoader.java Sun Apr 1 01:49:19 2007
@@ -19,6 +19,7 @@
package org.apache.tuscany.scdl.stax.impl;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import javax.xml.namespace.QName;
@@ -32,6 +33,8 @@
import org.apache.tuscany.assembly.model.AssemblyFactory;
import org.apache.tuscany.assembly.model.ConstrainingType;
import org.apache.tuscany.policy.model.PolicyFactory;
+import org.apache.tuscany.sca.idl.Interface;
+import org.apache.tuscany.sca.idl.Operation;
import org.apache.tuscany.scdl.stax.Constants;
import org.apache.tuscany.scdl.stax.Loader;
import org.apache.tuscany.scdl.stax.LoaderRegistry;
@@ -51,9 +54,7 @@
* @param policyFactory
* @param registry
*/
- public ConstrainingTypeLoader(AssemblyFactory factory,
- PolicyFactory policyFactory,
- LoaderRegistry registry) {
+ public ConstrainingTypeLoader(AssemblyFactory factory, PolicyFactory policyFactory, LoaderRegistry registry) {
super(factory, policyFactory);
this.factory = factory;
this.registry = registry;
@@ -65,17 +66,25 @@
AbstractReference abstractReference = null;
AbstractProperty abstractProperty = null;
AbstractContract abstractContract = null;
+ QName name = null;
+
+ // Read the constrainingType document
while (reader.hasNext()) {
int event = reader.getEventType();
switch (event) {
+
case START_ELEMENT:
- QName name = reader.getName();
+ name = reader.getName();
+
+ // Read a <constrainingType>
if (Constants.CONSTRAINING_TYPE_QNAME.equals(name)) {
constrainingType = factory.createConstrainingType();
constrainingType.setName(getQName(reader, Constants.NAME));
readIntents(constrainingType, reader);
} else if (Constants.SERVICE_QNAME.equals(name)) {
+
+ // Read a <service>
abstractService = factory.createAbstractService();
abstractContract = abstractService;
abstractService.setName(getString(reader, Constants.NAME));
@@ -83,6 +92,8 @@
readIntents(abstractService, reader);
} else if (Constants.REFERENCE_QNAME.equals(name)) {
+
+ // Read a <reference>
abstractReference = factory.createAbstractReference();
abstractContract = abstractReference;
abstractReference.setName(getString(reader, Constants.NAME));
@@ -90,17 +101,53 @@
readIntents(abstractReference, reader);
} else if (Constants.PROPERTY_QNAME.equals(name)) {
+
+ // Read a <property>
abstractProperty = factory.createAbstractProperty();
readAbstractProperty(abstractProperty, reader);
constrainingType.getProperties().add(abstractProperty);
readIntents(abstractProperty, reader);
+
+ } else if (OPERATION.equals(name)) {
+ // Read an <operation>
+ Operation operation = factory.createOperation();
+ operation.setName(getString(reader, NAME));
+ operation.setUnresolved(true);
+ readIntents(abstractContract, operation, reader);
+
+ } else {
+
+ // Read an extension element
+ Object extension = registry.load(reader);
+ if (extension != null) {
+ if (extension instanceof Interface) {
+
+ // <service><interface> and <reference><interface>
+ abstractContract.setInterface((Interface)extension);
+ }
+ }
}
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+
+ // Clear current state when reading reaching end element
+ if (SERVICE_QNAME.equals(name)) {
+ abstractService = null;
+ abstractContract = null;
+ } else if (REFERENCE_QNAME.equals(name)) {
+ abstractReference = null;
+ abstractContract = null;
+ } else if (PROPERTY_QNAME.equals(name)) {
+ abstractProperty = null;
+ }
+ break;
}
if (reader.hasNext()) {
reader.next();
}
-
}
return constrainingType;
Modified: incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/LoaderRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/LoaderRegistryImpl.java?view=diff&rev=524558&r1=524557&r2=524558
==============================================================================
--- incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/LoaderRegistryImpl.java (original)
+++ incubator/tuscany/java/sca/scdl4j/stax/src/main/java/org/apache/tuscany/scdl/stax/impl/LoaderRegistryImpl.java Sun Apr 1 01:49:19 2007
@@ -27,7 +27,6 @@
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org