diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-22 21:51:38 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-22 21:51:38 +0000 |
commit | b354c03aecb7f30bfd65f0ec02a81ab915ba4966 (patch) | |
tree | 569564504b982d2a5bfb3ab3052c0c5130fcae28 /branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache | |
parent | baa5887866a52cd40be16707d9741cbbad9d7263 (diff) |
Add "Extensible" support for the ContributionMetaData/Contribution/Import/Export models (TUSCANY-2983)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@767683 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache')
-rw-r--r-- | branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java | 172 |
1 files changed, 97 insertions, 75 deletions
diff --git a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java b/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java index dd1a3a677e..f362b5b10f 100644 --- a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java +++ b/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java @@ -6,15 +6,15 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations - * under the License. + * under the License. */ package org.apache.tuscany.sca.contribution.xml; @@ -30,6 +30,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ExtensionFactory; import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.ContributionMetadata; @@ -38,6 +39,7 @@ import org.apache.tuscany.sca.contribution.Import; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.contribution.service.ContributionReadException; import org.apache.tuscany.sca.contribution.service.ContributionResolveException; @@ -48,70 +50,80 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; /** * Processor for contribution metadata - * + * * @version $Rev$ $Date$ */ -public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<ContributionMetadata> { - +public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor implements + StAXArtifactProcessor<ContributionMetadata> { + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; - + private static final QName CONTRIBUTION_QNAME = new QName(SCA10_NS, "contribution"); private static final QName DEPLOYABLE_QNAME = new QName(SCA10_NS, "deployable"); - + private final AssemblyFactory assemblyFactory; private final ContributionFactory contributionFactory; - + private final ExtensionFactory extensionFactory; private final StAXArtifactProcessor<Object> extensionProcessor; + private final StAXAttributeProcessor<Object> attributeProcessor; private Monitor monitor; - public ContributionMetadataProcessor(AssemblyFactory assemblyFactory, - ContributionFactory contributionFactory, - StAXArtifactProcessor<Object> extensionProcessor, - Monitor monitor) { + public ContributionMetadataProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor<Object> extensionProcessor, + StAXAttributeProcessor<Object> attributeProcessor, + Monitor monitor) { + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + this.extensionProcessor = extensionProcessor; + this.attributeProcessor = attributeProcessor; + this.monitor = monitor; + } + + /* + public ContributionMetadataProcessor(AssemblyFactory assemblyFactory, + ContributionFactory contributionFactory, + StAXArtifactProcessor<Object> extensionProcessor, + Monitor monitor) { this.assemblyFactory = assemblyFactory; this.contributionFactory = contributionFactory; this.extensionProcessor = extensionProcessor; this.monitor = monitor; } - + */ + /** * Report a error. - * + * * @param problems * @param message * @param model */ - private void error(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-xml-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-xml-validation-messages", Severity.ERROR, model, message, ex); - monitor.problem(problem); - } - } - - public ContributionMetadataProcessor(ModelFactoryExtensionPoint modelFactories, - StAXArtifactProcessor<Object> extensionProcessor, - Monitor monitor) { - this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); - this.extensionProcessor = extensionProcessor; - this.monitor = monitor; + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + new ProblemImpl(this.getClass().getName(), "contribution-xml-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-xml-validation-messages", Severity.ERROR, + model, message, ex); + monitor.problem(problem); + } } - - + public QName getArtifactType() { return CONTRIBUTION_QNAME; } @@ -123,37 +135,38 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp public ContributionMetadata read(XMLStreamReader reader) throws ContributionReadException { ContributionMetadata contribution = null; QName name = null; - + try { 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); - - } else if (DEPLOYABLE_QNAME.equals(name)) { - + readExtendedAttributes(reader, contribution, attributeProcessor, extensionFactory); + + } else if (DEPLOYABLE_QNAME.equals(name)) { + // Read <deployable> QName compositeName = getQName(reader, "composite"); if (compositeName == null) { - error("AttributeCompositeMissing", reader); + 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); + contribution.getDeployables().add(composite); } } } else { - + // Read an extension element Object extension = extensionProcessor.read(reader); if (extension != null && contribution != null) { @@ -161,69 +174,74 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp contribution.getImports().add((Import)extension); } else if (extension instanceof Export) { contribution.getExports().add((Export)extension); + } else { + contribution.getExtensions().add(extension); } } } break; - + case XMLStreamConstants.END_ELEMENT: if (CONTRIBUTION_QNAME.equals(reader.getName())) { return contribution; } - break; + break; } - + //Read the next element if (reader.hasNext()) { reader.next(); } } - } - catch (XMLStreamException e) { + } catch (XMLStreamException e) { ContributionReadException ex = new ContributionReadException(e); error("XMLStreamException", reader, ex); } - + return contribution; } - public void write(ContributionMetadata contribution, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - + public void write(ContributionMetadata contribution, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + // Write <contribution> writeStartDocument(writer, CONTRIBUTION_QNAME.getNamespaceURI(), CONTRIBUTION_QNAME.getLocalPart()); + writeExtendedAttributes(writer, contribution, attributeProcessor); // Write <import> - for (Import imp: contribution.getImports()) { + for (Import imp : contribution.getImports()) { extensionProcessor.write(imp, writer); } - + // Write <export> - for (Export export: contribution.getExports()) { + for (Export export : contribution.getExports()) { extensionProcessor.write(export, writer); } - + // Write <deployable> - for (Composite deployable: contribution.getDeployables()) { - writeStart(writer, DEPLOYABLE_QNAME.getNamespaceURI(), DEPLOYABLE_QNAME.getLocalPart(), + for (Composite deployable : contribution.getDeployables()) { + writeStart(writer, + DEPLOYABLE_QNAME.getNamespaceURI(), + DEPLOYABLE_QNAME.getLocalPart(), new XAttr("composite", deployable.getName())); writeEnd(writer); } - + writeEndDocument(writer); } public void resolve(ContributionMetadata contribution, ModelResolver resolver) throws ContributionResolveException { - + // Resolve imports and exports - for (Export export: contribution.getExports()) { + for (Export export : contribution.getExports()) { extensionProcessor.resolve(export, resolver); } - for (Import import_: contribution.getImports()) { + for (Import import_ : contribution.getImports()) { extensionProcessor.resolve(import_, resolver); } - + // Resolve deployable composites - List<Composite> deployables = contribution.getDeployables(); + List<Composite> deployables = contribution.getDeployables(); for (int i = 0, n = deployables.size(); i < n; i++) { Composite deployable = deployables.get(i); Composite resolved = (Composite)resolver.resolveModel(Composite.class, deployable); @@ -231,7 +249,11 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp deployables.set(i, resolved); } } - + + for (Object ext : contribution.getExtensions()) { + extensionProcessor.resolve(ext, resolver); + } + contribution.setUnresolved(false); } } |