From 47fdbd622dc107617a0e5bbd85d21f9249d17ed3 Mon Sep 17 00:00:00 2001 From: slaws Date: Thu, 30 Oct 2008 13:10:19 +0000 Subject: TUSCANY-2631 - Make the contribution processor more fault tolerant. Apply Ram's patches (and a few other changes). Doesn't do everything asked for in the JIRA but a step in the right direction git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@709156 13f79535-47bb-0310-9956-ffa450edef68 --- .../assembly/xml/ConstrainingTypeProcessor.java | 181 +++++++++++---------- 1 file changed, 94 insertions(+), 87 deletions(-) (limited to 'branches/sca-java-1.3.3/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java') 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 - 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 - 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 - 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 - 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 = 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 + 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 + 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 + 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 + 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 = new OperationImpl(); + operation.setName(getString(reader, NAME)); + operation.setUnresolved(true); + policyProcessor.readPolicies(abstractContract, operation, reader); - // and - 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) { + + // and + 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; } -- cgit v1.2.3