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 11:46:47 UTC

svn commit: r572267 [2/6] - in /incubator/tuscany/java/sca: itest/ modules/ modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ modules/binding-jms/src/main/jav...

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=572267&r1=572266&r2=572267&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 Mon Sep  3 02:46:41 2007
@@ -68,7 +68,7 @@
  * 
  * @version $Rev$ $Date$
  */
-public class CompositeProcessor extends BaseArtifactProcessor implements StAXArtifactProcessor<Composite> {
+public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor<Composite> {
 
     /**
      * Construct a new composite processor
@@ -98,7 +98,7 @@
      *            extensionProcessor); }
      */
 
-    public Composite read(XMLStreamReader reader) throws ContributionReadException {
+    public Composite read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
         Composite composite = null;
         Composite include = null;
         Component component = null;
@@ -113,356 +113,394 @@
         Callback callback = null;
         QName name = null;
 
-        try {
+        // Read the composite document
+        while (reader.hasNext()) {
+            int event = reader.getEventType();
+            switch (event) {
+                case START_ELEMENT:
+                    name = reader.getName();
+
+                    if (COMPOSITE_QNAME.equals(name)) {
+
+                        // Read a <composite>
+                        composite = assemblyFactory.createComposite();
+                        composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
+                        if(isSet(reader, AUTOWIRE)) {
+                            composite.setAutowire(getBoolean(reader, AUTOWIRE));
+                        }
+                        composite.setLocal(getBoolean(reader, LOCAL));
+                        composite.setConstrainingType(readConstrainingType(reader));
+                        policyProcessor.readPolicies(composite, reader);
+
+                    } else if (INCLUDE_QNAME.equals(name)) {
+
+                        // Read an <include>
+                        include = assemblyFactory.createComposite();
+                        include.setName(getQName(reader, "name"));
+                        include.setUnresolved(true);
+                        composite.getIncludes().add(include);
+
+                    } else if (SERVICE_QNAME.equals(name)) {
+                        if (component != null) {
+
+                            // Read a <component><service>
+                            componentService = assemblyFactory.createComponentService();
+                            contract = componentService;
+                            componentService.setName(getString(reader, NAME));
+                            component.getServices().add(componentService);
+                            policyProcessor.readPolicies(contract, reader);
+                        } else {
 
-            // Read the composite document
-            while (reader.hasNext()) {
-                int event = reader.getEventType();
-                switch (event) {
-                    case START_ELEMENT:
-                        name = reader.getName();
-
-                        if (COMPOSITE_QNAME.equals(name)) {
-
-                            // Read a <composite>
-                            composite = assemblyFactory.createComposite();
-                            composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
-                            if(isSet(reader, AUTOWIRE)) {
-                                composite.setAutowire(getBoolean(reader, AUTOWIRE));
-                            }
-                            composite.setLocal(getBoolean(reader, LOCAL));
-                            composite.setConstrainingType(readConstrainingType(reader));
-                            readPolicies(composite, reader);
-
-                        } else if (INCLUDE_QNAME.equals(name)) {
-
-                            // Read an <include>
-                            include = assemblyFactory.createComposite();
-                            include.setName(getQName(reader, "name"));
-                            include.setUnresolved(true);
-                            composite.getIncludes().add(include);
-
-                        } else if (SERVICE_QNAME.equals(name)) {
-                            if (component != null) {
-
-                                // Read a <component><service>
-                                componentService = assemblyFactory.createComponentService();
-                                contract = componentService;
-                                componentService.setName(getString(reader, NAME));
-                                component.getServices().add(componentService);
-                                readPolicies(contract, reader);
+                            // Read a <composite><service>
+                            compositeService = assemblyFactory.createCompositeService();
+                            contract = compositeService;
+                            compositeService.setName(getString(reader, NAME));
+
+                            String promoted = getString(reader, PROMOTE);
+                            String promotedComponentName;
+                            String promotedServiceName;
+                            int s = promoted.indexOf('/');
+                            if (s == -1) {
+                                promotedComponentName = promoted;
+                                promotedServiceName = null;
                             } else {
+                                promotedComponentName = promoted.substring(0, s);
+                                promotedServiceName = promoted.substring(s + 1);
+                            }
 
-                                // Read a <composite><service>
-                                compositeService = assemblyFactory.createCompositeService();
-                                contract = compositeService;
-                                compositeService.setName(getString(reader, NAME));
-
-                                String promoted = getString(reader, PROMOTE);
-                                String promotedComponentName;
-                                String promotedServiceName;
-                                int s = promoted.indexOf('/');
-                                if (s == -1) {
-                                    promotedComponentName = promoted;
-                                    promotedServiceName = null;
-                                } else {
-                                    promotedComponentName = promoted.substring(0, s);
-                                    promotedServiceName = promoted.substring(s + 1);
-                                }
+                            Component promotedComponent = assemblyFactory.createComponent();
+                            promotedComponent.setUnresolved(true);
+                            promotedComponent.setName(promotedComponentName);
+                            compositeService.setPromotedComponent(promotedComponent);
+
+                            ComponentService promotedService = assemblyFactory.createComponentService();
+                            promotedService.setUnresolved(true);
+                            promotedService.setName(promotedServiceName);
+                            compositeService.setPromotedService(promotedService);
 
-                                Component promotedComponent = assemblyFactory.createComponent();
-                                promotedComponent.setUnresolved(true);
-                                promotedComponent.setName(promotedComponentName);
-                                compositeService.setPromotedComponent(promotedComponent);
-
-                                ComponentService promotedService = assemblyFactory.createComponentService();
-                                promotedService.setUnresolved(true);
-                                promotedService.setName(promotedServiceName);
-                                compositeService.setPromotedService(promotedService);
+                            composite.getServices().add(compositeService);
+                            policyProcessor.readPolicies(contract, reader);
+                        }
 
-                                composite.getServices().add(compositeService);
-                                readPolicies(contract, reader);
+                    } else if (REFERENCE_QNAME.equals(name)) {
+                        if (component != null) {
+                            // Read a <component><reference>
+                            componentReference = assemblyFactory.createComponentReference();
+                            contract = componentReference;
+                            componentReference.setName(getString(reader, NAME));
+                            readMultiplicity(componentReference, reader);
+                            if (isSet(reader, AUTOWIRE)) {
+                                componentReference.setAutowire(getBoolean(reader, AUTOWIRE));
                             }
-
-                        } else if (REFERENCE_QNAME.equals(name)) {
-                            if (component != null) {
-                                // Read a <component><reference>
-                                componentReference = assemblyFactory.createComponentReference();
-                                contract = componentReference;
-                                componentReference.setName(getString(reader, NAME));
-                                readMultiplicity(componentReference, reader);
-                                if (isSet(reader, AUTOWIRE)) {
-                                    componentReference.setAutowire(getBoolean(reader, AUTOWIRE));
-                                }
-                                readTargets(componentReference, reader);
-                                componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
-                                component.getReferences().add(componentReference);
-                                readPolicies(contract, reader);
-                            } else {
-                                // Read a <composite><reference>
-                                compositeReference = assemblyFactory.createCompositeReference();
-                                contract = compositeReference;
-                                compositeReference.setName(getString(reader, NAME));
-                                readMultiplicity(compositeReference, reader);
-                                readTargets(compositeReference, reader);
-                                String promote = reader.getAttributeValue(null, Constants.PROMOTE);
-                                if (promote != null) {
-                                    for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) {
-                                        ComponentReference promotedReference =
-                                            assemblyFactory.createComponentReference();
-                                        promotedReference.setUnresolved(true);
-                                        promotedReference.setName(tokens.nextToken());
-                                        compositeReference.getPromotedReferences().add(promotedReference);
-                                    }
+                            readTargets(componentReference, reader);
+                            componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
+                            component.getReferences().add(componentReference);
+                            policyProcessor.readPolicies(contract, reader);
+                        } else {
+                            // Read a <composite><reference>
+                            compositeReference = assemblyFactory.createCompositeReference();
+                            contract = compositeReference;
+                            compositeReference.setName(getString(reader, NAME));
+                            readMultiplicity(compositeReference, reader);
+                            readTargets(compositeReference, reader);
+                            String promote = reader.getAttributeValue(null, Constants.PROMOTE);
+                            if (promote != null) {
+                                for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) {
+                                    ComponentReference promotedReference =
+                                        assemblyFactory.createComponentReference();
+                                    promotedReference.setUnresolved(true);
+                                    promotedReference.setName(tokens.nextToken());
+                                    compositeReference.getPromotedReferences().add(promotedReference);
                                 }
-                                compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
-                                composite.getReferences().add(compositeReference);
-                                readPolicies(contract, reader);
                             }
+                            compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
+                            composite.getReferences().add(compositeReference);
+                            policyProcessor.readPolicies(contract, reader);
+                        }
 
-                        } else if (PROPERTY_QNAME.equals(name)) {
-                            if (component != null) {
+                    } 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);
-                                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 <component><property>
+                            componentProperty = assemblyFactory.createComponentProperty();
+                            property = componentProperty;
+                            componentProperty.setSource(getString(reader, SOURCE));
+                            componentProperty.setFile(getString(reader, FILE));
+                            policyProcessor.readPolicies(property, 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);
-                                readAbstractProperty(property, reader);
-                                
-                                // Read the property value
-                                Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
-                                property.setValue(value);
-                                
-                                composite.getProperties().add(property);
-                            }
+                            // Read a <composite><property>
+                            property = assemblyFactory.createProperty();
+                            policyProcessor.readPolicies(property, reader);
+                            readAbstractProperty(property, reader);
+                            
+                            // Read the property value
+                            Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
+                            property.setValue(value);
+                            
+                            composite.getProperties().add(property);
+                        }
 
-                        } else if (COMPONENT_QNAME.equals(name)) {
+                    } else if (COMPONENT_QNAME.equals(name)) {
 
-                            // Read a <component>
-                            component = assemblyFactory.createComponent();
-                            component.setName(getString(reader, NAME));
-                            if (isSet(reader, AUTOWIRE)) {
-                                component.setAutowire(getBoolean(reader, AUTOWIRE));
-                            }
-                            component.setConstrainingType(readConstrainingType(reader));
-                            composite.getComponents().add(component);
-                            readPolicies(component, reader);
-
-                        } else if (WIRE_QNAME.equals(name)) {
-
-                            // Read a <wire>
-                            wire = assemblyFactory.createWire();
-                            ComponentReference source = assemblyFactory.createComponentReference();
-                            source.setUnresolved(true);
-                            source.setName(getString(reader, SOURCE));
-                            wire.setSource(source);
-
-                            ComponentService target = assemblyFactory.createComponentService();
-                            target.setUnresolved(true);
-                            target.setName(getString(reader, TARGET));
-                            wire.setTarget(target);
-
-                            composite.getWires().add(wire);
-                            readPolicies(wire, reader);
-
-                        } else if (CALLBACK_QNAME.equals(name)) {
-
-                            // Read a <callback>
-                            callback = assemblyFactory.createCallback();
-                            contract.setCallback(callback);
-                            readPolicies(callback, reader);
-
-                        } else if (OPERATION_QNAME.equals(name)) {
-
-                            // Read an <operation>
-                            Operation operation = assemblyFactory.createOperation();
-                            operation.setName(getString(reader, NAME));
-                            operation.setUnresolved(true);
-                            if (callback != null) {
-                                readPolicies(callback, operation, reader);
-                            } else {
-                                readPolicies(contract, operation, reader);
-                            }
-                        } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {
-
-                            // Read an implementation.composite
-                            Composite implementation = assemblyFactory.createComposite();
-                            implementation.setName(getQName(reader, NAME));
-                            implementation.setUnresolved(true);
-                            component.setImplementation(implementation);
-                            readPolicies(implementation, reader);
+                        // Read a <component>
+                        component = assemblyFactory.createComponent();
+                        component.setName(getString(reader, NAME));
+                        if (isSet(reader, AUTOWIRE)) {
+                            component.setAutowire(getBoolean(reader, AUTOWIRE));
+                        }
+                        component.setConstrainingType(readConstrainingType(reader));
+                        composite.getComponents().add(component);
+                        policyProcessor.readPolicies(component, reader);
+
+                    } else if (WIRE_QNAME.equals(name)) {
+
+                        // Read a <wire>
+                        wire = assemblyFactory.createWire();
+                        ComponentReference source = assemblyFactory.createComponentReference();
+                        source.setUnresolved(true);
+                        source.setName(getString(reader, SOURCE));
+                        wire.setSource(source);
+
+                        ComponentService target = assemblyFactory.createComponentService();
+                        target.setUnresolved(true);
+                        target.setName(getString(reader, TARGET));
+                        wire.setTarget(target);
+
+                        composite.getWires().add(wire);
+                        policyProcessor.readPolicies(wire, reader);
+
+                    } else if (CALLBACK_QNAME.equals(name)) {
+
+                        // Read a <callback>
+                        callback = assemblyFactory.createCallback();
+                        contract.setCallback(callback);
+                        policyProcessor.readPolicies(callback, reader);
+
+                    } else if (OPERATION_QNAME.equals(name)) {
+
+                        // Read an <operation>
+                        Operation operation = assemblyFactory.createOperation();
+                        operation.setName(getString(reader, NAME));
+                        operation.setUnresolved(true);
+                        if (callback != null) {
+                            policyProcessor.readPolicies(callback, operation, reader);
                         } else {
+                            policyProcessor.readPolicies(contract, operation, reader);
+                        }
+                    } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {
 
-                            // Read an extension element
-                            Object extension = extensionProcessor.read(reader);
-                            if (extension != null) {
-                                if (extension instanceof InterfaceContract) {
-
-                                    // <service><interface> and
-                                    // <reference><interface>
-                                    if (contract != null) {
-                                        contract.setInterfaceContract((InterfaceContract)extension);
-                                    } else {
-                                        if (name.getNamespaceURI().equals(SCA10_NS)) {
-                                            throw new ContributionReadException(
-                                                                                "Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
-                                        } else {
-                                            composite.getExtensions().add(extension);
-                                        }
-                                    }
+                        // Read an implementation.composite
+                        Composite implementation = assemblyFactory.createComposite();
+                        implementation.setName(getQName(reader, NAME));
+                        implementation.setUnresolved(true);
+                        component.setImplementation(implementation);
+                        policyProcessor.readPolicies(implementation, reader);
+                    } else {
 
-                                } else if (extension instanceof Binding) {
-                                    // <service><binding> and
-                                    // <reference><binding>
-                                    if (callback != null) {
-                                        callback.getBindings().add((Binding)extension);
+                        // Read an extension element
+                        Object extension = extensionProcessor.read(reader);
+                        if (extension != null) {
+                            if (extension instanceof InterfaceContract) {
+
+                                // <service><interface> and
+                                // <reference><interface>
+                                if (contract != null) {
+                                    contract.setInterfaceContract((InterfaceContract)extension);
+                                } else {
+                                    if (name.getNamespaceURI().equals(SCA10_NS)) {
+                                        throw new ContributionReadException(
+                                                                            "Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
                                     } else {
-                                        if (contract != null) {
-                                            contract.getBindings().add((Binding)extension);
-                                        } else {
-                                            if (name.getNamespaceURI().equals(SCA10_NS)) {
-                                                throw new ContributionReadException(
-                                                                                    "Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
-                                            } else {
-                                                composite.getExtensions().add(extension);
-                                            }
-                                        }
+                                        composite.getExtensions().add(extension);
                                     }
+                                }
 
-                                } else if (extension instanceof Implementation) {
-
-                                    // <component><implementation>
-                                    if (component != null) {
-                                        component.setImplementation((Implementation)extension);
+                            } else if (extension instanceof Binding) {
+                                // <service><binding> and
+                                // <reference><binding>
+                                if (callback != null) {
+                                    callback.getBindings().add((Binding)extension);
+                                } else {
+                                    if (contract != null) {
+                                        contract.getBindings().add((Binding)extension);
                                     } else {
                                         if (name.getNamespaceURI().equals(SCA10_NS)) {
                                             throw new ContributionReadException(
-                                                                                "Unexpected <implementation> element found. It should appear inside a <component> element");
+                                                                                "Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
                                         } else {
                                             composite.getExtensions().add(extension);
                                         }
                                     }
-                                } else {
+                                }
+
+                            } else if (extension instanceof Implementation) {
 
-                                    // Add the extension element to the current
-                                    // element
-                                    if (callback != null) {
-                                        callback.getExtensions().add(extension);
-                                    } else if (contract != null) {
-                                        contract.getExtensions().add(extension);
-                                    } else if (property != null) {
-                                        property.getExtensions().add(extension);
-                                    } else if (component != null) {
-                                        component.getExtensions().add(extension);
+                                // <component><implementation>
+                                if (component != null) {
+                                    component.setImplementation((Implementation)extension);
+                                } else {
+                                    if (name.getNamespaceURI().equals(SCA10_NS)) {
+                                        throw new ContributionReadException(
+                                                                            "Unexpected <implementation> element found. It should appear inside a <component> element");
                                     } else {
                                         composite.getExtensions().add(extension);
                                     }
                                 }
+                            } else {
+
+                                // Add the extension element to the current
+                                // element
+                                if (callback != null) {
+                                    callback.getExtensions().add(extension);
+                                } else if (contract != null) {
+                                    contract.getExtensions().add(extension);
+                                } else if (property != null) {
+                                    property.getExtensions().add(extension);
+                                } else if (component != null) {
+                                    component.getExtensions().add(extension);
+                                } else {
+                                    composite.getExtensions().add(extension);
+                                }
                             }
                         }
-                        break;
+                    }
+                    break;
 
-                    case XMLStreamConstants.CHARACTERS:
-                        break;
+                case XMLStreamConstants.CHARACTERS:
+                    break;
 
-                    case END_ELEMENT:
-                        name = reader.getName();
+                case END_ELEMENT:
+                    name = reader.getName();
 
-                        // Clear current state when reading reaching end element
-                        if (SERVICE_QNAME.equals(name)) {
-                            componentService = null;
-                            compositeService = null;
-                            contract = null;
-                        } else if (INCLUDE_QNAME.equals(name)) {
-                            include = null;
-                        } else if (REFERENCE_QNAME.equals(name)) {
-                            componentReference = null;
-                            compositeReference = null;
-                            contract = null;
-                        } else if (PROPERTY_QNAME.equals(name)) {
-                            componentProperty = null;
-                            property = null;
-                        } else if (COMPONENT_QNAME.equals(name)) {
-                            component = null;
-                        } else if (WIRE_QNAME.equals(name)) {
-                            wire = null;
-                        } else if (CALLBACK_QNAME.equals(name)) {
-                            callback = null;
-                        }
-                        break;
-                }
-
-                // Read the next element
-                if (reader.hasNext()) {
-                    reader.next();
-                }
+                    // Clear current state when reading reaching end element
+                    if (SERVICE_QNAME.equals(name)) {
+                        componentService = null;
+                        compositeService = null;
+                        contract = null;
+                    } else if (INCLUDE_QNAME.equals(name)) {
+                        include = null;
+                    } else if (REFERENCE_QNAME.equals(name)) {
+                        componentReference = null;
+                        compositeReference = null;
+                        contract = null;
+                    } else if (PROPERTY_QNAME.equals(name)) {
+                        componentProperty = null;
+                        property = null;
+                    } else if (COMPONENT_QNAME.equals(name)) {
+                        component = null;
+                    } else if (WIRE_QNAME.equals(name)) {
+                        wire = null;
+                    } else if (CALLBACK_QNAME.equals(name)) {
+                        callback = null;
+                    }
+                    break;
             }
-            return composite;
 
-        } catch (XMLStreamException e) {
-            throw new ContributionReadException(e);
+            // Read the next element
+            if (reader.hasNext()) {
+                reader.next();
+            }
         }
+        return composite;
     }
 
-    public void write(Composite composite, XMLStreamWriter writer) throws ContributionWriteException {
-
-        try {
-            // Write <composite> element
-            writeStartDocument(writer,
-                               COMPOSITE,
-                               writeConstrainingType(composite),
-                               new XAttr(TARGET_NAMESPACE, composite.getName().getNamespaceURI()),
-                               new XAttr(NAME, composite.getName().getLocalPart()),
-                               new XAttr(AUTOWIRE, composite.getAutowire()),
-                               writeIntents(composite),
-                               writePolicySets(composite));
+    public void write(Composite composite, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
 
-            // Write <service> elements
-            for (Service service : composite.getServices()) {
-                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();
-                    }
+        // Write <composite> element
+        writeStartDocument(writer,
+                           COMPOSITE,
+                           writeConstrainingType(composite),
+                           new XAttr(TARGET_NAMESPACE, composite.getName().getNamespaceURI()),
+                           new XAttr(NAME, composite.getName().getLocalPart()),
+                           new XAttr(AUTOWIRE, composite.getAutowire()),
+                           policyProcessor.writePolicies(composite));
+
+        // Write <service> elements
+        for (Service service : composite.getServices()) {
+            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 = null;
+                    promote = promotedComponent.getName();
+                }
+            } else {
+                promote = null;
+            }
+            writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), new XAttr(PROMOTE, promote),
+                       policyProcessor.writePolicies(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,
+                           policyProcessor.writePolicies(callback));
+            
+                // Write callback bindings
+                for (Binding binding : callback.getBindings()) {
+                    extensionProcessor.write(binding, writer);
                 }
-                writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), new XAttr(PROMOTE, promote),
-                           writeIntents(service), writePolicySets(service));
                 
+                // 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()) {
+            writeStart(writer, COMPONENT, new XAttr(NAME, component.getName()),
+                       new XAttr(AUTOWIRE, component.getAutowire()),
+                       policyProcessor.writePolicies(component));
+            
+            // Write <service> elements
+            for (ComponentService service : component.getServices()) {
+                writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
+                           policyProcessor.writePolicies(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));
+                    writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));
                 
-                    // Write callback bindings
+                    // Write bindings
                     for (Binding binding : callback.getBindings()) {
                         extensionProcessor.write(binding, writer);
                     }
@@ -474,7 +512,7 @@
                 
                     writeEnd(writer);
                 }
-
+                
                 // Write extensions
                 for (Object extension : service.getExtensions()) {
                     extensionProcessor.write(extension, writer);
@@ -482,156 +520,26 @@
                 
                 writeEnd(writer);
             }
-
-            // Write <component> elements
-            for (Component component : composite.getComponents()) {
-                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()) {
-                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
+            for (ComponentReference reference : component.getReferences()) {
                 writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
-                           new XAttr(PROMOTE, promote),
-                           writeIntents(reference), writePolicySets(reference));
+                           new XAttr(AUTOWIRE, reference.getAutowire()),
+                           writeTargets(reference),
+                           policyProcessor.writePolicies(reference));
 
                 // Write reference interface
                 extensionProcessor.write(reference.getInterfaceContract(), writer);
-                
+
                 // Write bindings
                 for (Binding binding : reference.getBindings()) {
                     extensionProcessor.write(binding, writer);
                 }
                 
-                // Write <callback> element
+                // Write callback
                 if (reference.getCallback() != null) {
                     Callback callback = reference.getCallback();
-                    writeStart(writer, CALLBACK);
+                    writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));
                 
                     // Write callback bindings
                     for (Binding binding : callback.getBindings()) {
@@ -639,23 +547,23 @@
                     }
                     
                     // Write extensions
-                    for (Object extension : callback.getExtensions()) {
-                        extensionProcessor.write(extension, writer);
+                    for (Object extensions : callback.getExtensions()) {
+                        extensionProcessor.write(extensions, writer);
                     }
                 
                     writeEnd(writer);
                 }
                 
                 // Write extensions
-                for (Object extension : reference.getExtensions()) {
-                    extensionProcessor.write(extension, writer);
+                for (Object extensions : reference.getExtensions()) {
+                    extensionProcessor.write(extensions, writer);
                 }
                 
                 writeEnd(writer);
             }
-
+            
             // Write <property> elements
-            for (Property property : composite.getProperties()) {
+            for (ComponentProperty property : component.getProperties()) {
                 writeStart(writer,
                            PROPERTY,
                            new XAttr(NAME, property.getName()),
@@ -663,7 +571,9 @@
                            new XAttr(MANY, property.isMany()),
                            new XAttr(TYPE, property.getXSDType()),
                            new XAttr(ELEMENT, property.getXSDElement()),
-                           writeIntents(property), writePolicySets(property));
+                           new XAttr(SOURCE, property.getSource()),
+                           new XAttr(FILE, property.getFile()),
+                           policyProcessor.writePolicies(property));
 
                 // Write property value
                 writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);
@@ -675,28 +585,107 @@
 
                 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 <wire> elements
-            for (Wire wire : composite.getWires()) {
-                writeStart(writer, WIRE, new XAttr(SOURCE, wire.getSource().getName()), new XAttr(TARGET, wire
-                    .getTarget().getName()));
+        // Write <reference> elements
+        for (Reference reference : composite.getReferences()) {
+            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),
+                       policyProcessor.writePolicies(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 : wire.getExtensions()) {
+                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()) {
+            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()),
+                       policyProcessor.writePolicies(property));
 
-            for (Object extension : composite.getExtensions()) {
+            // Write property value
+            writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);
+
+            // Write extensions
+            for (Object extension : property.getExtensions()) {
                 extensionProcessor.write(extension, writer);
             }
 
-            writeEndDocument(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);
+            }
+            writeEnd(writer);
+        }
 
-        } catch (XMLStreamException e) {
-            throw new ContributionWriteException(e);
+        for (Object extension : composite.getExtensions()) {
+            extensionProcessor.write(extension, writer);
         }
+
+        writeEndDocument(writer);
     }
 
     public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException {

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java Mon Sep  3 02:46:41 2007
@@ -40,7 +40,7 @@
  * 
  * @version $Rev$ $Date$
  */
-public class ConstrainingTypeDocumentProcessor extends BaseArtifactProcessor implements URLArtifactProcessor<ConstrainingType> {
+public class ConstrainingTypeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor<ConstrainingType> {
     private XMLInputFactory inputFactory;
 
     /**
@@ -57,10 +57,33 @@
     public ConstrainingType read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
         InputStream urlStream = null;
         try {
+            
+            // Create a stream reader
             urlStream = url.openStream();
             XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream);
             reader.nextTag();
+            
+            // Read the constrainingType model 
             ConstrainingType constrainingType = (ConstrainingType)extensionProcessor.read(reader);
+
+            // For debugging purposes, write it back to XML
+//            if (constrainingType != null) {
+//                try {
+//                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+//                    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+//                    outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+//                    extensionProcessor.write(constrainingType, outputFactory.createXMLStreamWriter(bos));
+//                    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray()));
+//                    OutputFormat format = new OutputFormat();
+//                    format.setIndenting(true);
+//                    format.setIndent(2);
+//                    XMLSerializer serializer = new XMLSerializer(System.out, format);
+//                    serializer.serialize(document);
+//                } catch (Exception e) {
+//                    e.printStackTrace();
+//                }
+//            }
+            
             return constrainingType;
             
         } catch (XMLStreamException e) {

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=572267&r1=572266&r2=572267&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 Mon Sep  3 02:46:41 2007
@@ -48,7 +48,7 @@
  * 
  * @version $Rev$ $Date$
  */
-public class ConstrainingTypeProcessor extends BaseArtifactProcessor implements StAXArtifactProcessor<ConstrainingType> {
+public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor<ConstrainingType> {
 
     /**
      * Construct a new constrainingType processor.
@@ -60,7 +60,7 @@
         super(factory, policyFactory, extensionProcessor);
     }
 
-    public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException {
+    public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
         ConstrainingType constrainingType = null;
         AbstractService abstractService = null;
         AbstractReference abstractReference = null;
@@ -68,178 +68,167 @@
         AbstractContract abstractContract = null;
         QName name = null;
         
-        try {
-            
-            // Read the constrainingType document
-            while (reader.hasNext()) {
-                int event = reader.getEventType();
-                switch (event) {
-    
-                    case START_ELEMENT:
-                        name = reader.getName();
+        // Read the constrainingType document
+        while (reader.hasNext()) {
+            int event = reader.getEventType();
+            switch (event) {
+
+                case START_ELEMENT:
+                    name = reader.getName();
+                    
+                    // Read a <constrainingType>
+                    if (Constants.CONSTRAINING_TYPE_QNAME.equals(name)) {
+                        constrainingType = assemblyFactory.createConstrainingType();
+                        constrainingType.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
+                        policyProcessor.readPolicies(constrainingType, reader);
+
+                    } else if (Constants.SERVICE_QNAME.equals(name)) {
                         
-                        // Read a <constrainingType>
-                        if (Constants.CONSTRAINING_TYPE_QNAME.equals(name)) {
-                            constrainingType = assemblyFactory.createConstrainingType();
-                            constrainingType.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
-                            readIntents(constrainingType, reader);
-    
-                        } else if (Constants.SERVICE_QNAME.equals(name)) {
-                            
-                            // Read a <service>
-                            abstractService = assemblyFactory.createAbstractService();
-                            abstractContract = abstractService;
-                            abstractService.setName(getString(reader, Constants.NAME));
-                            constrainingType.getServices().add(abstractService);
-                            readIntents(abstractService, reader);
-    
-                        } else if (Constants.REFERENCE_QNAME.equals(name)) {
-                            
-                            // Read a <reference>
-                            abstractReference = assemblyFactory.createAbstractReference();
-                            abstractContract = abstractReference;
-                            abstractReference.setName(getString(reader, Constants.NAME));
-                            readMultiplicity(abstractReference, reader);
-                            constrainingType.getReferences().add(abstractReference);
-                            readIntents(abstractReference, reader);
-    
-                        } else if (Constants.PROPERTY_QNAME.equals(name)) {
-                            
-                            // 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);
-                            
-                        } else if (OPERATION.equals(name)) {
-    
-                            // Read an <operation>
-                            Operation operation = assemblyFactory.createOperation();
-                            operation.setName(getString(reader, NAME));
-                            operation.setUnresolved(true);
-                            readIntents(abstractContract, operation, reader);
+                        // Read a <service>
+                        abstractService = assemblyFactory.createAbstractService();
+                        abstractContract = abstractService;
+                        abstractService.setName(getString(reader, Constants.NAME));
+                        constrainingType.getServices().add(abstractService);
+                        policyProcessor.readPolicies(abstractService, reader);
+
+                    } else if (Constants.REFERENCE_QNAME.equals(name)) {
+                        
+                        // Read a <reference>
+                        abstractReference = assemblyFactory.createAbstractReference();
+                        abstractContract = abstractReference;
+                        abstractReference.setName(getString(reader, Constants.NAME));
+                        readMultiplicity(abstractReference, reader);
+                        constrainingType.getReferences().add(abstractReference);
+                        policyProcessor.readPolicies(abstractReference, reader);
+
+                    } else if (Constants.PROPERTY_QNAME.equals(name)) {
+                        
+                        // 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);
+                        policyProcessor.readPolicies(abstractProperty, reader);
+                        
+                    } else if (OPERATION.equals(name)) {
+
+                        // Read an <operation>
+                        Operation operation = assemblyFactory.createOperation();
+                        operation.setName(getString(reader, NAME));
+                        operation.setUnresolved(true);
+                        policyProcessor.readPolicies(abstractContract, operation, reader);
+                        
+                    } else {
+
+                        // Read an extension element
+                        Object extension = extensionProcessor.read(reader);
+                        if (extension instanceof InterfaceContract) {
                             
+                            // <service><interface> and <reference><interface>
+                            abstractContract.setInterfaceContract((InterfaceContract)extension);
                         } else {
-    
-                            // Read an extension element
-                            Object extension = extensionProcessor.read(reader);
-                            if (extension instanceof InterfaceContract) {
-                                
-                                // <service><interface> and <reference><interface>
-                                abstractContract.setInterfaceContract((InterfaceContract)extension);
-                            } else {
 
-                                // Add the extension element to the current element
-                                if (abstractContract != null) {
-                                    abstractContract.getExtensions().add(extension);
-                                } else {
-                                    constrainingType.getExtensions().add(extension);
-                                }
-                                
+                            // Add the extension element to the current element
+                            if (abstractContract != null) {
+                                abstractContract.getExtensions().add(extension);
+                            } else {
+                                constrainingType.getExtensions().add(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();
-                }
+                    }
+                    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;
-            
-        } catch (XMLStreamException e) {
-            throw new ContributionReadException(e);
         }
+        return constrainingType;
     }
     
-    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()),
-               writeIntents(constrainingType));
-    
-            // Write <service> elements 
-            for (AbstractService service : constrainingType.getServices()) {
-                writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
-                           writeIntents(service));
-                
-                extensionProcessor.write(service.getInterfaceContract(), writer);
-
-                for (Object extension: service.getExtensions()) {
-                    extensionProcessor.write(extension, writer);
-                }
-                
-                writeEnd(writer);
-            }
+    public void write(ConstrainingType constrainingType, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
 
-            // Write <reference> elements
-            for (AbstractReference reference : constrainingType.getReferences()) {
-                writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
-                           writeIntents(reference));
-                
-                extensionProcessor.write(reference.getInterfaceContract(), writer);
-
-                for (Object extension: reference.getExtensions()) {
-                    extensionProcessor.write(extension, writer);
-                }
-                
-                writeEnd(writer);
-            }
-    
-            // 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);
-
-                // Write extensions
-                for (Object extension : abstractProperty.getExtensions()) {
-                    extensionProcessor.write(extension, writer);
-                }
+        // Write <constrainingType> element
+        writeStartDocument(writer, CONSTRAINING_TYPE,
+           new XAttr(TARGET_NAMESPACE, constrainingType.getName().getNamespaceURI()),
+           new XAttr(NAME, constrainingType.getName().getLocalPart()),
+           policyProcessor.writePolicies(constrainingType));
+
+        // Write <service> elements 
+        for (AbstractService service : constrainingType.getServices()) {
+            writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
+                       policyProcessor.writePolicies(service));
+            
+            extensionProcessor.write(service.getInterfaceContract(), writer);
 
-                writeEnd(writer);
-            }
-    
-            // Write extension elements
-            for (Object extension: constrainingType.getExtensions()) {
+            for (Object extension: service.getExtensions()) {
                 extensionProcessor.write(extension, writer);
             }
             
-            writeEndDocument(writer);
+            writeEnd(writer);
+        }
+
+        // Write <reference> elements
+        for (AbstractReference reference : constrainingType.getReferences()) {
+            writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
+                       policyProcessor.writePolicies(reference));
             
-        } catch (XMLStreamException e) {
-            throw new ContributionWriteException(e);
+            extensionProcessor.write(reference.getInterfaceContract(), writer);
+
+            for (Object extension: reference.getExtensions()) {
+                extensionProcessor.write(extension, writer);
+            }
+            
+            writeEnd(writer);
+        }
+
+        // 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()),
+                       policyProcessor.writePolicies(abstractProperty));
+
+            // Write property value
+            writePropertyValue(abstractProperty.getValue(), abstractProperty.getXSDElement(), abstractProperty.getXSDType(), writer);
+
+            // 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);
+        }
+        
+        writeEndDocument(writer);
     }
     
     public void resolve(ConstrainingType constrainingType, ModelResolver resolver) throws ContributionResolveException {

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java Mon Sep  3 02:46:41 2007
@@ -22,10 +22,13 @@
 import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
 
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
@@ -38,11 +41,10 @@
 import org.apache.tuscany.sca.contribution.service.ContributionReadException;
 import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
 import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
-import org.apache.tuscany.sca.policy.IntentAttachPoint;
 import org.apache.tuscany.sca.policy.PolicyFactory;
 import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
 
-public class DefaultBeanModelProcessor extends BaseArtifactProcessor implements StAXArtifactProcessor {
+public class DefaultBeanModelProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor {
 
     private QName artifactType;
     private Class<Implementation> modelClass;
@@ -84,6 +86,7 @@
                     getter = modelClass.getMethod("get" + name.substring(3));
                 } catch (Exception e) {
                     getter = null;
+                    continue;
                 }
                 
                 // Get the property name
@@ -111,11 +114,10 @@
         }
     }
 
-    public Object read(XMLStreamReader reader) throws ContributionReadException {
+    public Object read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
 
+        // Read an element
         try {
-
-            // Read an element
             
             // Create a new instance of the model
             Object model;
@@ -139,13 +141,9 @@
             }
 
             // Read policies
-            if (model instanceof PolicySetAttachPoint) {
-                readPolicies((PolicySetAttachPoint)model, reader);
-            } else if (model instanceof IntentAttachPoint) {
-                readIntents((IntentAttachPoint)model, reader);
-            }
+            policyProcessor.readPolicies(model, reader);
 
-            // TODO read extension elements
+            // FIXME read extension elements
             
             // By default mark the model object unresolved
             if (model instanceof Base) {
@@ -165,20 +163,22 @@
         }
     }
 
-    public void write(Object bean, XMLStreamWriter writer) throws ContributionWriteException {
+    public void write(Object bean, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
         try {
-            // Write an <bean>
-            writer.writeStartElement(artifactType.getNamespaceURI(), artifactType.getLocalPart());
-
             // Write the bean properties as attributes
+            List<XAttr> attrs = new ArrayList<XAttr>();
             for (Map.Entry<String, Method> entry: getterMethods.entrySet()) {
                 if (entry.getValue().getReturnType() == String.class) {
                     String value = (String)entry.getValue().invoke(bean);
-                    writer.writeAttribute(entry.getKey(), value);
+                    attrs.add(new XAttr(entry.getKey(), value));
                 }
             }
             
-            writer.writeEndElement();
+            // Write element
+            writeStart(writer, artifactType.getNamespaceURI(), artifactType.getLocalPart(),
+                       policyProcessor.writePolicies(bean), new XAttr(null, attrs));
+
+            writeEnd(writer);
 
         } catch (Exception e) {
             throw new ContributionWriteException(e);

Added: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java?rev=572267&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java (added)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java Mon Sep  3 02:46:41 2007
@@ -0,0 +1,216 @@
+/*
+ * 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.assembly.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+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.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+public class PolicyAttachPointProcessor extends BaseStAXArtifactProcessor implements Constants {
+    
+    private PolicyFactory policyFactory;
+    
+    public PolicyAttachPointProcessor(PolicyFactory policyFactory) {
+        this.policyFactory = policyFactory;
+    }
+
+    /**
+     * Read policy intents associated with an operation.
+     * @param attachPoint
+     * @param operation
+     * @param reader
+     */
+    private void readIntents(Object attachPoint, Operation operation, XMLStreamReader reader) {
+        if (!(attachPoint instanceof IntentAttachPoint))
+            return;
+        IntentAttachPoint intentAttachPoint = (IntentAttachPoint)attachPoint;
+        String value = reader.getAttributeValue(null, REQUIRES);
+        if (value != null) {
+            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);
+            }
+        }
+    }
+
+    /**
+     * Reads policy intents and policy sets associated with an operation.
+     * @param attachPoint
+     * @param operation
+     * @param reader
+     */
+    public void readPolicies(Object attachPoint, Operation operation, XMLStreamReader reader) {
+        readIntents(attachPoint, operation, reader);
+        readPolicySets(attachPoint, operation, reader);
+    }
+
+    /**
+     * Reads policy intents and policy sets.
+     * @param attachPoint
+     * @param reader
+     */
+    public void readPolicies(Object attachPoint, XMLStreamReader reader) {
+        readPolicies(attachPoint, null, reader);
+    }
+
+    /**
+     * Reads policy sets associated with an operation.
+     * @param attachPoint
+     * @param operation
+     * @param reader
+     */
+    private void readPolicySets(Object attachPoint, Operation operation, XMLStreamReader reader) {
+        if (!(attachPoint instanceof PolicySetAttachPoint)) {
+            return;
+        }
+        PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint;
+        String value = reader.getAttributeValue(null, POLICY_SETS);
+        if (value != null) {
+            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);
+            }
+        }
+    }
+    
+    /**
+     * Write policies
+     * @param attachPoint
+     * @return
+     */
+    XAttr writePolicies(Object attachPoint) throws XMLStreamException {
+        return writePolicies(attachPoint, (Operation)null);
+    }
+
+    /**
+     * Write policies
+     * @param attachPoint
+     * @return
+     */
+    public void writePolicyAttributes(Object attachPoint, XMLStreamWriter writer) throws XMLStreamException {
+        writePolicyAttributes(attachPoint, (Operation)null, writer);
+    }
+
+    /**
+     * Write policies
+     * @param attachPoint
+     * @return
+     */
+    public void writePolicyPrefixes(Object attachPoint, XMLStreamWriter writer) throws XMLStreamException {
+        writePolicyPrefixes(attachPoint, (Operation)null, writer);
+    }
+
+    /**
+     * Write policies associated with an operation
+     * @param attachPoint
+     * @param operation
+     * @return
+     */
+    XAttr writePolicies(Object attachPoint, Operation operation) {
+        List<XAttr> attrs =new ArrayList<XAttr>();
+        attrs.add(writeIntents(attachPoint, operation));
+        attrs.add(writePolicySets(attachPoint, operation));
+        return new XAttr(null, attrs);
+    }
+
+    /**
+     * Write policies
+     * @param attachPoint
+     * @return
+     */
+    public void writePolicyAttributes(Object attachPoint, Operation operation, XMLStreamWriter writer) throws XMLStreamException {
+        XAttr attr = writePolicies(attachPoint, operation);
+        attr.write(writer);
+    }
+
+    /**
+     * Write policies
+     * @param attachPoint
+     * @return
+     */
+    public void writePolicyPrefixes(Object attachPoint, Operation operation, XMLStreamWriter writer) throws XMLStreamException {
+        XAttr attr = writePolicies(attachPoint, operation);
+        attr.writePrefix(writer);
+    }
+
+    /**
+     * Write policy intents associated with an operation.
+     * @param attachPoint
+     * @param operation
+     */
+    private 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);
+    }
+
+    /**
+     * Write policy sets associated with an operation.
+     * @param attachPoint
+     * @param operation
+     */
+    private 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);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org