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 | |
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')
27 files changed, 692 insertions, 580 deletions
diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java index c9590e5718..e7263770f7 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.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.assembly.xml; @@ -50,7 +50,6 @@ import org.apache.tuscany.sca.assembly.ConfiguredOperation; import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.Extensible; -import org.apache.tuscany.sca.assembly.Extension; import org.apache.tuscany.sca.assembly.ExtensionFactory; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Multiplicity; @@ -65,7 +64,6 @@ 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; -import org.apache.tuscany.sca.contribution.service.ContributionWriteException; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.Problem; @@ -87,8 +85,8 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** - * A base class with utility methods for the other artifact processors in this module. - * + * A base class with utility methods for the other artifact processors in this module. + * * @version $Rev$ $Date$ */ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implements Constants { @@ -134,7 +132,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement } /** - * Constructs a new BaseArtifactProcessor. + * Constructs a new BaseArtifactProcessor. * @param assemblyfactory * @param extensionFactory * @param policyFactory @@ -149,17 +147,17 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement StAXAttributeProcessor extensionAttributeProcessor, Monitor monitor) { this.assemblyFactory = assemblyfactory; - this.extensionFactory = extensionFactory; + this.extensionFactory = extensionFactory; this.policyFactory = policyFactory; this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor; this.extensionAttributeProcessor = extensionAttributeProcessor; this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); this.monitor = monitor; } - + /** * Marshals warnings into the monitor - * + * * @param message * @param model * @param messageParameters @@ -170,10 +168,10 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement monitor.problem(problem); } } - + /** * Marshals errors into the monitor - * + * * @param problems * @param message * @param model @@ -184,10 +182,10 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement monitor.problem(problem); } } - + /** * Marshals exceptions into the monitor - * + * * @param problems * @param message * @param model @@ -270,7 +268,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement reference.setMultiplicity(Multiplicity.ONE_ONE); } } - + protected XAttr writeMultiplicity(AbstractReference reference) { Multiplicity multiplicity = reference.getMultiplicity(); if (multiplicity != null) { @@ -346,55 +344,55 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation; resolveIntents(policiedImpl.getRequiredIntents(), resolver); PolicyValidationUtils.validateIntents(policiedImpl, policiedImpl.getType()); - + resolvePolicySets(policiedImpl.getPolicySets(), resolver); PolicyValidationUtils.validatePolicySets(policiedImpl); - + if ( implementation instanceof OperationsConfigurator ) { OperationsConfigurator opsConfigurator = (OperationsConfigurator)implementation; for ( ConfiguredOperation implOp : opsConfigurator.getConfiguredOperations() ) { resolveIntents(implOp.getRequiredIntents(), resolver); PolicyValidationUtils.validateIntents(implOp, policiedImpl.getType()); - + resolvePolicySets(implOp.getPolicySets(), resolver); - PolicyValidationUtils.validatePolicySets(implOp, + PolicyValidationUtils.validatePolicySets(implOp, policiedImpl.getType(), policiedImpl.getApplicablePolicySets()); } } - + for ( Service service : implementation.getServices() ) { resolveIntents(service.getRequiredIntents(), resolver); resolvePolicySets(service.getPolicySets(), resolver); - + for ( ConfiguredOperation svcOp : service.getConfiguredOperations() ) { resolveIntents(svcOp.getRequiredIntents(), resolver); resolvePolicySets(svcOp.getPolicySets(), resolver); } } - + for ( Reference reference : implementation.getReferences() ) { resolveIntents(reference.getRequiredIntents(), resolver); resolvePolicySets(reference.getPolicySets(), resolver); } } - + resolver.addModel(implementation); } } } - + if ( implementation instanceof IntentAttachPoint && - ((IntentAttachPoint)implementation).getType() != null && + ((IntentAttachPoint)implementation).getType() != null && ((IntentAttachPoint)implementation).getType().isUnresolved() ) { ((IntentAttachPoint)implementation).setType( - resolver.resolveModel(IntentAttachPointType.class, + resolver.resolveModel(IntentAttachPointType.class, ((IntentAttachPoint)implementation).getType())); } } return implementation; } - + /** * Resolve interface, callback interface and bindings on a list of contracts. * @param contracts the list of contracts @@ -405,7 +403,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement resolveContracts(null, contracts, resolver); } - + /** * Resolve interface, callback interface and bindings on a list of contracts. * @param parent element for the contracts @@ -414,10 +412,10 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement */ protected <C extends Contract> void resolveContracts(Base parent, List<C> contracts, ModelResolver resolver) throws ContributionResolveException { - + String parentName = (parent instanceof Composite) ? ((Composite)parent).getName().toString() : (parent instanceof Component) ? ((Component)parent).getName() : "UNKNOWN"; - + for (Contract contract : contracts) { try { //resolve the intents and policysets as they need to be copied over into the @@ -425,46 +423,46 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement resolveIntents(contract.getRequiredIntents(), resolver); resolvePolicySets(contract.getPolicySets(), resolver); resolvePolicySets(contract.getApplicablePolicySets(), resolver); - + // Inherit the composite / component level applicable policy sets. if ( parent != null && parent instanceof PolicySetAttachPoint ) { addInheritedPolicySets(((PolicySetAttachPoint)parent).getApplicablePolicySets(), contract.getApplicablePolicySets()); } - + for ( ConfiguredOperation confOp : contract.getConfiguredOperations() ) { resolveIntents(confOp.getRequiredIntents(), resolver); resolvePolicySets(confOp.getPolicySets(), resolver); resolvePolicySets(confOp.getApplicablePolicySets(), resolver); - + //inherit applicable policy sets from parent contract addInheritedPolicySets(contract.getApplicablePolicySets(), confOp.getApplicablePolicySets()); } - + // Resolve the interface contract InterfaceContract interfaceContract = contract.getInterfaceContract(); if (interfaceContract != null) { extensionProcessor.resolve(interfaceContract, resolver); } - + // Resolve bindings for (int i = 0, n = contract.getBindings().size(); i < n; i++) { Binding binding = contract.getBindings().get(i); extensionProcessor.resolve(binding, resolver); - + if (binding instanceof IntentAttachPoint) { IntentAttachPoint policiedBinding = (IntentAttachPoint)binding; - + if ( policiedBinding.getType() != null && policiedBinding.getType().isUnresolved() ) { - IntentAttachPointType resolved = - resolver.resolveModel(IntentAttachPointType.class, + IntentAttachPointType resolved = + resolver.resolveModel(IntentAttachPointType.class, policiedBinding.getType()); policiedBinding.setType(resolved); } - + resolveIntents(policiedBinding.getRequiredIntents(), resolver); PolicyValidationUtils.validateIntents(policiedBinding, policiedBinding.getType()); } - + if (binding instanceof PolicySetAttachPoint) { PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding; resolvePolicySets(policiedBinding.getPolicySets(), resolver); @@ -475,24 +473,24 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement addInheritedPolicySets(contract.getApplicablePolicySets(), policiedBinding.getApplicablePolicySets()); PolicyValidationUtils.validatePolicySets(policiedBinding); } - + if (binding instanceof OperationsConfigurator) { OperationsConfigurator opConfigurator = (OperationsConfigurator)binding; for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) { resolveIntents(confOp.getRequiredIntents(), resolver); PolicyValidationUtils.validateIntents(confOp, ((PolicySetAttachPoint)binding).getType()); - + resolvePolicySets(confOp.getPolicySets(), resolver); resolvePolicySets(confOp.getApplicablePolicySets(), resolver); //inherit the applicable policysets from parent binding as whatever applies to that //applies to the binding as well - addInheritedPolicySets(((PolicySetAttachPoint)binding).getApplicablePolicySets(), + addInheritedPolicySets(((PolicySetAttachPoint)binding).getApplicablePolicySets(), confOp.getApplicablePolicySets()); PolicyValidationUtils.validatePolicySets(confOp, ((PolicySetAttachPoint)binding).getType()); } } } - + // Resolve callback bindings if (contract.getCallback() != null) { resolveIntents(contract.getCallback().getRequiredIntents(), resolver); @@ -500,25 +498,25 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement resolvePolicySets(contract.getCallback().getApplicablePolicySets(), resolver); //inherit the contract's policy intents and policysets addInheritedPolicySets(contract.getApplicablePolicySets(), contract.getCallback().getApplicablePolicySets()); - + for (int i = 0, n = contract.getCallback().getBindings().size(); i < n; i++) { Binding binding = contract.getCallback().getBindings().get(i); extensionProcessor.resolve(binding, resolver); - + if (binding instanceof IntentAttachPoint) { IntentAttachPoint policiedBinding = (IntentAttachPoint)binding; - + if ( policiedBinding.getType().isUnresolved() ) { - IntentAttachPointType resolved = - resolver.resolveModel(IntentAttachPointType.class, + IntentAttachPointType resolved = + resolver.resolveModel(IntentAttachPointType.class, policiedBinding.getType()); policiedBinding.setType(resolved); } - + resolveIntents(policiedBinding.getRequiredIntents(), resolver); PolicyValidationUtils.validateIntents(policiedBinding, policiedBinding.getType()); } - + if (binding instanceof PolicySetAttachPoint) { PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding; resolvePolicySets(policiedBinding.getPolicySets(), resolver); @@ -529,18 +527,18 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement addInheritedPolicySets(contract.getApplicablePolicySets(), policiedBinding.getApplicablePolicySets()); PolicyValidationUtils.validatePolicySets(policiedBinding); } - + if (binding instanceof OperationsConfigurator) { OperationsConfigurator opConfigurator = (OperationsConfigurator)binding; for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) { resolveIntents(confOp.getRequiredIntents(), resolver); PolicyValidationUtils.validateIntents(confOp, ((PolicySetAttachPoint)binding).getType()); - + resolvePolicySets(confOp.getPolicySets(), resolver); resolvePolicySets(confOp.getApplicablePolicySets(), resolver); //inherit the applicable policysets from parent binding as whatever applies to that //applies to the binding as well - addInheritedPolicySets(((PolicySetAttachPoint)binding).getApplicablePolicySets(), + addInheritedPolicySets(((PolicySetAttachPoint)binding).getApplicablePolicySets(), confOp.getApplicablePolicySets()); PolicyValidationUtils.validatePolicySets(confOp, ((PolicySetAttachPoint)binding).getType()); } @@ -549,7 +547,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement } } catch ( PolicyValidationException e ) { error("PolicyServiceValidationException", contract, contract.getName(), parentName, e.getMessage()); - //throw new ContributionResolveException("PolicyValidation exceptions when processing service/reference '" + //throw new ContributionResolveException("PolicyValidation exceptions when processing service/reference '" //+ contract.getName() + "' in '" + parentName + "'"); } } @@ -593,7 +591,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement * @return * @throws XMLStreamException * @throws ContributionReadException - * @throws ParserConfigurationException + * @throws ParserConfigurationException */ protected Document readPropertyValue(QName element, QName type, XMLStreamReader reader) throws XMLStreamException, ContributionReadException { @@ -692,7 +690,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement * Load a property value specification from an StAX stream into a DOM * Document. Only elements, text and attributes are processed; all comments * and other whitespace are ignored. - * + * * @param reader the stream to read from * @param root the DOM node to load * @throws javax.xml.stream.XMLStreamException @@ -793,7 +791,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement } /** - * Write the value of a property + * Write the value of a property * @param document * @param element * @param type @@ -860,74 +858,42 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement } } } - + protected void addInheritedIntents(List<Intent> sourceList, List<Intent> targetList) { if (sourceList != null) { targetList.addAll(sourceList); } } - + protected void addInheritedPolicySets(List<PolicySet> sourceList, List<PolicySet> targetList) { if (sourceList != null) { targetList.addAll(sourceList); } } - + /** - * + * * @param reader * @param elementName - * @param estensibleElement + * @param extensible * @param extensionAttributeProcessor * @throws ContributionReadException * @throws XMLStreamException */ - protected void readExtendedAttributes(XMLStreamReader reader, Extensible estensibleElement) throws ContributionReadException, XMLStreamException { - QName elementName = reader.getName(); - for (int a = 0; a < reader.getAttributeCount(); a++) { - QName attributeName = reader.getAttributeName(a); - if( attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) { - if( ! elementName.getNamespaceURI().equals(attributeName.getNamespaceURI()) ) { - Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); - Extension attributeExtension; - if (attributeValue instanceof Extension) { - attributeExtension = (Extension) attributeValue; - } else { - attributeExtension = extensionFactory.createExtension(attributeName, attributeValue, true); - } - estensibleElement.getAttributeExtensions().add(attributeExtension); - } - } - } + protected void readExtendedAttributes(XMLStreamReader reader, Extensible extensible) throws ContributionReadException, XMLStreamException { + super.readExtendedAttributes(reader, extensible, extensionAttributeProcessor, extensionFactory); } - - /** - * - * @param attributeModel - * @param writer - * @param extensibleElement - * @param extensionAttributeProcessor - * @throws ContributionWriteException - * @throws XMLStreamException - */ - protected void writeExtendedAttributes(XMLStreamWriter writer, Extensible extensibleElement, StAXAttributeProcessor extensionAttributeProcessor) throws ContributionWriteException, XMLStreamException { - for(Extension extension : extensibleElement.getAttributeExtensions()) { - if(extension.isAttribute()) { - extensionAttributeProcessor.write(extension, writer); - } - } - } - /*protected void validatePolicySets(PolicySetAttachPoint policySetAttachPoint) + /*protected void validatePolicySets(PolicySetAttachPoint policySetAttachPoint) throws ContributionResolveException { validatePolicySets(policySetAttachPoint, policySetAttachPoint.getApplicablePolicySets()); } - - + + protected void validatePolicySets(PolicySetAttachPoint policySetAttachPoint, List<PolicySet> applicablePolicySets) throws ContributionResolveException { - //Since the applicablePolicySets in a policySetAttachPoint will already have the + //Since the applicablePolicySets in a policySetAttachPoint will already have the //list of policysets that might ever be applicable to this attachPoint, just check //if the defined policysets feature in the list of applicable policysets IntentAttachPointType attachPointType = policySetAttachPoint.getType(); @@ -941,8 +907,8 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement } else { throw new ContributionResolveException("Policy Set '" + definedPolicySet.getName() + "' is not defined in this domain "); - - + + } } }*/ diff --git a/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java b/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java index f35f35ac4c..c0bd9465e4 100644 --- a/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java +++ b/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java @@ -6,28 +6,29 @@ * 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.java.impl; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.java.JavaExport; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * Implementation of a Java Import model - * + * * @version $Rev$ $Date$ */ -public class JavaExportImpl implements JavaExport { +public class JavaExportImpl extends ExtensibleImpl implements JavaExport { private ModelResolver modelResolver; /** diff --git a/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java b/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java index cc18d5f798..f2fdb3278e 100644 --- a/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java +++ b/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java @@ -6,21 +6,22 @@ * 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.java.impl; import java.util.List; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.Export; import org.apache.tuscany.sca.contribution.java.JavaExport; @@ -29,10 +30,10 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * Implementation of a Java Import model - * + * * @version $Rev$ $Date$ */ -public class JavaImportImpl implements JavaImport { +public class JavaImportImpl extends ExtensibleImpl implements JavaImport { private ModelResolver modelResolver; private List<Contribution> contributions; /** @@ -43,7 +44,7 @@ public class JavaImportImpl implements JavaImport { * Contribution URI where the artifact is imported from */ private String location; - + public JavaImportImpl() { super(); } @@ -99,10 +100,10 @@ public class JavaImportImpl implements JavaImport { } } } - + return false; } - + @Override public String toString() { return String.valueOf(packageName); diff --git a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java index 8991585d32..99af328964 100644 --- a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java +++ b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java @@ -6,35 +6,36 @@ * 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.namespace.impl; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an export for the contribution - * + * * @version $Rev$ $Date$ */ -public class NamespaceExportImpl implements NamespaceExport { - private String namespace; +public class NamespaceExportImpl extends ExtensibleImpl implements NamespaceExport { + private String namespace; private ModelResolver modelResolver; - + protected NamespaceExportImpl() { super(); } - + public String getNamespace() { return namespace; } @@ -42,13 +43,13 @@ public class NamespaceExportImpl implements NamespaceExport { public void setNamespace(String namespace) { this.namespace = namespace; } - + public ModelResolver getModelResolver() { return modelResolver; } - + public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + } diff --git a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java index a316818b0f..2ed444506c 100644 --- a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java +++ b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.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.namespace.impl; @@ -27,11 +27,14 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import org.apache.tuscany.sca.assembly.ExtensionFactory; import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; import org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory; +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; @@ -42,26 +45,35 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; /** * Artifact processor for Namespace export - * + * * @version $Rev$ $Date$ */ -public class NamespaceExportProcessor implements StAXArtifactProcessor<NamespaceExport> { +public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<NamespaceExport> { private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; private static final QName EXPORT = new QName(SCA10_NS, "export"); private static final String NAMESPACE = "namespace"; - + private final NamespaceImportExportFactory factory; private final Monitor monitor; - - public NamespaceExportProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + private final ExtensionFactory extensionFactory; + private final StAXArtifactProcessor<Object> extensionProcessor; + private final StAXAttributeProcessor<Object> attributeProcessor; + + public NamespaceExportProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor<Object> extensionProcessor, + StAXAttributeProcessor<Object> attributeProcessor, + Monitor monitor) { this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class); + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + this.extensionProcessor = extensionProcessor; + this.attributeProcessor = attributeProcessor; this.monitor = monitor; } - + /** * Report a warning. - * + * * @param problems * @param message * @param model @@ -72,10 +84,10 @@ public class NamespaceExportProcessor implements StAXArtifactProcessor<Namespace monitor.problem(problem); } } - + /** * Report a exception. - * + * * @param problems * @param message * @param model @@ -90,43 +102,47 @@ public class NamespaceExportProcessor implements StAXArtifactProcessor<Namespace public QName getArtifactType() { return EXPORT; } - + public Class<NamespaceExport> getModelType() { return NamespaceExport.class; } - + /** * Process <export namespace=""/> */ public NamespaceExport read(XMLStreamReader reader) throws ContributionReadException { NamespaceExport namespaceExport = this.factory.createNamespaceExport(); QName element = null; - + 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 + } else { namespaceExport.setNamespace(ns); - } - + } + readExtendedAttributes(reader, namespaceExport, attributeProcessor, extensionFactory); + } else { + readExtendedElement(reader, namespaceExport, extensionProcessor); + } + break; case XMLStreamConstants.END_ELEMENT: if (EXPORT.equals(reader.getName())) { return namespaceExport; } - break; + break; } - + // Read the next element if (reader.hasNext()) { reader.next(); @@ -137,24 +153,28 @@ public class NamespaceExportProcessor implements StAXArtifactProcessor<Namespace ContributionReadException ex = new ContributionReadException(e); error("XMLStreamException", reader, ex); } - + return namespaceExport; } public void write(NamespaceExport namespaceExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - + // Write <export> writer.writeStartElement(EXPORT.getNamespaceURI(), EXPORT.getLocalPart()); - + if (namespaceExport.getNamespace() != null) { writer.writeAttribute(NAMESPACE, namespaceExport.getNamespace()); } - + + writeExtendedAttributes(writer, namespaceExport, attributeProcessor); + + writeExtendedElements(writer, namespaceExport, extensionProcessor); + writer.writeEndElement(); } public void resolve(NamespaceExport namespaceExport, ModelResolver resolver) throws ContributionResolveException { - + if (namespaceExport.getNamespace() != null) // Initialize the export's resolver namespaceExport.setModelResolver(new NamespaceExportModelResolver(resolver)); diff --git a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java index 6d2a31f702..35e2d539d4 100644 --- a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java +++ b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java @@ -6,19 +6,20 @@ * 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.namespace.impl; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.Export; import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; @@ -26,26 +27,26 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an import for the contribution - * + * * @version $Rev$ $Date$ */ -public class NamespaceImportImpl implements NamespaceImport { +public class NamespaceImportImpl extends ExtensibleImpl implements NamespaceImport { private ModelResolver modelResolver; /** * The namespace to be imported */ - private String namespace; + private String namespace; /** * Optional location URI pointing to a Contribution that exports the namespace */ private String location; - + protected NamespaceImportImpl() { super(); } - + public String getLocation() { return location; } @@ -61,16 +62,16 @@ public class NamespaceImportImpl implements NamespaceImport { public void setNamespace(String namespace) { this.namespace = namespace; } - + public ModelResolver getModelResolver() { return modelResolver; } - + public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + /** * Match a NamespaceImport to a given NamespaceExport based on : * location is not provided @@ -84,7 +85,7 @@ public class NamespaceImportImpl implements NamespaceImport { } return false; } - + @Override public String toString() { return String.valueOf(namespace); diff --git a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java index a364823256..97fa65b7c2 100644 --- a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java +++ b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.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.namespace.impl; @@ -27,11 +27,14 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import org.apache.tuscany.sca.assembly.ExtensionFactory; import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; import org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory; +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; @@ -42,28 +45,37 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; /** * Artifact processor for Namespace import - * + * * @version $Rev$ $Date$ */ -public class NamespaceImportProcessor implements StAXArtifactProcessor<NamespaceImport> { +public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<NamespaceImport> { private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; - + private static final QName IMPORT = new QName(SCA10_NS, "import"); private static final String NAMESPACE = "namespace"; private static final String LOCATION = "location"; - + private final NamespaceImportExportFactory factory; + private final ExtensionFactory extensionFactory; + private final StAXArtifactProcessor<Object> extensionProcessor; + private final StAXAttributeProcessor<Object> attributeProcessor; private final Monitor monitor; - - public NamespaceImportProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + + public NamespaceImportProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor<Object> extensionProcessor, + StAXAttributeProcessor<Object> attributeProcessor, + Monitor monitor) { this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class); this.monitor = monitor; + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + this.extensionProcessor = extensionProcessor; + this.attributeProcessor = attributeProcessor; } - + /** * Report a warning. - * + * * @param problems * @param message * @param model @@ -74,10 +86,10 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac monitor.problem(problem); } } - + /** * Report a exception. - * + * * @param problems * @param message * @param model @@ -88,11 +100,11 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac monitor.problem(problem); } } - + public QName getArtifactType() { return IMPORT; } - + public Class<NamespaceImport> getModelType() { return NamespaceImport.class; } @@ -103,36 +115,40 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac public NamespaceImport read(XMLStreamReader reader) throws ContributionReadException { NamespaceImport namespaceImport = this.factory.createNamespaceImport(); QName element; - + 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 + } else { namespaceImport.setNamespace(ns); - + } + String location = reader.getAttributeValue(null, LOCATION); if (location != null) { namespaceImport.setLocation(location); } + readExtendedAttributes(reader, namespaceImport, attributeProcessor, extensionFactory); + } else { + readExtendedElement(reader, namespaceImport, extensionProcessor); } break; case XMLStreamConstants.END_ELEMENT: if (IMPORT.equals(reader.getName())) { return namespaceImport; } - break; + break; } - + // Read the next element if (reader.hasNext()) { reader.next(); @@ -143,22 +159,24 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac ContributionReadException ex = new ContributionReadException(e); error("XMLStreamException", reader, ex); } - + return namespaceImport; } public void write(NamespaceImport namespaceImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - + // Write <import> writer.writeStartElement(IMPORT.getNamespaceURI(), IMPORT.getLocalPart()); - + if (namespaceImport.getNamespace() != null) { writer.writeAttribute(NAMESPACE, namespaceImport.getNamespace()); } if (namespaceImport.getLocation() != null) { writer.writeAttribute(LOCATION, namespaceImport.getLocation()); } - + + writeExtendedAttributes(writer, namespaceImport, attributeProcessor); + writeExtendedElements(writer, namespaceImport, extensionProcessor); writer.writeEndElement(); } diff --git a/branches/sca-java-1.x/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java b/branches/sca-java-1.x/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java index 1f508d6a4a..5e213e3729 100644 --- a/branches/sca-java-1.x/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java +++ b/branches/sca-java-1.x/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.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.namespace.impl; @@ -41,17 +41,19 @@ import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl; /** * Test NamespaceExportProcessorTestCase - * + * * @version $Rev$ $Date$ */ public class NamespaceExportProcessorTestCase extends TestCase { private static final String VALID_XML = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" - + "<export xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\" namespace=\"http://foo\"/>"; + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + + "<export xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\"" + + " ns:ext=\"extended\" namespace=\"http://foo\">" + + "<ns:foo/></export>"; private static final String INVALID_XML = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<export xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\"/>"; private XMLInputFactory inputFactory; @@ -64,11 +66,11 @@ public class NamespaceExportProcessorTestCase extends TestCase { inputFactory = XMLInputFactory.newInstance(); // Create a monitor UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); if (monitorFactory != null) { monitor = monitorFactory.createMonitor(); utilities.addUtility(monitorFactory); - } + } StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); } @@ -81,6 +83,8 @@ public class NamespaceExportProcessorTestCase extends TestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); NamespaceExport namespaceExport = (NamespaceExport)staxProcessor.read(reader); assertEquals("http://foo", namespaceExport.getNamespace()); + assertEquals(1, namespaceExport.getAttributeExtensions().size()); + assertEquals(1, namespaceExport.getExtensions().size()); } /** @@ -96,8 +100,8 @@ public class NamespaceExportProcessorTestCase extends TestCase { assertTrue(true); }*/ staxProcessor.read(reader); - Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); + Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); assertNotNull(problem); assertEquals("AttributeNameSpaceMissing", problem.getMessageId()); - } + } } diff --git a/branches/sca-java-1.x/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java b/branches/sca-java-1.x/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java index 71ac33bf68..7e889ec3ea 100644 --- a/branches/sca-java-1.x/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java +++ b/branches/sca-java-1.x/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.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.namespace.impl; @@ -32,7 +32,6 @@ import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.service.ContributionReadException; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.UtilityExtensionPoint; @@ -44,17 +43,19 @@ import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl; /** * Test NamespaceImportProcessorTestCase - * + * * @version $Rev$ $Date$ */ public class NamespaceImportProcessorTestCase extends TestCase { private static final String VALID_XML = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" - + "<import xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\" namespace=\"http://foo\" location=\"sca://contributions/001\"/>"; + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + + "<import xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\"" + + " ns:ext=\"extended\" namespace=\"http://foo\" location=\"sca://contributions/001\">" + + "<ns:foo/></import>"; private static final String INVALID_XML = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<import xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\" location=\"sca://contributions/001\"/>"; private XMLInputFactory inputFactory; @@ -67,7 +68,7 @@ public class NamespaceImportProcessorTestCase extends TestCase { inputFactory = XMLInputFactory.newInstance(); // Create a monitor UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); if (monitorFactory != null) { monitor = monitorFactory.createMonitor(); utilities.addUtility(monitorFactory); @@ -83,9 +84,11 @@ public class NamespaceImportProcessorTestCase extends TestCase { public void testLoad() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); NamespaceImport namespaceImport = (NamespaceImport)staxProcessor.read(reader); - + assertEquals("http://foo", namespaceImport.getNamespace()); assertEquals("sca://contributions/001", namespaceImport.getLocation()); + assertEquals(1, namespaceImport.getAttributeExtensions().size()); + assertEquals(1, namespaceImport.getExtensions().size()); } /** @@ -101,8 +104,8 @@ public class NamespaceImportProcessorTestCase extends TestCase { assertTrue(true); }*/ staxProcessor.read(reader); - Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); + Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); assertNotNull(problem); assertEquals("AttributeNameSpaceMissing", problem.getMessageId()); - } + } } diff --git a/branches/sca-java-1.x/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportImpl.java b/branches/sca-java-1.x/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportImpl.java index c2d525dfef..50ba5bcd6f 100644 --- a/branches/sca-java-1.x/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportImpl.java +++ b/branches/sca-java-1.x/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportImpl.java @@ -6,39 +6,40 @@ * 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.resource.impl; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.contribution.resource.ResourceExport; /** * The representation of an export for the contribution - * + * * @version $Rev$ $Date$ */ -public class ResourceExportImpl implements ResourceExport { +public class ResourceExportImpl extends ExtensibleImpl implements ResourceExport { /** * The resource URI to be exported - */ - private String uri; - + */ + private String uri; + private ModelResolver modelResolver; - + protected ResourceExportImpl() { super(); } - + public String getURI() { return uri; } @@ -46,13 +47,13 @@ public class ResourceExportImpl implements ResourceExport { public void setURI(String uri) { this.uri = uri; } - + public ModelResolver getModelResolver() { return modelResolver; } - + public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + } diff --git a/branches/sca-java-1.x/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportImpl.java b/branches/sca-java-1.x/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportImpl.java index cd33f1290f..6a862a2f04 100644 --- a/branches/sca-java-1.x/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportImpl.java +++ b/branches/sca-java-1.x/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportImpl.java @@ -6,21 +6,22 @@ * 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.resource.impl; import java.util.List; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.Export; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -29,16 +30,16 @@ import org.apache.tuscany.sca.contribution.resource.ResourceImport; /** * The representation of an import for the contribution - * + * * @version $Rev$ $Date$ */ -public class ResourceImportImpl implements ResourceImport { +public class ResourceImportImpl extends ExtensibleImpl implements ResourceImport { /** * The resource URI to be imported */ - private String uri; - - private ModelResolver modelResolver; + private String uri; + + private ModelResolver modelResolver; private List<Contribution> exportContributions; /** @@ -46,11 +47,10 @@ public class ResourceImportImpl implements ResourceImport { */ private String location; - protected ResourceImportImpl() { super(); } - + public String getLocation() { return location; } @@ -66,15 +66,15 @@ public class ResourceImportImpl implements ResourceImport { public void setURI(String uri) { this.uri = uri; } - + public ModelResolver getModelResolver() { return modelResolver; } - + public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + public List<Contribution> getExportContributions() { return exportContributions; } @@ -95,11 +95,11 @@ public class ResourceImportImpl implements ResourceImport { return true; } } - + } return false; } - + @Override public String toString() { return String.valueOf(uri); 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); } } diff --git a/branches/sca-java-1.x/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java b/branches/sca-java-1.x/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java index 8f69f15cd1..cef1f705af 100644 --- a/branches/sca-java-1.x/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java +++ b/branches/sca-java-1.x/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.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; @@ -45,26 +45,27 @@ import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl; /** * Test the contribution metadata processor. - * + * * @version $Rev$ $Date$ */ public class ContributionMetadataProcessorTestCase extends TestCase { private static final String VALID_XML = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" - + "<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\">" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\" ns:bar=\"extended\">" + "<deployable composite=\"ns:Composite1\"/>" + "<deployable composite=\"ns:Composite2\"/>" + + "<ns:bar x=\"1\"/>" + "</contribution>"; private static final String INVALID_XML = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\">" + "<deployable composite=\"ns:Composite1\"/>" + "<deployable/>" + "</contribution>"; - + private XMLInputFactory inputFactory; private XMLOutputFactory outputFactory; private StAXArtifactProcessor<Object> staxProcessor; @@ -73,17 +74,17 @@ public class ContributionMetadataProcessorTestCase extends TestCase { @Override protected void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); - + inputFactory = XMLInputFactory.newInstance(); outputFactory = XMLOutputFactory.newInstance(); - + // Create a monitor UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); if (monitorFactory != null) { monitor = monitorFactory.createMonitor(); utilities.addUtility(monitorFactory); - } + } StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); } @@ -93,6 +94,8 @@ public class ContributionMetadataProcessorTestCase extends TestCase { ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader); assertNotNull(contribution); assertEquals(2, contribution.getDeployables().size()); + assertEquals(1, contribution.getAttributeExtensions().size()); + assertEquals(1, contribution.getExtensions().size()); } public void testReadInvalid() throws Exception { @@ -104,17 +107,17 @@ public class ContributionMetadataProcessorTestCase extends TestCase { assertTrue(true); }*/ staxProcessor.read(reader); - Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); + Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); assertNotNull(problem); assertEquals("AttributeCompositeMissing", problem.getMessageId()); - } + } public void testWrite() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader); validateContribution(contribution); - + //write the contribution metadata contents StringWriter stringWriter = new StringWriter(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(stringWriter); @@ -123,19 +126,19 @@ public class ContributionMetadataProcessorTestCase extends TestCase { reader = inputFactory.createXMLStreamReader(new StringReader(stringWriter.toString())); contribution = (ContributionMetadata)staxProcessor.read(reader); - + validateContribution(contribution); } - + private void validateContribution(ContributionMetadata contribution) { QName deployable; - + assertNotNull(contribution); assertEquals(2, contribution.getDeployables().size()); deployable = new QName("http://ns", "Composite1"); assertEquals(deployable, contribution.getDeployables().get(0).getName()); deployable = new QName("http://ns", "Composite2"); - assertEquals(deployable, contribution.getDeployables().get(1).getName()); + assertEquals(deployable, contribution.getDeployables().get(1).getName()); } - + } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java index 7400501d85..84a6a9a8f9 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.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; @@ -24,63 +24,51 @@ import org.apache.tuscany.sca.assembly.Base; /** * Represents an artifact in an SCA contribution. - * + * * @version $Rev$ $Date$ */ public interface Artifact extends Base { - + /** * Returns the URI that unique identifies the artifact inside the contribution. - * + * * @return The artifact URI */ String getURI(); - + /** * Sets the URI that uniquely identifies the artifact inside the contribution. - * + * * @param uri The artifact URI */ void setURI(String uri); /** * Returns the location of the artifact. - * + * * @return The artifact location */ String getLocation(); - + /** * Set the location of the artifact. - * + * * @param location The artifact location */ void setLocation(String location); - + /** * Returns the in-memory model representing the artifact. - * + * * @return The model object */ Object getModel(); - + /** * Sets the in-memory model representing the artifact. - * + * * @param model The model object */ void setModel(Object model); - - /** - * Returns the contents of the artifact cached here. - * @return the contents of the artifact - */ - byte[] getContents(); - - /** - * Sets the contents of the artifact. - * @param contents the contents of the artifact - */ - void setContents(byte[] contents); } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java index 84a927628d..0076e1c89f 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.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; @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.contribution; import java.util.List; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Extensible; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** @@ -29,48 +30,48 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; * * @version $Rev$ $Date$ */ -public interface Contribution extends Artifact { - +public interface Contribution extends Artifact, Extensible { + /** * Default location of contribution metadata in an SCA contribution. */ String SCA_CONTRIBUTION_META = "META-INF/sca-contribution.xml"; - + /** * Default location of a generated contribution metadata in an SCA contribution. */ String SCA_CONTRIBUTION_GENERATED_META = "META-INF/sca-contribution-generated.xml"; - + /** * Default location of deployable composites in an SCA contribution. */ String SCA_CONTRIBUTION_DEPLOYABLES = "META-INF/sca-deployables/"; - + /** * Returns a list of exports based on the contribution metadata. - * + * * @return The list of exports in this contribution */ List<Export> getExports(); /** * Returns a list of imports based on the contribution metadata. - * + * * @return The list of imports in this contribution */ List<Import> getImports(); - + /** * Returns the list of deployable composites in the contribution. - * + * * @return The list of deployable composites */ List<Composite> getDeployables(); /** * Returns the list of artifacts in the contribution. - * + * * @return The list of artifacts in the contribution */ List<Artifact> getArtifacts(); @@ -78,41 +79,41 @@ public interface Contribution extends Artifact { /** * Returns the model resolver for the models representing the artifacts * visible in the scope of this contribution. - * + * * @return The model resolver */ ModelResolver getModelResolver(); - + /** * Sets the model resolver for the models representing the artifacts * visible in the scope of this contribution. - * + * * @param modelResolver The model resolver */ void setModelResolver(ModelResolver modelResolver); - + /** * Returns the ClassLoader used to load classes and resources from * this contribution - * + * * FIXME Remove this, the base contribution model should not depend - * on Java ClassLoaders. - * + * on Java ClassLoaders. + * * @return The contribution ClassLoader */ ClassLoader getClassLoader(); - + /** * Sets the ClassLoader used to load classes and resources from * this contribution - * + * * FIXME Remove this, the base contribution model should not depend - * on Java ClassLoaders. - * + * on Java ClassLoaders. + * * @param classLoader the contribution class loader */ void setClassLoader(ClassLoader classLoader); - + /** * Returns the type string based on the types that appear in * o.a.t.s.contribution.PackageType diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java index 4043fb9eda..5f26c3d907 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.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; @@ -23,31 +23,32 @@ import java.util.List; import org.apache.tuscany.sca.assembly.Base; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Extensible; /** * The representation of SCA contribution metadata. * * @version $Rev$ $Date$ */ -public interface ContributionMetadata extends Base { - +public interface ContributionMetadata extends Base, Extensible { + /** * Returns a list of exports based on the contribution metadata. - * + * * @return The list of exports */ List<Export> getExports(); /** * Returns a list of imports based on the contribution metadata. - * + * * @return The list of imports */ List<Import> getImports(); - + /** * Returns the list of deployable based on the contribution metadata. - * + * * @return The list of deployable composites */ List<Composite> getDeployables(); diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java index bfa16b1ce3..a6e5afe7b8 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java @@ -6,42 +6,43 @@ * 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; +import org.apache.tuscany.sca.assembly.Extensible; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an export. - * + * * @version $Rev$ $Date$ */ -public interface Export { +public interface Export extends Extensible { /** * Returns the model resolver for the models representing artifacts * made available by this export. - * + * * @return The model resolver */ ModelResolver getModelResolver(); - + /** * Sets the model resolver for the models representing artifacts * made available by this export. - * + * * @param modelResolver */ void setModelResolver(ModelResolver modelResolver); - + } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java index 35076f55a7..256a2387f1 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java @@ -6,33 +6,34 @@ * 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; +import org.apache.tuscany.sca.assembly.Extensible; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an import. - * + * * @version $Rev$ $Date$ */ -public interface Import { +public interface Import extends Extensible { /** * Returns the model resolver for the models representing artifacts * made available by this import. - * + * * @return The model resolver */ ModelResolver getModelResolver(); @@ -40,17 +41,17 @@ public interface Import { /** * Sets the model resolver for the models representing artifacts * made available by this import. - * + * * @param modelResolver The model resolver */ void setModelResolver(ModelResolver modelResolver); - + /** * Verify that a specific export actually exports what is being imported. - * + * * @param export The Exported being verified * @return true/false */ boolean match(Export export); - + }
\ No newline at end of file diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java index 881987f622..3ce27d47c3 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.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.impl; @@ -24,7 +24,7 @@ import org.apache.tuscany.sca.contribution.Artifact; /** * The model representing an artifact in a contribution. - * + * * @version $Rev$ $Date$ */ class ArtifactImpl implements Artifact { @@ -32,11 +32,10 @@ class ArtifactImpl implements Artifact { private String location; private Object model; private boolean unresolved; - private byte[] contents; ArtifactImpl() { } - + public String getLocation() { return location; } @@ -44,35 +43,27 @@ class ArtifactImpl implements Artifact { public void setLocation(String location) { this.location = location; } - + public String getURI() { return uri; } - + public void setURI(String uri) { this.uri = uri; } - + public Object getModel() { return model; } - + public void setModel(Object model) { this.model = model; } - public byte[] getContents() { - return contents; - } - - public void setContents(byte[] contents) { - this.contents = contents; - } - public boolean isUnresolved() { return unresolved; } - + public void setUnresolved(boolean unresolved) { this.unresolved = unresolved; } @@ -81,7 +72,7 @@ class ArtifactImpl implements Artifact { public int hashCode() { return uri.hashCode(); } - + @Override public boolean equals(Object obj) { if (obj == this) { diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java index dcdbda8ce7..3bad5c3612 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.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.impl; @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.Export; @@ -34,7 +35,7 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; * * @version $Rev$ $Date$ */ -class ContributionImpl implements Contribution { +class ContributionImpl extends ExtensibleImpl implements Contribution { private String type; private String uri; private String location; @@ -46,13 +47,13 @@ class ContributionImpl implements Contribution { private List<Composite> deployables = new ArrayList<Composite>(); private List<Artifact> artifacts = new ArrayList<Artifact>(); private ModelResolver modelResolver; - + // FIXME remove this dependency on Java ClassLoaders private ClassLoader classLoader; ContributionImpl() { } - + public String getLocation() { return this.location; } @@ -65,17 +66,17 @@ class ContributionImpl implements Contribution { public ClassLoader getClassLoader() { return classLoader; } - + //FIXME Remove dependency on Java ClassLoaders public void setClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } - - + + public String getURI() { return this.uri; } - + public void setURI(String uri) { this.uri = uri; } @@ -83,27 +84,27 @@ class ContributionImpl implements Contribution { public Object getModel() { return model; } - + public void setModel(Object model) { this.model = model; } - + public byte[] getContents() { return contents; } - + public void setContents(byte[] contents) { this.contents = contents; } - + public boolean isUnresolved() { return unresolved; } - + public void setUnresolved(boolean unresolved) { this.unresolved = unresolved; } - + public ModelResolver getModelResolver() { return modelResolver; } @@ -111,7 +112,7 @@ class ContributionImpl implements Contribution { public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + public List<Export> getExports() { return exports; } @@ -132,7 +133,7 @@ class ContributionImpl implements Contribution { public int hashCode() { return uri.hashCode(); } - + @Override public boolean equals(Object obj) { if (obj == this) { diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java index 75b12b1260..da8c879a93 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.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.impl; @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.ContributionMetadata; import org.apache.tuscany.sca.contribution.Export; import org.apache.tuscany.sca.contribution.Import; @@ -32,7 +33,7 @@ import org.apache.tuscany.sca.contribution.Import; * * @version $Rev$ $Date$ */ -class ContributionMetadataImpl implements ContributionMetadata { +class ContributionMetadataImpl extends ExtensibleImpl implements ContributionMetadata { private boolean unresolved; private List<Export> exports = new ArrayList<Export>(); private List<Import> imports = new ArrayList<Import>(); @@ -40,15 +41,15 @@ class ContributionMetadataImpl implements ContributionMetadata { ContributionMetadataImpl() { } - + public boolean isUnresolved() { return unresolved; } - + public void setUnresolved(boolean unresolved) { this.unresolved = unresolved; } - + public List<Export> getExports() { return exports; } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java index e67395337a..d4614e5427 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java @@ -6,40 +6,41 @@ * 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.impl; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.DefaultExport; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an export for the contribution - * + * * @version $Rev$ $Date$ */ -public class DefaultExportImpl implements DefaultExport { +public class DefaultExportImpl extends ExtensibleImpl implements DefaultExport { private ModelResolver modelResolver; - + protected DefaultExportImpl() { super(); } - + public ModelResolver getModelResolver() { return modelResolver; } - + public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java index 17c09f2cbc..7ab535f916 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java @@ -6,19 +6,20 @@ * 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.impl; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.DefaultExport; import org.apache.tuscany.sca.contribution.DefaultImport; import org.apache.tuscany.sca.contribution.Export; @@ -26,30 +27,30 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an import for the contribution - * + * * @version $Rev$ $Date$ */ -public class DefaultImportImpl implements DefaultImport { +public class DefaultImportImpl extends ExtensibleImpl implements DefaultImport { private ModelResolver modelResolver; protected DefaultImportImpl() { super(); } - + public ModelResolver getModelResolver() { return modelResolver; } - + public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + public boolean match(Export export) { if (export instanceof DefaultExport) { return true; } return false; } - + } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java index f23797a831..84ac93313d 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.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.processor; @@ -35,16 +35,22 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + /** - * A base class with utility methods for the other artifact processors in this module. - * + * A base class with utility methods for the other artifact processors in this module. + * * @version $Rev$ $Date$ */ public abstract class BaseStAXArtifactProcessor { /** - * Returns a QName from a string. + * Returns a QName from a string. * @param reader * @param value * @return @@ -178,9 +184,9 @@ public abstract class BaseStAXArtifactProcessor { } } } - + /** - * + * * @param writer * @param uri * @throws XMLStreamException @@ -193,8 +199,8 @@ public abstract class BaseStAXArtifactProcessor { if (prefix != null) { return null; } else { - - // Find an available prefix and bind it to the given URI + + // Find an available prefix and bind it to the given URI NamespaceContext nsc = writer.getNamespaceContext(); for (int i=1; ; i++) { prefix = "ns" + i; @@ -205,7 +211,7 @@ public abstract class BaseStAXArtifactProcessor { writer.setPrefix(prefix, uri); return prefix; } - + } /** @@ -219,12 +225,12 @@ public abstract class BaseStAXArtifactProcessor { String prefix = writeElementPrefix(writer, uri); writer.writeStartElement(uri, name); if (prefix != null){ - writer.writeNamespace(prefix,uri); + writer.writeNamespace(prefix,uri); } writeAttributePrefixes(writer, attrs); writeAttributes(writer, attrs); } - + /** * Start an element. * @param qname @@ -234,9 +240,9 @@ public abstract class BaseStAXArtifactProcessor { protected void writeStart(XMLStreamWriter writer, QName qname, XAttr... attrs) throws XMLStreamException { writeStart(writer, qname.getNamespaceURI(), qname.getLocalPart(), attrs); } - + /** - * End an element. + * End an element. * @param writer * @throws XMLStreamException */ @@ -303,10 +309,83 @@ public abstract class BaseStAXArtifactProcessor { } /** + * + * @param reader + * @param elementName + * @param extensible + * @param extensionAttributeProcessor + * @param extensionAttributeProcessor + * @param extensionFactory + * @throws ContributionReadException + * @throws XMLStreamException + */ + protected void readExtendedAttributes(XMLStreamReader reader, + Extensible extensible, + StAXAttributeProcessor extensionAttributeProcessor, + ExtensionFactory extensionFactory) throws ContributionReadException, + XMLStreamException { + QName elementName = reader.getName(); + for (int a = 0; a < reader.getAttributeCount(); a++) { + QName attributeName = reader.getAttributeName(a); + if (attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) { + if (!elementName.getNamespaceURI().equals(attributeName.getNamespaceURI())) { + Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); + Extension attributeExtension; + if (attributeValue instanceof Extension) { + attributeExtension = (Extension)attributeValue; + } else { + attributeExtension = extensionFactory.createExtension(attributeName, attributeValue, true); + } + extensible.getAttributeExtensions().add(attributeExtension); + } + } + } + } + + /** + * + * @param attributeModel + * @param writer + * @param extensibleElement + * @param extensionAttributeProcessor + * @throws ContributionWriteException + * @throws XMLStreamException + */ + protected void writeExtendedAttributes(XMLStreamWriter writer, + Extensible extensibleElement, + StAXAttributeProcessor extensionAttributeProcessor) + throws ContributionWriteException, XMLStreamException { + for (Extension extension : extensibleElement.getAttributeExtensions()) { + if (extension.isAttribute()) { + extensionAttributeProcessor.write(extension, writer); + } + } + } + + protected void readExtendedElement(XMLStreamReader reader, + Extensible extensible, + StAXArtifactProcessor extensionProcessor) throws ContributionReadException, + XMLStreamException { + Object ext = extensionProcessor.read(reader); + if (extensible != null) { + extensible.getExtensions().add(ext); + } + } + + protected void writeExtendedElements(XMLStreamWriter writer, + Extensible extensible, + StAXArtifactProcessor extensionProcessor) throws ContributionWriteException, + XMLStreamException { + for (Object ext : extensible.getExtensions()) { + extensionProcessor.write(ext, writer); + } + } + + /** * Represents an XML attribute that needs to be written to a document. */ public static class XAttr { - + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; private String uri = SCA10_NS; @@ -374,7 +453,7 @@ public abstract class BaseStAXArtifactProcessor { } /** - * Writes a string from a QName and registers a prefix for its namespace. + * Writes a string from a QName and registers a prefix for its namespace. * @param reader * @param value * @return @@ -390,14 +469,14 @@ public abstract class BaseStAXArtifactProcessor { if (prefix.length() > 0) { return prefix + ":" + qname.getLocalPart(); } else { - + // Empty prefix, just return the local part of the given qname return qname.getLocalPart(); } - + } else { - - // Find an available prefix and bind it to the given URI + + // Find an available prefix and bind it to the given URI NamespaceContext nsc = writer.getNamespaceContext(); for (int i=1; ; i++) { prefix = "ns" + i; @@ -415,7 +494,7 @@ public abstract class BaseStAXArtifactProcessor { } /** - * Registers a prefix for the namespace of a QName. + * Registers a prefix for the namespace of a QName. * @param reader * @param value * @return @@ -428,8 +507,8 @@ public abstract class BaseStAXArtifactProcessor { if (prefix != null) { return; } else { - - // Find an available prefix and bind it to the given URI + + // Find an available prefix and bind it to the given URI NamespaceContext nsc = writer.getNamespaceContext(); for (int i=1; ; i++) { prefix = "ns" + i; @@ -451,12 +530,12 @@ public abstract class BaseStAXArtifactProcessor { public void write(XMLStreamWriter writer) throws XMLStreamException { String str; if (value instanceof QName) { - + // Write a QName str = writeQNameValue(writer, (QName)value); - + } else if (value instanceof List) { - + // Write a list of values List<?> values = (List<?>)value; if (values.isEmpty()) { @@ -468,7 +547,7 @@ public abstract class BaseStAXArtifactProcessor { // Skip null values continue; } - + if (v instanceof XAttr) { // Write an XAttr value ((XAttr)v).write(writer); @@ -482,14 +561,14 @@ public abstract class BaseStAXArtifactProcessor { // Write a QName value buffer.append(writeQNameValue(writer, (QName)v)); } else { - // Write value as a string + // Write value as a string buffer.append(String.valueOf(v)); } } str = buffer.toString(); - + } else { - + // Write a string if (value == null) { return; @@ -509,24 +588,24 @@ public abstract class BaseStAXArtifactProcessor { } /** - * Registers a prefix for the namespace of a QName or list of QNames + * Registers a prefix for the namespace of a QName or list of QNames * @param writer * @throws XMLStreamException */ public void writePrefix(XMLStreamWriter writer) throws XMLStreamException { if (value instanceof QName) { - + // Write prefix for a single QName value writeQNamePrefix(writer, (QName)value); - + } else if (value instanceof List) { - + // Write prefixes for a list of values for (Object v: (List<?>)value) { if (v instanceof QName) { // Write prefix for a QName value writeQNamePrefix(writer, (QName)v); - + } else if (v instanceof XAttr) { // Write prefix for an XAttr value ((XAttr)v).writePrefix(writer); @@ -535,5 +614,5 @@ public abstract class BaseStAXArtifactProcessor { } } } - + } diff --git a/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java b/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java index e3f0844e35..f81b386420 100644 --- a/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java +++ b/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.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.workspace.processor.impl; @@ -59,7 +59,7 @@ import org.apache.tuscany.sca.workspace.scanner.impl.JarContributionScanner; /** * URLArtifactProcessor that handles contribution files and the artifacts they contain * and returns a contribution model. - * + * * @version $Rev$ $Date$ */ public class ContributionContentProcessor implements URLArtifactProcessor<Contribution>{ @@ -80,7 +80,7 @@ public class ContributionContentProcessor implements URLArtifactProcessor<Contri this.monitor = monitor; URLArtifactProcessorExtensionPoint artifactProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); this.artifactProcessor = new ExtensibleURLArtifactProcessor(artifactProcessors, this.monitor); - + // Get and initialize artifact processors StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); @@ -88,7 +88,7 @@ public class ContributionContentProcessor implements URLArtifactProcessor<Contri this.extensionProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor); this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); } - + /* public ContributionContentProcessor(ModelFactoryExtensionPoint modelFactories, ModelResolverExtensionPoint modelResolvers, URLArtifactProcessor<Object> artifactProcessor, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) { @@ -101,17 +101,17 @@ public class ContributionContentProcessor implements URLArtifactProcessor<Contri this.monitor = monitor; } */ - + public String getArtifactType() { return ".contribution/content"; } - + public Class<Contribution> getModelType() { return Contribution.class; } - + public Contribution read(URL parentURL, URI contributionURI, URL contributionURL) throws ContributionReadException { - + // Create contribution model Contribution contribution = contributionFactory.createContribution(); contribution.setURI(contributionURI.toString()); @@ -127,7 +127,7 @@ public class ContributionContentProcessor implements URLArtifactProcessor<Contri } else { scanner = new JarContributionScanner(); } - + // Scan the contribution and list the artifacts contained in it List<Artifact> artifacts = contribution.getArtifacts(); boolean contributionMetadata = false; @@ -141,7 +141,7 @@ public class ContributionContentProcessor implements URLArtifactProcessor<Contri artifact.setLocation(artifactURL.toString()); artifacts.add(artifact); modelResolver.addModel(artifact); - + // Read each artifact Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL); if (model != null) { @@ -157,10 +157,12 @@ public class ContributionContentProcessor implements URLArtifactProcessor<Contri contribution.getImports().addAll(c.getImports()); contribution.getExports().addAll(c.getExports()); contribution.getDeployables().addAll(c.getDeployables()); + contribution.getExtensions().addAll(c.getExtensions()); + contribution.getAttributeExtensions().addAll(c.getAttributeExtensions()); } } } - + // If no sca-contribution.xml file was provided then just consider // all composites in the contribution as deployables if (!contributionMetadata) { @@ -177,24 +179,24 @@ public class ContributionContentProcessor implements URLArtifactProcessor<Contri DefaultExport defaultExport = contributionFactory.createDefaultExport(); contribution.getExports().add(defaultExport); } - + return contribution; } - + public void resolve(Contribution contribution, ModelResolver resolver) throws ContributionResolveException { - + // Resolve the contribution model itself ModelResolver contributionResolver = contribution.getModelResolver(); contribution.setUnresolved(false); contributionResolver.addModel(contribution); - + // Resolve imports and exports for (Export export: contribution.getExports()) { if (export instanceof DefaultExport) { - + // Initialize the default export's resolver export.setModelResolver(contributionResolver); - + } else { extensionProcessor.resolve(export, contributionResolver); } @@ -202,7 +204,7 @@ public class ContributionContentProcessor implements URLArtifactProcessor<Contri for (Import import_: contribution.getImports()) { extensionProcessor.resolve(import_, contributionResolver); } - + // Resolve all artifact models for (Artifact artifact : contribution.getArtifacts()) { Object model = artifact.getModel(); @@ -216,7 +218,7 @@ public class ContributionContentProcessor implements URLArtifactProcessor<Contri } } } - + // Resolve deployable composites List<Composite> deployables = contribution.getDeployables(); for (int i = 0, n = deployables.size(); i < n; i++) { @@ -230,7 +232,7 @@ public class ContributionContentProcessor implements URLArtifactProcessor<Contri /** * FIXME Temporary hack for testing the ClassLoaderModelResolver. - * + * * @param modelResolvers */ private static void hackResolvers(ModelResolverExtensionPoint modelResolvers) { diff --git a/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionInfoProcessor.java b/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionInfoProcessor.java index 40e377604c..d7a05ff532 100644 --- a/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionInfoProcessor.java +++ b/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionInfoProcessor.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.workspace.processor.impl; @@ -60,7 +60,7 @@ import org.apache.tuscany.sca.workspace.scanner.impl.JarContributionScanner; /** * URLArtifactProcessor that handles contribution files and returns a contribution * info model. - * + * * @version $Rev$ $Date$ */ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribution>{ @@ -87,7 +87,7 @@ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribut this.extensionProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor); this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); } - + /* public ContributionInfoProcessor(ModelFactoryExtensionPoint modelFactories, ModelResolverExtensionPoint modelResolvers, URLArtifactProcessor<Object> artifactProcessor) { this.modelFactories = modelFactories; @@ -97,17 +97,17 @@ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribut this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); } */ - + public String getArtifactType() { return ".contribution/info"; } - + public Class<Contribution> getModelType() { return null; } - + public Contribution read(URL parentURL, URI contributionURI, URL contributionURL) throws ContributionReadException { - + // Create contribution model Contribution contribution = contributionFactory.createContribution(); contribution.setURI(contributionURI.toString()); @@ -123,7 +123,7 @@ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribut } else { scanner = new JarContributionScanner(); } - + // Read generated and user sca-contribution.xml files boolean contributionMetadata = false; for (String path: new String[]{ @@ -140,14 +140,16 @@ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribut continue; } contributionMetadata = true; - + // Read the sca-contribution.xml file ContributionMetadata c = (ContributionMetadata)artifactProcessor.read(contributionURL, URI.create(path), url); contribution.getImports().addAll(c.getImports()); contribution.getExports().addAll(c.getExports()); contribution.getDeployables().addAll(c.getDeployables()); + contribution.getExtensions().addAll(c.getExtensions()); + contribution.getAttributeExtensions().addAll(c.getAttributeExtensions()); } - + // If no sca-contribution.xml file was provided then consider // all composites in the contribution as deployables, and also // read any files that are explicitly asssigned artifact processors @@ -173,10 +175,10 @@ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribut } if (read) { URL artifactURL = scanner.getArtifactURL(contributionURL, artifactURI); - + // Read each artifact Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL); - + // In the absence of more info, consider all composites as deployable if (model instanceof Composite) { contribution.getDeployables().add((Composite)model); @@ -184,7 +186,7 @@ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribut } } } - + // Add default contribution import and export DefaultImport defaultImport = contributionFactory.createDefaultImport(); defaultImport.setModelResolver(new DefaultModelResolver()); @@ -192,24 +194,24 @@ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribut DefaultExport defaultExport = contributionFactory.createDefaultExport(); contribution.getExports().add(defaultExport); } - + return contribution; } - + public void resolve(Contribution contribution, ModelResolver resolver) throws ContributionResolveException { - + // Mark the contribution model resolved ModelResolver contributionResolver = contribution.getModelResolver(); contribution.setUnresolved(false); contributionResolver.addModel(contribution); - + // Resolve imports and exports for (Export export: contribution.getExports()) { if (export instanceof DefaultExport) { - + // Initialize the default export's resolver export.setModelResolver(contributionResolver); - + } else { extensionProcessor.resolve(export, contributionResolver); } @@ -217,12 +219,12 @@ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribut for (Import import_: contribution.getImports()) { extensionProcessor.resolve(import_, contributionResolver); } - + } /** * FIXME Temporary hack for testing the ClassLoaderModelResolver. - * + * * @param modelResolvers */ private static void hackResolvers(ModelResolverExtensionPoint modelResolvers) { diff --git a/branches/sca-java-1.x/modules/workspace/src/main/java/org/apache/tuscany/sca/workspace/impl/WorkspaceImpl.java b/branches/sca-java-1.x/modules/workspace/src/main/java/org/apache/tuscany/sca/workspace/impl/WorkspaceImpl.java index 97fd796f9d..9e242613eb 100644 --- a/branches/sca-java-1.x/modules/workspace/src/main/java/org/apache/tuscany/sca/workspace/impl/WorkspaceImpl.java +++ b/branches/sca-java-1.x/modules/workspace/src/main/java/org/apache/tuscany/sca/workspace/impl/WorkspaceImpl.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.workspace.impl; @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.Export; @@ -35,7 +36,7 @@ import org.apache.tuscany.sca.workspace.Workspace; * * @version $Rev$ $Date$ */ -class WorkspaceImpl implements Workspace { +class WorkspaceImpl extends ExtensibleImpl implements Workspace { private List<Contribution> contributions = new ArrayList<Contribution>(); private String location; @@ -43,14 +44,14 @@ class WorkspaceImpl implements Workspace { private Object model; private byte[] contents; private boolean unresolved; - private ModelResolver modelResolver; - + private ModelResolver modelResolver; + /** - * Constructs a new workspace. + * Constructs a new workspace. */ WorkspaceImpl() { } - + public String getLocation() { return location; } @@ -74,11 +75,11 @@ class WorkspaceImpl implements Workspace { public byte[] getContents() { return contents; } - + public void setContents(byte[] contents) { this.contents = contents; } - + public void setURI(String uri) { this.uri = uri; } @@ -94,7 +95,7 @@ class WorkspaceImpl implements Workspace { public List<Contribution> getContributions() { return contributions; } - + public List<Artifact> getArtifacts() { return (List<Artifact>)(Object)contributions; } @@ -103,11 +104,11 @@ class WorkspaceImpl implements Workspace { //FIXME Remove later return null; } - + public void setClassLoader(ClassLoader classLoader) { //FIXME Remove later } - + public List<Composite> getDeployables() { List<Composite> deployables = new ArrayList<Composite>(); for (Contribution contribution: contributions) { @@ -115,7 +116,7 @@ class WorkspaceImpl implements Workspace { } return deployables; } - + public List<Export> getExports() { List<Export> exports = new ArrayList<Export>(); for (Contribution contribution: contributions) { @@ -123,7 +124,7 @@ class WorkspaceImpl implements Workspace { } return exports; } - + public List<Import> getImports() { List<Import> imports = new ArrayList<Import>(); for (Contribution contribution: contributions) { @@ -131,11 +132,11 @@ class WorkspaceImpl implements Workspace { } return imports; } - + public ModelResolver getModelResolver() { return modelResolver; } - + public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } |