diff options
Diffstat (limited to 'branches/sca-java-1.3.3/modules')
18 files changed, 1021 insertions, 808 deletions
diff --git a/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java b/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java index 9727b89aab..3da39732e9 100644 --- a/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java +++ b/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java @@ -84,7 +84,7 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA 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 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA 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; } diff --git a/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java index 09ec7664ce..dfeb647380 100644 --- a/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java +++ b/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java @@ -149,7 +149,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt super(contributionFactory, assemblyFactory, policyFactory, extensionProcessor, monitor); } - public Composite read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public Composite read(XMLStreamReader reader) throws ContributionReadException { Composite composite = null; Composite include = null; Component component = null; @@ -164,411 +164,418 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt 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)); - - //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); - } + try { + // Read the composite document + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + name = reader.getName(); - Component promotedComponent = assemblyFactory.createComponent(); - promotedComponent.setUnresolved(true); - promotedComponent.setName(promotedComponentName); - compositeService.setPromotedComponent(promotedComponent); + if (COMPOSITE_QNAME.equals(name)) { - ComponentService promotedService = assemblyFactory.createComponentService(); - promotedService.setUnresolved(true); - promotedService.setName(promotedServiceName); - compositeService.setPromotedService(promotedService); + // 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()); } - - //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; } diff --git a/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java b/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java index 334b6c6b97..35a1c553b2 100644 --- a/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java +++ b/branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java @@ -77,7 +77,7 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements 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 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements 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; } diff --git a/branches/sca-java-1.3.3/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties b/branches/sca-java-1.3.3/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties index 95edf89e30..8cc5e5a5ec 100644 --- a/branches/sca-java-1.3.3/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties +++ b/branches/sca-java-1.3.3/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties @@ -26,4 +26,4 @@ PolicyImplValidationException = PolicyValidation exception when processing imple 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} diff --git a/branches/sca-java-1.3.3/modules/assembly-xsd/src/main/resources/sca-contributions.xsd b/branches/sca-java-1.3.3/modules/assembly-xsd/src/main/resources/sca-contributions.xsd new file mode 100644 index 0000000000..a22d8ac075 --- /dev/null +++ b/branches/sca-java-1.3.3/modules/assembly-xsd/src/main/resources/sca-contributions.xsd @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- (c) Copyright SCA Collaboration 2007 --> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + elementFormDefault="qualified"> + + <include schemaLocation="sca-core.xsd"/> + + <element name="contribution" type="sca:ContributionType"/> + <complexType name="ContributionType"> + <sequence> + <element name="deployable" type="sca:DeployableType" minOccurs="1" maxOccurs="unbounded"/> + <element name="import" type="sca:ImportType" minOccurs="0" maxOccurs="unbounded"/> + <element name="export" type="sca:ExportType" minOccurs="0" maxOccurs="unbounded"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <anyAttribute namespace="##other" processContents="lax"/> + </complexType> + + <complexType name="DeployableType"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="composite" type="QName" use="required"/> + <anyAttribute namespace="##other" processContents="lax"/> + </complexType> + + <complexType name="ImportType"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="namespace" type="string" use="required"/> + <attribute name="location" type="anyURI" use="required"/> + <anyAttribute namespace="##other" processContents="lax"/> + </complexType> + + <complexType name="ExportType"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="namespace" type="string" use="required"/> + <anyAttribute namespace="##other" processContents="lax"/> + </complexType> +</schema>
\ No newline at end of file diff --git a/branches/sca-java-1.3.3/modules/assembly-xsd/src/main/resources/sca.xsd b/branches/sca-java-1.3.3/modules/assembly-xsd/src/main/resources/sca.xsd index 10f54275d0..62444a6d03 100644 --- a/branches/sca-java-1.3.3/modules/assembly-xsd/src/main/resources/sca.xsd +++ b/branches/sca-java-1.3.3/modules/assembly-xsd/src/main/resources/sca.xsd @@ -16,6 +16,8 @@ <include schemaLocation="sca-binding-jms.xsd"/> <include schemaLocation="sca-binding-sca.xsd"/> + <include schemaLocation="sca-contributions.xsd"/> + <include schemaLocation="sca-definitions.xsd"/> <include schemaLocation="sca-policy.xsd"/> diff --git a/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java b/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java index 9f6ff52289..d7c3817b68 100644 --- a/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java +++ b/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java @@ -74,6 +74,20 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> { monitor.problem(problem); } } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } public QName getArtifactType() { return EXPORT_JAVA; @@ -86,38 +100,44 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> { /** * Process <export package=""/> */ - public JavaExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public JavaExport read(XMLStreamReader reader) throws ContributionReadException { JavaExport javaExport = this.factory.createJavaExport(); QName element = null; - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: - element = reader.getName(); - - // Read <export.java> - if (EXPORT_JAVA.equals(element)) { - String packageName = reader.getAttributeValue(null, PACKAGE); - if (packageName == null) { - error("AttributePackageMissing", reader); - //throw new ContributionReadException("Attribute 'package' is missing"); - } else - javaExport.setPackage(packageName); - } - break; - case XMLStreamConstants.END_ELEMENT: - if (EXPORT_JAVA.equals(reader.getName())) { - return javaExport; - } - break; - } - - //Read the next element - if (reader.hasNext()) { - reader.next(); + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read <export.java> + if (EXPORT_JAVA.equals(element)) { + String packageName = reader.getAttributeValue(null, PACKAGE); + if (packageName == null) { + error("AttributePackageMissing", reader); + //throw new ContributionReadException("Attribute 'package' is missing"); + } else + javaExport.setPackage(packageName); + } + break; + case XMLStreamConstants.END_ELEMENT: + if (EXPORT_JAVA.equals(reader.getName())) { + return javaExport; + } + break; + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } } } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } return javaExport; } diff --git a/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java b/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java index d027d75b32..7812c25c1c 100644 --- a/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java +++ b/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java @@ -75,6 +75,20 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> { monitor.problem(problem); } } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } public QName getArtifactType() { return IMPORT_JAVA; @@ -87,41 +101,47 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> { /** * Process <import.java package="" location=""/> */ - public JavaImport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public JavaImport read(XMLStreamReader reader) throws ContributionReadException { JavaImport javaImport = this.factory.createJavaImport(); QName element = null; - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: - element = reader.getName(); - - // Read <import.java> - if (IMPORT_JAVA.equals(element)) { - String packageName = reader.getAttributeValue(null, PACKAGE); - if (packageName == null) { - error("AttributePackageMissing", reader); - //throw new ContributionReadException("Attribute 'package' is missing"); - } else - javaImport.setPackage(packageName); - - String location = reader.getAttributeValue(null, LOCATION); - javaImport.setLocation(location); - } - break; - case XMLStreamConstants.END_ELEMENT: - if (IMPORT_JAVA.equals(reader.getName())) { - return javaImport; - } - break; - } - - // Read the next element - if (reader.hasNext()) { - reader.next(); + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read <import.java> + if (IMPORT_JAVA.equals(element)) { + String packageName = reader.getAttributeValue(null, PACKAGE); + if (packageName == null) { + error("AttributePackageMissing", reader); + //throw new ContributionReadException("Attribute 'package' is missing"); + } else + javaImport.setPackage(packageName); + + String location = reader.getAttributeValue(null, LOCATION); + javaImport.setLocation(location); + } + break; + case XMLStreamConstants.END_ELEMENT: + if (IMPORT_JAVA.equals(reader.getName())) { + return javaImport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } } } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } return javaImport; } diff --git a/branches/sca-java-1.3.3/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties b/branches/sca-java-1.3.3/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties index 70b58f75c0..09fc3e9fff 100644 --- a/branches/sca-java-1.3.3/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties +++ b/branches/sca-java-1.3.3/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties @@ -19,4 +19,5 @@ # # AttributePackageMissing = Attribute 'package' is missing +XMLStreamException = XMLStreamException occured due to : {0} diff --git a/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java b/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java index 64862301c1..a316818b0f 100644 --- a/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java +++ b/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java @@ -72,6 +72,20 @@ public class NamespaceExportProcessor implements StAXArtifactProcessor<Namespace monitor.problem(problem); } } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } public QName getArtifactType() { return EXPORT; @@ -84,39 +98,45 @@ public class NamespaceExportProcessor implements StAXArtifactProcessor<Namespace /** * Process <export namespace=""/> */ - public NamespaceExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public NamespaceExport read(XMLStreamReader reader) throws ContributionReadException { NamespaceExport namespaceExport = this.factory.createNamespaceExport(); QName element = null; - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: - element = reader.getName(); - - // Read <export> - if (EXPORT.equals(element)) { - String ns = reader.getAttributeValue(null, NAMESPACE); - if (ns == null) { - error("AttributeNameSpaceMissing", reader); - //throw new ContributionReadException("Attribute 'namespace' is missing"); - } else - namespaceExport.setNamespace(ns); - } - - break; - case XMLStreamConstants.END_ELEMENT: - if (EXPORT.equals(reader.getName())) { - return namespaceExport; - } - break; - } - - // Read the next element - if (reader.hasNext()) { - reader.next(); + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read <export> + if (EXPORT.equals(element)) { + String ns = reader.getAttributeValue(null, NAMESPACE); + if (ns == null) { + error("AttributeNameSpaceMissing", reader); + //throw new ContributionReadException("Attribute 'namespace' is missing"); + } else + namespaceExport.setNamespace(ns); + } + + break; + case XMLStreamConstants.END_ELEMENT: + if (EXPORT.equals(reader.getName())) { + return namespaceExport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } } } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } return namespaceExport; } diff --git a/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java b/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java index 829e5fa43f..a364823256 100644 --- a/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java +++ b/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java @@ -75,6 +75,20 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac } } + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + public QName getArtifactType() { return IMPORT; } @@ -86,43 +100,49 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac /** * Process <import namespace="" location=""/> */ - public NamespaceImport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public NamespaceImport read(XMLStreamReader reader) throws ContributionReadException { NamespaceImport namespaceImport = this.factory.createNamespaceImport(); QName element; - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: - element = reader.getName(); - - // Read <import> - if (IMPORT.equals(element)) { - String ns = reader.getAttributeValue(null, NAMESPACE); - if (ns == null) { - error("AttributeNameSpaceMissing", reader); - //throw new ContributionReadException("Attribute 'namespace' is missing"); - } else - namespaceImport.setNamespace(ns); - - String location = reader.getAttributeValue(null, LOCATION); - if (location != null) { - namespaceImport.setLocation(location); + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read <import> + if (IMPORT.equals(element)) { + String ns = reader.getAttributeValue(null, NAMESPACE); + if (ns == null) { + error("AttributeNameSpaceMissing", reader); + //throw new ContributionReadException("Attribute 'namespace' is missing"); + } else + namespaceImport.setNamespace(ns); + + String location = reader.getAttributeValue(null, LOCATION); + if (location != null) { + namespaceImport.setLocation(location); + } } - } - break; - case XMLStreamConstants.END_ELEMENT: - if (IMPORT.equals(reader.getName())) { - return namespaceImport; - } - break; - } - - // Read the next element - if (reader.hasNext()) { - reader.next(); + break; + case XMLStreamConstants.END_ELEMENT: + if (IMPORT.equals(reader.getName())) { + return namespaceImport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } } } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } return namespaceImport; } diff --git a/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties b/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties index c7ddba3c3d..c1cbd06e7f 100644 --- a/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties +++ b/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties @@ -19,4 +19,5 @@ # # AttributeNameSpaceMissing = Attribute 'namespace' is missing +XMLStreamException = XMLStreamException occured due to : {0} diff --git a/branches/sca-java-1.3.3/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java b/branches/sca-java-1.3.3/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java index 68d5d4761e..cf99aee389 100644 --- a/branches/sca-java-1.3.3/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java +++ b/branches/sca-java-1.3.3/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java @@ -68,10 +68,24 @@ public class ResourceExportProcessor implements StAXArtifactProcessor<ResourceEx */ private void error(String message, Object model, Object... messageParameters) { if (monitor != null) { - Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); } } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } public QName getArtifactType() { return EXPORT_RESOURCE; @@ -84,39 +98,45 @@ public class ResourceExportProcessor implements StAXArtifactProcessor<ResourceEx /** * Process <export.resource uri=""/> */ - public ResourceExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public ResourceExport read(XMLStreamReader reader) throws ContributionReadException { ResourceExport resourceExport = this.factory.createResourceExport(); QName element = null; - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: - element = reader.getName(); - - // Read <export.resource> - if (EXPORT_RESOURCE.equals(element)) { - String uri = reader.getAttributeValue(null, URI); - if (uri == null) { - error("AttributeURIMissing", reader); - //throw new ContributionReadException("Attribute 'uri' is missing"); - } else - resourceExport.setURI(uri); - } - - break; - case XMLStreamConstants.END_ELEMENT: - if (EXPORT_RESOURCE.equals(reader.getName())) { - return resourceExport; - } - break; - } - - // Read the next element - if (reader.hasNext()) { - reader.next(); + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read <export.resource> + if (EXPORT_RESOURCE.equals(element)) { + String uri = reader.getAttributeValue(null, URI); + if (uri == null) { + error("AttributeURIMissing", reader); + //throw new ContributionReadException("Attribute 'uri' is missing"); + } else + resourceExport.setURI(uri); + } + + break; + case XMLStreamConstants.END_ELEMENT: + if (EXPORT_RESOURCE.equals(reader.getName())) { + return resourceExport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } } } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } return resourceExport; } diff --git a/branches/sca-java-1.3.3/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java b/branches/sca-java-1.3.3/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java index 8b2fc44a1c..bc3fb7fa5f 100644 --- a/branches/sca-java-1.3.3/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java +++ b/branches/sca-java-1.3.3/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java @@ -74,6 +74,20 @@ public class ResourceImportProcessor implements StAXArtifactProcessor<ResourceI monitor.problem(problem); } } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } public QName getArtifactType() { return IMPORT_RESOURCE; @@ -86,43 +100,49 @@ public class ResourceImportProcessor implements StAXArtifactProcessor<ResourceI /** * Process <import.resource uri="" location=""/> */ - public ResourceImport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public ResourceImport read(XMLStreamReader reader) throws ContributionReadException { ResourceImport resourceImport = this.factory.createResourceImport(); QName element; - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: - element = reader.getName(); - - // Read <import> - if (IMPORT_RESOURCE.equals(element)) { - String uri = reader.getAttributeValue(null, URI); - if (uri == null) { - error("AttributeURIMissing", reader); - //throw new ContributionReadException("Attribute 'uri' is missing"); - } else - resourceImport.setURI(uri); - - String location = reader.getAttributeValue(null, LOCATION); - if (location != null) { - resourceImport.setLocation(location); + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read <import> + if (IMPORT_RESOURCE.equals(element)) { + String uri = reader.getAttributeValue(null, URI); + if (uri == null) { + error("AttributeURIMissing", reader); + //throw new ContributionReadException("Attribute 'uri' is missing"); + } else + resourceImport.setURI(uri); + + String location = reader.getAttributeValue(null, LOCATION); + if (location != null) { + resourceImport.setLocation(location); + } } - } - break; - case XMLStreamConstants.END_ELEMENT: - if (IMPORT_RESOURCE.equals(reader.getName())) { - return resourceImport; - } - break; - } - - // Read the next element - if (reader.hasNext()) { - reader.next(); + break; + case XMLStreamConstants.END_ELEMENT: + if (IMPORT_RESOURCE.equals(reader.getName())) { + return resourceImport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } } } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } return resourceImport; } diff --git a/branches/sca-java-1.3.3/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties b/branches/sca-java-1.3.3/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties index 58ee8153f8..9df66cce52 100644 --- a/branches/sca-java-1.3.3/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties +++ b/branches/sca-java-1.3.3/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties @@ -19,4 +19,5 @@ # # AttributeURIMissing = Attribute 'uri' is missing +XMLStreamException = XMLStreamException occured due to : {0} diff --git a/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java b/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java index e2e97239e0..f74a87d890 100644 --- a/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java +++ b/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java @@ -33,6 +33,7 @@ import org.apache.tuscany.sca.contribution.ContributionMetadata; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.contribution.service.ContributionReadException; import org.apache.tuscany.sca.contribution.service.ContributionResolveException; @@ -61,7 +62,7 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess public ContributionMetadataDocumentProcessor(ModelFactoryExtensionPoint modelFactories, StAXArtifactProcessor staxProcessor, Monitor monitor) { - this.inputFactory = modelFactories.getFactory(XMLInputFactory.class); + this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); this.staxProcessor = staxProcessor; this.monitor = monitor; } diff --git a/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java b/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java index 3f5aacb541..dd1a3a677e 100644 --- a/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java +++ b/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java @@ -88,6 +88,20 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp } } + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-xml-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + public ContributionMetadataProcessor(ModelFactoryExtensionPoint modelFactories, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) { @@ -106,63 +120,69 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp return ContributionMetadata.class; } - public ContributionMetadata read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public ContributionMetadata read(XMLStreamReader reader) throws ContributionReadException { ContributionMetadata contribution = null; QName name = null; - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: - name = reader.getName(); - - if (CONTRIBUTION_QNAME.equals(name)) { - - // Read <contribution> - contribution = this.contributionFactory.createContributionMetadata(); - contribution.setUnresolved(true); + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + name = reader.getName(); - } else if (DEPLOYABLE_QNAME.equals(name)) { - - // Read <deployable> - QName compositeName = getQName(reader, "composite"); - if (compositeName == null) { - error("AttributeCompositeMissing", reader); - //throw new ContributionReadException("Attribute 'composite' is missing"); + if (CONTRIBUTION_QNAME.equals(name)) { + + // Read <contribution> + contribution = this.contributionFactory.createContributionMetadata(); + contribution.setUnresolved(true); + + } else if (DEPLOYABLE_QNAME.equals(name)) { + + // Read <deployable> + QName compositeName = getQName(reader, "composite"); + if (compositeName == null) { + error("AttributeCompositeMissing", reader); + //throw new ContributionReadException("Attribute 'composite' is missing"); + } else { + if (contribution != null) { + Composite composite = assemblyFactory.createComposite(); + composite.setName(compositeName); + composite.setUnresolved(true); + contribution.getDeployables().add(composite); + } + } } else { - if (contribution != null) { - Composite composite = assemblyFactory.createComposite(); - composite.setName(compositeName); - composite.setUnresolved(true); - contribution.getDeployables().add(composite); + + // Read an extension element + Object extension = extensionProcessor.read(reader); + if (extension != null && contribution != null) { + if (extension instanceof Import) { + contribution.getImports().add((Import)extension); + } else if (extension instanceof Export) { + contribution.getExports().add((Export)extension); + } } } - } else { - - // Read an extension element - Object extension = extensionProcessor.read(reader); - if (extension != null && contribution != null) { - if (extension instanceof Import) { - contribution.getImports().add((Import)extension); - } else if (extension instanceof Export) { - contribution.getExports().add((Export)extension); - } + break; + + case XMLStreamConstants.END_ELEMENT: + if (CONTRIBUTION_QNAME.equals(reader.getName())) { + return contribution; } - } - break; - - case XMLStreamConstants.END_ELEMENT: - if (CONTRIBUTION_QNAME.equals(reader.getName())) { - return contribution; - } - break; - } - - //Read the next element - if (reader.hasNext()) { - reader.next(); + break; + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } } } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } return contribution; } diff --git a/branches/sca-java-1.3.3/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties b/branches/sca-java-1.3.3/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties index 3e1a0187fe..4827fd5e94 100644 --- a/branches/sca-java-1.3.3/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties +++ b/branches/sca-java-1.3.3/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties @@ -18,6 +18,7 @@ # under the License. # # -XMLStreamException = XMLStreamException occured due to: -IOException = IOException occured due to: -AttributeCompositeMissing = Attribute 'composite' is missing
\ No newline at end of file +XMLStreamException = XMLStreamException occured due to : {0} +IOException = IOException occured due to : {0} +AttributeCompositeMissing = Attribute 'composite' is missing + |