tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r718858 [2/9] - in /tuscany/java/sca/modules: ./ assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ assembly-xml/src/main/resources/ assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ assembly-xml/src/test/resource...
Date Wed, 19 Nov 2008 05:28:12 GMT

Propchange: tuscany/java/sca/modules/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Nov 18 21:27:58 2008
@@ -1,2 +1,3 @@
 /tuscany/branches/sca-java-1.3/modules:671193
-/tuscany/java/sca/modules:694855
+/tuscany/branches/sca-java-1.x/modules:713805-714043
+/tuscany/java/sca/modules:694816-713804

Modified: tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java?rev=718858&r1=718857&r2=718858&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java (original)
+++ tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java Tue Nov 18 21:27:58 2008
@@ -242,8 +242,29 @@
             reference.setMultiplicity(Multiplicity.ONE_N);
         } else if (ZERO_N.equals(value)) {
             reference.setMultiplicity(Multiplicity.ZERO_N);
+        } else if (ONE_ONE.equals(value)) {
+            reference.setMultiplicity(Multiplicity.ONE_ONE);
         }
     }
+    
+    protected XAttr writeMultiplicity(AbstractReference reference) {
+        Multiplicity multiplicity = reference.getMultiplicity();
+        if (multiplicity != null) {
+            String value = null;
+            if (Multiplicity.ZERO_ONE.equals(multiplicity)) {
+                value = ZERO_ONE;
+            } else if (Multiplicity.ONE_N.equals(multiplicity)) {
+                value = ONE_N;
+            } else if (Multiplicity.ZERO_N.equals(multiplicity)) {
+                value = ZERO_N;
+            } else if (Multiplicity.ONE_ONE.equals(multiplicity)) {
+                value = ONE_ONE;
+                return null;
+            }
+            return new XAttr(MULTIPLICITY, value);
+        }
+        return null;
+    }
 
     /**
      * Returns the value of a constrainingType attribute.

Modified: tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java?rev=718858&r1=718857&r2=718858&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java (original)
+++ tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java Tue Nov 18 21:27:58 2008
@@ -84,7 +84,7 @@
               modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor);
     }
     
-    public ComponentType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+    public ComponentType read(XMLStreamReader reader) throws ContributionReadException {
         ComponentType componentType = null;
         Service service = null;
         Reference reference = null;
@@ -93,136 +93,143 @@
         Callback callback = null;
         QName name = null;
         
-        // Read the componentType document
-        while (reader.hasNext()) {
-            int event = reader.getEventType();
-            switch (event) {
-                case START_ELEMENT:
-                    name = reader.getName();
-
-                    if (Constants.COMPONENT_TYPE_QNAME.equals(name)) {
-
-                        // Read a <componentType>
-                        componentType = assemblyFactory.createComponentType();
-                        componentType.setConstrainingType(readConstrainingType(reader));
-
-                    } else if (Constants.SERVICE_QNAME.equals(name)) {
-
-                        // Read a <service>
-                        service = assemblyFactory.createService();
-                        contract = service;
-                        service.setName(getString(reader, Constants.NAME));
-                        componentType.getServices().add(service);
-                        policyProcessor.readPolicies(service, reader);
-
-                    } else if (Constants.REFERENCE_QNAME.equals(name)) {
-
-                        // Read a <reference>
-                        reference = assemblyFactory.createReference();
-                        contract = reference;
-                        reference.setName(getString(reader, Constants.NAME));
-                        reference.setWiredByImpl(getBoolean(reader, Constants.WIRED_BY_IMPL));
-                        readMultiplicity(reference, reader);
-                        readTargets(reference, reader);
-                        componentType.getReferences().add(reference);
-                        policyProcessor.readPolicies(reference, reader);
-
-                    } else if (Constants.PROPERTY_QNAME.equals(name)) {
-
-                        // Read a <property>
-                        property = assemblyFactory.createProperty();
-                        readAbstractProperty(property, reader);
-                        policyProcessor.readPolicies(property, reader);
-                        
-                        // Read the property value
-                        Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
-                        property.setValue(value);
-                        
-                        componentType.getProperties().add(property);
-                        
-                    } else if (Constants.IMPLEMENTATION_QNAME.equals(name)) {
-                        
-                        // Read an <implementation> element
-                        policyProcessor.readPolicies(componentType, reader);
-                        
-                    } else if (Constants.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 = new OperationImpl();
-                        operation.setName(getString(reader, NAME));
-                        operation.setUnresolved(true);
-                        if (callback != null) {
-                            policyProcessor.readPolicies(callback, operation, reader);
-                        } else {
-                            policyProcessor.readPolicies(contract, operation, reader);
-                        }
-                    } else {
-
-                        // Read an extension element
-                        Object extension = extensionProcessor.read(reader);
-                        if (extension != null) {
-                            if (extension instanceof InterfaceContract) {
-
-                                // <service><interface> and <reference><interface>
-                                contract.setInterfaceContract((InterfaceContract)extension);
-
-                            } else if (extension instanceof Binding) {
-
-                                // <service><binding> and <reference><binding>
-                                if (callback != null) {
-                                    callback.getBindings().add((Binding)extension);
-                                } else {
-                                    contract.getBindings().add((Binding)extension);
-                                }
+        try {
+            // Read the componentType document
+            while (reader.hasNext()) {
+                int event = reader.getEventType();
+                switch (event) {
+                    case START_ELEMENT:
+                        name = reader.getName();
+    
+                        if (Constants.COMPONENT_TYPE_QNAME.equals(name)) {
+    
+                            // Read a <componentType>
+                            componentType = assemblyFactory.createComponentType();
+                            componentType.setConstrainingType(readConstrainingType(reader));
+    
+                        } else if (Constants.SERVICE_QNAME.equals(name)) {
+    
+                            // Read a <service>
+                            service = assemblyFactory.createService();
+                            contract = service;
+                            service.setName(getString(reader, Constants.NAME));
+                            componentType.getServices().add(service);
+                            policyProcessor.readPolicies(service, reader);
+    
+                        } else if (Constants.REFERENCE_QNAME.equals(name)) {
+    
+                            // Read a <reference>
+                            reference = assemblyFactory.createReference();
+                            contract = reference;
+                            reference.setName(getString(reader, Constants.NAME));
+                            reference.setWiredByImpl(getBoolean(reader, Constants.WIRED_BY_IMPL));
+                            readMultiplicity(reference, reader);
+                            readTargets(reference, reader);
+                            componentType.getReferences().add(reference);
+                            policyProcessor.readPolicies(reference, reader);
+    
+                        } else if (Constants.PROPERTY_QNAME.equals(name)) {
+    
+                            // Read a <property>
+                            property = assemblyFactory.createProperty();
+                            readAbstractProperty(property, reader);
+                            policyProcessor.readPolicies(property, reader);
+                            
+                            // Read the property value
+                            Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
+                            property.setValue(value);
+                            
+                            componentType.getProperties().add(property);
+                            
+                        } else if (Constants.IMPLEMENTATION_QNAME.equals(name)) {
+                            
+                            // Read an <implementation> element
+                            policyProcessor.readPolicies(componentType, reader);
+                            
+                        } else if (Constants.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 = new OperationImpl();
+                            operation.setName(getString(reader, NAME));
+                            operation.setUnresolved(true);
+                            if (callback != null) {
+                                policyProcessor.readPolicies(callback, operation, reader);
                             } 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);
+                                policyProcessor.readPolicies(contract, operation, reader);
+                            }
+                        } else {
+    
+                            // Read an extension element
+                            Object extension = extensionProcessor.read(reader);
+                            if (extension != null) {
+                                if (extension instanceof InterfaceContract) {
+    
+                                    // <service><interface> and <reference><interface>
+                                    contract.setInterfaceContract((InterfaceContract)extension);
+    
+                                } else if (extension instanceof Binding) {
+    
+                                    // <service><binding> and <reference><binding>
+                                    if (callback != null) {
+                                        callback.getBindings().add((Binding)extension);
+                                    } else {
+                                        contract.getBindings().add((Binding)extension);
+                                    }
                                 } else {
-                                    if (componentType instanceof Extensible) {
-                                        ((Extensible)componentType).getExtensions().add(extension);
+                                    
+                                    // 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 (componentType instanceof Extensible) {
+                                            ((Extensible)componentType).getExtensions().add(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();
+                        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();
+                }
             }
         }
+        catch (XMLStreamException e) {
+            ContributionReadException ex = new ContributionReadException(e);
+            error("XMLStreamException", reader, ex);
+        }
+        
         return componentType;
     }
     
@@ -271,6 +278,7 @@
             
             writeStart(writer, REFERENCE,
                   new XAttr(NAME, reference.getName()),
+                  writeMultiplicity(reference),
                   writeTargets(reference),
                   policyProcessor.writePolicies(reference));
 

Modified: tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java?rev=718858&r1=718857&r2=718858&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java (original)
+++ tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java Tue Nov 18 21:27:58 2008
@@ -136,7 +136,7 @@
         
     }
     
-    public Composite read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+    public Composite read(XMLStreamReader reader) throws ContributionReadException {
         Composite composite = null;
         Composite include = null;
         Component component = null;
@@ -151,411 +151,418 @@
         Callback callback = null;
         QName name = null;
 
-        // 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, TARGET_NAMESPACE)){
-                            // spec says that a composite must have a namespace
-                            warning("NoCompositeNamespace", composite, composite.getName().toString());   
-                        }
-                        
-                        if(isSet(reader, AUTOWIRE)) {
-                            composite.setAutowire(getBoolean(reader, AUTOWIRE));
-                        }
-                        
-                        //handle extension attributes
-                        this.readExtendedAttributes(reader, name, composite, extensionAttributeProcessor);
-
-                        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.setURI(getString(reader, URI));
-                        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));
+        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();
                             
-                            //handle extension attributes
-                            this.readExtendedAttributes(reader, name, componentService, extensionAttributeProcessor);
-
-                            component.getServices().add(componentService);
-                            policyProcessor.readPolicies(contract, reader);
-                        } else {
-
-                            // Read a <composite><service>
-                            compositeService = assemblyFactory.createCompositeService();
-                            contract = compositeService;
-                            compositeService.setName(getString(reader, NAME));
-
-                            String promoted = getString(reader, PROMOTE);
-                            if (promoted != null) {
-                                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);
-                                }
+                            composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
     
-                                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);
+                            if(!isSet(reader, TARGET_NAMESPACE)){
+                                // spec says that a composite must have a namespace
+                                warning("NoCompositeNamespace", composite, composite.getName().toString());   
                             }
-
-                            //handle extension attributes
-                            this.readExtendedAttributes(reader, name, compositeService, extensionAttributeProcessor);
-
-                            composite.getServices().add(compositeService);
-                            policyProcessor.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));
+                            
+                            if(isSet(reader, AUTOWIRE)) {
+                                composite.setAutowire(getBoolean(reader, AUTOWIRE));
                             }
-                            readTargets(componentReference, reader);
-                            componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                             
                             //handle extension attributes
-                            this.readExtendedAttributes(reader, name, componentReference, extensionAttributeProcessor);
-
-                            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);
+                            this.readExtendedAttributes(reader, name, composite, extensionAttributeProcessor);
+    
+                            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.setURI(getString(reader, URI));
+                            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));
+                                
+                                //handle extension attributes
+                                this.readExtendedAttributes(reader, name, componentService, extensionAttributeProcessor);
+    
+                                component.getServices().add(componentService);
+                                policyProcessor.readPolicies(contract, reader);
+                            } else {
+    
+                                // Read a <composite><service>
+                                compositeService = assemblyFactory.createCompositeService();
+                                contract = compositeService;
+                                compositeService.setName(getString(reader, NAME));
+    
+                                String promoted = getString(reader, PROMOTE);
+                                if (promoted != null) {
+                                    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);
                                 }
+    
+                                //handle extension attributes
+                                this.readExtendedAttributes(reader, name, compositeService, extensionAttributeProcessor);
+    
+                                composite.getServices().add(compositeService);
+                                policyProcessor.readPolicies(contract, reader);
                             }
-                            compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
-                            
-                            //handle extension attributes
-                            this.readExtendedAttributes(reader, name, compositeReference, extensionAttributeProcessor);
-
-                            composite.getReferences().add(compositeReference);                            
-                            policyProcessor.readPolicies(contract, reader);
-                        }
-
-                    } else if (PROPERTY_QNAME.equals(name)) {
-                        if (component != null) {
-
-                            // Read a <component><property>
-                            componentProperty = assemblyFactory.createComponentProperty();
-                            property = componentProperty;
-                            String source = getString(reader, SOURCE);
-                            if(source!=null) {
-                                source = source.trim();
+    
+                        } 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));
+                                
+                                //handle extension attributes
+                                this.readExtendedAttributes(reader, name, componentReference, extensionAttributeProcessor);
+    
+                                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));
+                                
+                                //handle extension attributes
+                                this.readExtendedAttributes(reader, name, compositeReference, extensionAttributeProcessor);
+    
+                                composite.getReferences().add(compositeReference);                            
+                                policyProcessor.readPolicies(contract, reader);
                             }
-                            componentProperty.setSource(source);
-                            if (source != null) {
-                                // $<name>/...
-                                if (source.charAt(0) == '$') {
-                                    int index = source.indexOf('/');
-                                    if (index == -1) {
-                                        // Tolerating $prop
-                                        source = source + "/";
-                                        index = source.length() - 1;
+    
+                        } else if (PROPERTY_QNAME.equals(name)) {
+                            if (component != null) {
+    
+                                // Read a <component><property>
+                                componentProperty = assemblyFactory.createComponentProperty();
+                                property = componentProperty;
+                                String source = getString(reader, SOURCE);
+                                if(source!=null) {
+                                    source = source.trim();
+                                }
+                                componentProperty.setSource(source);
+                                if (source != null) {
+                                    // $<name>/...
+                                    if (source.charAt(0) == '$') {
+                                        int index = source.indexOf('/');
+                                        if (index == -1) {
+                                            // Tolerating $prop
+                                            source = source + "/";
+                                            index = source.length() - 1;
+                                        }
+                                        source = source.substring(index + 1);
+                                        if ("".equals(source)) {
+                                            source = ".";
+                                        }
                                     }
-                                    source = source.substring(index + 1);
-                                    if ("".equals(source)) {
-                                        source = ".";
+                                    XPath xpath = xPathFactory.newXPath();
+                                    xpath.setNamespaceContext(reader.getNamespaceContext());
+                                    try {
+                                        componentProperty.setSourceXPathExpression(xpath.compile(source));
+                                    } catch (XPathExpressionException e) {
+                                    	ContributionReadException ce = new ContributionReadException(e);
+                                    	error("ContributionReadException", xpath, ce);
+                                        //throw ce;
                                     }
                                 }
-                                XPath xpath = xPathFactory.newXPath();
-                                xpath.setNamespaceContext(reader.getNamespaceContext());
-                                try {
-                                    componentProperty.setSourceXPathExpression(xpath.compile(source));
-                                } catch (XPathExpressionException e) {
-                                	ContributionReadException ce = new ContributionReadException(e);
-                                	error("ContributionReadException", xpath, ce);
-                                    //throw ce;
-                                }
+                                componentProperty.setFile(getString(reader, FILE));
+                                
+                                //handle extension attributes
+                                this.readExtendedAttributes(reader, name, componentProperty, extensionAttributeProcessor);
+    
+                                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();
+                                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);
+                            }
+                            
+                            // TUSCANY-1949
+                            // If the property doesn't have a value, the END_ELEMENT event is read by the readPropertyValue
+                            if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
+                                property = null;
+                                componentProperty = null;
+                            }
+    
+                        } 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));
+                            }
+                            if (isSet(reader, URI)) {
+                                component.setURI(getString(reader, URI));
                             }
-                            componentProperty.setFile(getString(reader, FILE));
                             
                             //handle extension attributes
-                            this.readExtendedAttributes(reader, name, componentProperty, extensionAttributeProcessor);
-
-                            policyProcessor.readPolicies(property, reader);
-                            readAbstractProperty(componentProperty, reader);
+                           this.readExtendedAttributes(reader, name, component, extensionAttributeProcessor);
                             
-                            // Read the property value
-                            Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
-                            property.setValue(value);
+                            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);
+    
+                            //handle extension attributes
+                            this.readExtendedAttributes(reader, name, wire, extensionAttributeProcessor);
+    
+                            composite.getWires().add(wire);
+                            policyProcessor.readPolicies(wire, reader);
+    
+                        } else if (CALLBACK_QNAME.equals(name)) {
+    
+                            // Read a <callback>
+                            callback = assemblyFactory.createCallback();
+                            contract.setCallback(callback);
                             
-                            component.getProperties().add(componentProperty);
-                        } else {
-
-                            // Read a <composite><property>
-                            property = assemblyFactory.createProperty();
-                            policyProcessor.readPolicies(property, reader);
-                            readAbstractProperty(property, reader);
+                            //handle extension attributes
+                            this.readExtendedAttributes(reader, name, callback, extensionAttributeProcessor);
                             
-                            // Read the property value
-                            Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
-                            property.setValue(value);
+                            policyProcessor.readPolicies(callback, reader);
+    
+                        } else if (OPERATION_QNAME.equals(name)) {
+    
+                            // Read an <operation>
+                            ConfiguredOperation operation = assemblyFactory.createConfiguredOperation();
+                            operation.setName(getString(reader, NAME));
+                            operation.setUnresolved(true);
+                            if (callback != null) {
+                                policyProcessor.readPolicies(operation, reader);
+                            } else {
+                                policyProcessor.readPolicies(operation, reader);
+                            }
                             
-                            composite.getProperties().add(property);
-                        }
-                        
-                        // TUSCANY-1949
-                        // If the property doesn't have a value, the END_ELEMENT event is read by the readPropertyValue
-                        if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
-                            property = null;
-                            componentProperty = null;
-                        }
-
-                    } 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));
-                        }
-                        if (isSet(reader, URI)) {
-                            component.setURI(getString(reader, URI));
-                        }
-                        
-                        //handle extension attributes
-                       this.readExtendedAttributes(reader, name, component, extensionAttributeProcessor);
-                        
-                        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);
-
-                        //handle extension attributes
-                        this.readExtendedAttributes(reader, name, wire, extensionAttributeProcessor);
-
-                        composite.getWires().add(wire);
-                        policyProcessor.readPolicies(wire, reader);
-
-                    } else if (CALLBACK_QNAME.equals(name)) {
-
-                        // Read a <callback>
-                        callback = assemblyFactory.createCallback();
-                        contract.setCallback(callback);
-                        
-                        //handle extension attributes
-                        this.readExtendedAttributes(reader, name, callback, extensionAttributeProcessor);
-                        
-                        policyProcessor.readPolicies(callback, reader);
-
-                    } else if (OPERATION_QNAME.equals(name)) {
-
-                        // Read an <operation>
-                        ConfiguredOperation operation = assemblyFactory.createConfiguredOperation();
-                        operation.setName(getString(reader, NAME));
-                        operation.setUnresolved(true);
-                        if (callback != null) {
-                            policyProcessor.readPolicies(operation, reader);
+                            OperationsConfigurator opConfigurator = null;
+                            if ( compositeService != null ) {
+                                opConfigurator = compositeService;
+                            } else if ( componentService != null ) {
+                                opConfigurator = componentService;
+                            } else if ( compositeReference != null ) {
+                                opConfigurator = compositeReference;
+                            } else if ( componentReference != null ) {
+                                opConfigurator = componentReference;
+                            }
+                            
+                            opConfigurator.getConfiguredOperations().add(operation);
+                        } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {
+    
+                            // Read an implementation.composite
+                            Composite implementation = assemblyFactory.createComposite();
+                            implementation.setName(getQName(reader, NAME));
+                            implementation.setUnresolved(true);
+                            
+                            //handle extension attributes
+                            this.readExtendedAttributes(reader, name, implementation, extensionAttributeProcessor);
+    
+                            component.setImplementation(implementation);
+                            policyProcessor.readPolicies(implementation, reader);
                         } else {
-                            policyProcessor.readPolicies(operation, reader);
-                        }
-                        
-                        OperationsConfigurator opConfigurator = null;
-                        if ( compositeService != null ) {
-                            opConfigurator = compositeService;
-                        } else if ( componentService != null ) {
-                            opConfigurator = componentService;
-                        } else if ( compositeReference != null ) {
-                            opConfigurator = compositeReference;
-                        } else if ( componentReference != null ) {
-                            opConfigurator = componentReference;
-                        }
-                        
-                        opConfigurator.getConfiguredOperations().add(operation);
-                    } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {
-
-                        // Read an implementation.composite
-                        Composite implementation = assemblyFactory.createComposite();
-                        implementation.setName(getQName(reader, NAME));
-                        implementation.setUnresolved(true);
-                        
-                        //handle extension attributes
-                        this.readExtendedAttributes(reader, name, implementation, extensionAttributeProcessor);
-
-                        component.setImplementation(implementation);
-                        policyProcessor.readPolicies(implementation, reader);
-                    } else {
-
-                        // 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)) {
-                                    	error("UnexpectedInterfaceElement", extension);
-                                        //throw new ContributionReadException("Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
+    
+                            // 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 {
-                                        composite.getExtensions().add(extension);
+                                        if (name.getNamespaceURI().equals(SCA10_NS)) {
+                                        	error("UnexpectedInterfaceElement", extension);
+                                            //throw new ContributionReadException("Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
+                                        } else {
+                                            composite.getExtensions().add(extension);
+                                        }
                                     }
-                                }
-                            } else if (extension instanceof Binding) {
-                                if ( extension instanceof PolicySetAttachPoint ) {
-                                    IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
-                                    bindingType.setName(name);
-                                    bindingType.setUnresolved(true);
-                                    ((PolicySetAttachPoint)extension).setType(bindingType);
-                                }
-                                // <service><binding> and
-                                // <reference><binding>
-                                if (callback != null) {
-                                    callback.getBindings().add((Binding)extension);
-                                } else {
-                                    if (contract != null) {
-                                        contract.getBindings().add((Binding)extension);
+                                } else if (extension instanceof Binding) {
+                                    if ( extension instanceof PolicySetAttachPoint ) {
+                                        IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
+                                        bindingType.setName(name);
+                                        bindingType.setUnresolved(true);
+                                        ((PolicySetAttachPoint)extension).setType(bindingType);
+                                    }
+                                    // <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)) {
+                                            	error("UnexpectedBindingElement", extension);
+                                                //throw new ContributionReadException("Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
+                                            } else {
+                                                composite.getExtensions().add(extension);
+                                            }
+                                        }
+                                    }
+    
+                                } else if (extension instanceof Implementation) {
+                                    if ( extension instanceof PolicySetAttachPoint ) {
+                                        IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType();
+                                        implType.setName(name);
+                                        implType.setUnresolved(true);
+                                        ((PolicySetAttachPoint)extension).setType(implType);
+                                    }
+                                    // <component><implementation>
+                                    if (component != null) {
+                                        component.setImplementation((Implementation)extension);
                                     } else {
                                         if (name.getNamespaceURI().equals(SCA10_NS)) {
-                                        	error("UnexpectedBindingElement", extension);
-                                            //throw new ContributionReadException("Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
+                                        	error("UnexpectedImplementationElement", extension);
+                                            //throw new ContributionReadException("Unexpected <implementation> element found. It should appear inside a <component> element");
                                         } else {
                                             composite.getExtensions().add(extension);
                                         }
                                     }
-                                }
-
-                            } else if (extension instanceof Implementation) {
-                                if ( extension instanceof PolicySetAttachPoint ) {
-                                    IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType();
-                                    implType.setName(name);
-                                    implType.setUnresolved(true);
-                                    ((PolicySetAttachPoint)extension).setType(implType);
-                                }
-                                // <component><implementation>
-                                if (component != null) {
-                                    component.setImplementation((Implementation)extension);
                                 } else {
-                                    if (name.getNamespaceURI().equals(SCA10_NS)) {
-                                    	error("UnexpectedImplementationElement", extension);
-                                        //throw new ContributionReadException("Unexpected <implementation> element found. It should appear inside a <component> element");
+    
+                                    // 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);
                                     }
                                 }
-                            } 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;
-
-                case XMLStreamConstants.CHARACTERS:
-                    break;
-
-                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();
+                        break;
+    
+                    case XMLStreamConstants.CHARACTERS:
+                        break;
+    
+                    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();
+                }
             }
         }
+        catch (XMLStreamException e) {
+            ContributionReadException ex = new ContributionReadException(e);
+            error("XMLStreamException", reader, ex);
+        }
+        
         return composite;
     }
 
@@ -567,6 +574,7 @@
                            writeConstrainingType(composite),
                            new XAttr(TARGET_NAMESPACE, composite.getName().getNamespaceURI()),
                            new XAttr(NAME, composite.getName().getLocalPart()),
+                           new XAttr(LOCAL, composite.isLocal() ? Boolean.TRUE : null),
                            new XAttr(AUTOWIRE, composite.getAutowire()),
                            policyProcessor.writePolicies(composite));
         
@@ -670,6 +678,10 @@
                 extensionProcessor.write(component.getImplementation(), writer);
             }
             
+            for (Object extension : component.getExtensions()) {
+                extensionProcessor.write(extension, writer);
+            }            
+            
             // Write <service> elements
             for (ComponentService service : component.getServices()) {
                 writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
@@ -719,6 +731,7 @@
             for (ComponentReference reference : component.getReferences()) {
                 writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
                            new XAttr(AUTOWIRE, reference.getAutowire()),
+                           writeMultiplicity(reference),
                            writeTargets(reference),
                            policyProcessor.writePolicies(reference));
 
@@ -788,7 +801,7 @@
 
                 writeEnd(writer);
             }
-    
+ 
             writeEnd(writer);
         }
 
@@ -805,6 +818,7 @@
             // Write <reference> element
             writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
                        new XAttr(PROMOTE, promote),
+                       writeMultiplicity(reference),
                        policyProcessor.writePolicies(reference));
 
             //write extended attributes
@@ -888,9 +902,9 @@
         }
 
         for (Object extension : composite.getExtensions()) {
-            extensionProcessor.write(extension, writer);
+        		extensionProcessor.write(extension, writer);
         }
-
+        
         writeEndDocument(writer);
     }
 

Modified: tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java?rev=718858&r1=718857&r2=718858&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java (original)
+++ tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java Tue Nov 18 21:27:58 2008
@@ -42,8 +42,8 @@
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
-import org.apache.tuscany.sca.policy.PolicyFactory;
 import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.PolicyFactory;
 import org.w3c.dom.Document;
 
 /**
@@ -77,7 +77,7 @@
               modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor);
     }
     
-    public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+    public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException {
         ConstrainingType constrainingType = null;
         AbstractService abstractService = null;
         AbstractReference abstractReference = null;
@@ -85,100 +85,107 @@
         AbstractContract abstractContract = null;
         QName name = null;
         
-        // 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 <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_QNAME.equals(name)) {
-
-                        // Read an <operation>
-                        Operation operation = new OperationImpl();
-                        operation.setName(getString(reader, NAME));
-                        operation.setUnresolved(true);
-                        policyProcessor.readPolicies(abstractContract, operation, reader);
+        try {
+            // Read the constrainingType document
+            while (reader.hasNext()) {
+                int event = reader.getEventType();
+                switch (event) {
+    
+                    case START_ELEMENT:
+                        name = reader.getName();
                         
-                    } else {
-
-                        // Read an extension element
-                        Object extension = extensionProcessor.read(reader);
-                        if (extension instanceof InterfaceContract) {
+                        // 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 <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_QNAME.equals(name)) {
+    
+                            // Read an <operation>
+                            Operation operation = new OperationImpl();
+                            operation.setName(getString(reader, NAME));
+                            operation.setUnresolved(true);
+                            policyProcessor.readPolicies(abstractContract, operation, reader);
                             
-                            // <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);
+    
+                            // Read an extension element
+                            Object extension = extensionProcessor.read(reader);
+                            if (extension instanceof InterfaceContract) {
+                                
+                                // <service><interface> and <reference><interface>
+                                abstractContract.setInterfaceContract((InterfaceContract)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();
+                }
             }
         }
+        catch (XMLStreamException e) {
+            ContributionReadException ex = new ContributionReadException(e);
+            error("XMLStreamException", reader, ex);
+        }
+        
         return constrainingType;
     }
     
@@ -207,6 +214,7 @@
         // Write <reference> elements
         for (AbstractReference reference : constrainingType.getReferences()) {
             writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
+                       writeMultiplicity(reference),
                        policyProcessor.writePolicies(reference));
             
             extensionProcessor.write(reference.getInterfaceContract(), writer);

Modified: tuscany/java/sca/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties?rev=718858&r1=718857&r2=718858&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties (original)
+++ tuscany/java/sca/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties Tue Nov 18 21:27:58 2008
@@ -26,4 +26,4 @@
 PolicyServiceValidationException = PolicyValidation exceptions when processing service/reference {0} in {1}. Error is {2}
 ContributionReadException = ContributionReadException occured due to : {0}
 ContributionWriteException = ContributionWriteException occured due to : {0}
-
+XMLStreamException = XMLStreamException occured due to : {0}

Modified: tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java?rev=718858&r1=718857&r2=718858&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java (original)
+++ tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java Tue Nov 18 21:27:58 2008
@@ -25,48 +25,71 @@
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamReader;
 
-import junit.framework.Assert;
+import junit.framework.TestCase;
 
 import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
 import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
 import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory;
 import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
-public class AnyElementReadWriteTestCase {
+public class AnyElementReadWriteTestCase extends TestCase {
 
-    private static XMLInputFactory inputFactory;
-    //private static String XML = "<?xml version='1.0' encoding='UTF-8'?><composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\"><service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\"><interface.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" interface=\"calculator.CalculatorService\" /></service><component name=\"CalculatorServiceComponent\"><reference name=\"addService\" target=\"AddServiceComponent\" /><reference name=\"subtractService\" target=\"SubtractServiceComponent\" /><reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" /><reference name=\"divideService\" target=\"DivideServiceComponent\" /></component><component name=\"AddServiceComponent\" /><component name=\"SubtractServiceComponent\" /><component name=\"MultiplyServiceComponent\" /><component name=\"DivideServiceComponent\" /><x:unknownElement xmlns:x=\"http://x\" uknAttr=\"
 attribute1\"><x:subUnknownElement1 uknAttr1=\"attribute1\" /><x:subUnknownElement2 /></x:unknownElement></composite>";
-    private static String XML = "<?xml version='1.0' encoding='UTF-8'?><composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\"><service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\" /><component name=\"CalculatorServiceComponent\"><reference name=\"addService\" target=\"AddServiceComponent\" /><reference name=\"subtractService\" target=\"SubtractServiceComponent\" /><reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" /><reference name=\"divideService\" target=\"DivideServiceComponent\" /></component><component name=\"AddServiceComponent\" /><component name=\"SubtractServiceComponent\" /><component name=\"MultiplyServiceComponent\" /><component name=\"DivideServiceComponent\" /></composite>";
-    private static ExtensibleStAXArtifactProcessor staxProcessor;
-
-    @BeforeClass
-    public static void setUp() throws Exception {
-        ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
-        inputFactory = XMLInputFactory.newInstance();
-        StAXArtifactProcessorExtensionPoint staxProcessors =
-            extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
-        staxProcessor =
-            new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory
-                .newInstance(), null);
-    }
-
-    @Test
-    public void testReadWriteComposite() throws Exception {
-        InputStream is = getClass().getResourceAsStream("Calculator.composite");
-        XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
-        Composite composite = (Composite)staxProcessor.read(reader);
-        Assert.assertNotNull(composite);
-
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        staxProcessor.write(composite, bos);
-        System.out.println(bos.toString());
-        Assert.assertEquals(XML, bos.toString());
-        bos.close();
+	private XMLInputFactory inputFactory;
+	String XML = "<?xml version='1.0' encoding='UTF-8'?><composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\"><service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\"><interface.java interface=\"calculator.CalculatorService\" /></service><component name=\"CalculatorServiceComponent\"><reference name=\"addService\" multiplicity=\"0..1\" target=\"AddServiceComponent\" /><reference name=\"subtractService\" target=\"SubtractServiceComponent\" /><reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" /><reference name=\"divideService\" target=\"DivideServiceComponent\" /></component><component name=\"AddServiceComponent\" /><component name=\"SubtractServiceComponent\" /><component name=\"MultiplyServiceComponent\" /><component name=\"DivideServiceComponent\" /><x:unknownElement xmlns:x=\"http://x\" uknAttr=\"attribute1\"><y:subUnknownElement1 xmlns:y
 =\"http://y\" uknAttr1=\"attribute2\" /><x:subUnknownElement2 /></x:unknownElement></composite>";
+	private ExtensibleStAXArtifactProcessor staxProcessor;
+
+	@Override
+	public void setUp() throws Exception {
+		ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+		 ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+		 inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class);
+		
+		StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints
+				.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+		staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors,
+				inputFactory, XMLOutputFactory.newInstance(), null);
+	}
+
+	@Override
+	public void tearDown() throws Exception {
+	}
+
+	/*
+	@Test
+	public void testReadWriteComposite() throws Exception {
+		InputStream is = getClass().getResourceAsStream("Calculator.composite");
+		XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+		Composite composite = (Composite) staxProcessor.read(reader);
+		assertNotNull(composite);
+
+		ByteArrayOutputStream bos = new ByteArrayOutputStream();
+		staxProcessor.write(composite, bos);
+		//System.out.println(bos.toString());
+		assertEquals(XML, bos.toString());
+		bos.close();
+
+		is.close();
+	}
+	*/
+	
+	@Test
+	public void testReadWriteUnknownElementComposite() throws Exception {
+		InputStream is = getClass().getResourceAsStream("UnknownElement.composite");
+		XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+		Composite composite = (Composite) staxProcessor.read(reader);
+		assertNotNull(composite);
+
+		ByteArrayOutputStream bos = new ByteArrayOutputStream();
+		staxProcessor.write(composite, bos);
+		System.out.println(bos.toString());
+		//assertEquals(XML, bos.toString());
+		bos.close();
 
-        is.close();
-    }
+		is.close();
+	}	
 
 }

Propchange: tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Nov 18 21:27:58 2008
@@ -0,0 +1,2 @@
+/tuscany/branches/sca-java-1.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestReadWriteUnkonwnElement.java:671193
+/tuscany/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java:713805-714043

Modified: tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java?rev=718858&r1=718857&r2=718858&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java (original)
+++ tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java Tue Nov 18 21:27:58 2008
@@ -193,7 +193,7 @@
         
         documentProcessor.resolve(composite, resolver);
         
-        assertEquals(composite.getConstrainingType(), constrainingType);
+       assertEquals(composite.getConstrainingType(), constrainingType);
         assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType);
     }
 



Mime
View raw message