diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-17 01:27:23 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-17 01:27:23 +0000 |
commit | 558e63a849e90059c16a8834f87b8c39b629b237 (patch) | |
tree | 6642696ecdd62d78e4e66b9dd2c10ce972ef54af /branches/sca-java-1.x/modules | |
parent | cbb14b9965208792bdba2f313bc57951c90c1a12 (diff) |
TUSCANY-2463 - Storing extended attributes in a second list, wrapped into a extension class that stores the attribute QName, it's value
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@735197 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules')
25 files changed, 637 insertions, 343 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 80c5e807fe..ac9f4c6006 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 @@ -50,6 +50,8 @@ 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; import org.apache.tuscany.sca.assembly.OperationsConfigurator; @@ -93,6 +95,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement protected ContributionFactory contributionFactory; protected AssemblyFactory assemblyFactory; + protected ExtensionFactory extensionFactory; protected PolicyFactory policyFactory; protected StAXArtifactProcessor<Object> extensionProcessor; protected PolicyAttachPointProcessor policyProcessor; @@ -100,44 +103,53 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement protected IntentAttachPointTypeFactory intentAttachPointTypeFactory; private Monitor monitor; + /** * Constructs a new BaseArtifactProcessor. * @param contribFactory - * @param factory + * @param assemblyFactory + * @param extensionFactory * @param policyFactory + * @param extensionProcessor + * @param monitor */ @SuppressWarnings("unchecked") public BaseAssemblyProcessor(ContributionFactory contribFactory, - AssemblyFactory factory, + AssemblyFactory assemblyFactory, + ExtensionFactory extensionFactory, PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor, Monitor monitor) { - this.assemblyFactory = factory; + this.contributionFactory = contribFactory; + this.assemblyFactory = assemblyFactory; + this.extensionFactory = extensionFactory; this.policyFactory = policyFactory; this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor; - this.contributionFactory = contribFactory; this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); this.intentAttachPointTypeFactory = new IntentAttachPointTypeFactoryImpl(); this.monitor = monitor; } /** - * Constructs a new BaseArtifactProcessor. - * @param factory + * Constructs a new BaseArtifactProcessor. + * @param assemblyfactory + * @param extensionFactory * @param policyFactory + * @param extensionProcessor + * @param monitor */ @SuppressWarnings("unchecked") - public BaseAssemblyProcessor(AssemblyFactory factory, + public BaseAssemblyProcessor(AssemblyFactory assemblyfactory, + ExtensionFactory extensionFactory, PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor, Monitor monitor) { - this.assemblyFactory = factory; + this.assemblyFactory = assemblyfactory; + this.extensionFactory = extensionFactory; this.policyFactory = policyFactory; this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor; this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); this.monitor = monitor; - - //TODO - this constructor should take a monitor too. } /** @@ -866,15 +878,16 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement * @throws XMLStreamException */ protected void readExtendedAttributes(XMLStreamReader reader, QName elementName, Extensible estensibleElement, StAXAttributeProcessor extensionAttributeProcessor) throws ContributionReadException, XMLStreamException { - 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()) ) { - String attributeExtension = (String) extensionAttributeProcessor.read(attributeName, reader); - estensibleElement.getExtensions().add(attributeExtension); - } - } - } + 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()) ) { + String attributeValue = (String) extensionAttributeProcessor.read(attributeName, reader); + Extension attributeExtension = extensionFactory.createExtension(attributeName, attributeValue, true); + estensibleElement.getAttributeExtensions().add(attributeExtension); + } + } + } } @@ -888,14 +901,13 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement * @throws XMLStreamException */ protected void writeExtendedAttributes(XMLStreamWriter writer, Extensible extensibleElement, StAXAttributeProcessor extensionAttributeProcessor) throws ContributionWriteException, XMLStreamException { - for(Object o : extensibleElement.getExtensions()) { - //FIXME How to identify it's a extended attribute ? - if(o instanceof String) { - extensionAttributeProcessor.write(o, writer); - } + for(Extension extension : extensibleElement.getAttributeExtensions()) { + if(extension.isAttribute()) { + extensionAttributeProcessor.write(extension.getValue(), writer); + } } } - + /*protected void validatePolicySets(PolicySetAttachPoint policySetAttachPoint) throws ContributionResolveException { validatePolicySets(policySetAttachPoint, policySetAttachPoint.getApplicablePolicySets()); diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java index b07c91d1b3..ec355e069e 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java @@ -56,7 +56,7 @@ public class ComponentTypeDocumentProcessor extends BaseAssemblyProcessor implem public ComponentTypeDocumentProcessor(StAXArtifactProcessor staxProcessor, XMLInputFactory inputFactory, Monitor monitor) { - super(null, null, staxProcessor, monitor); + super(null, null, null, staxProcessor, monitor); this.inputFactory = inputFactory; } @@ -68,7 +68,7 @@ public class ComponentTypeDocumentProcessor extends BaseAssemblyProcessor implem public ComponentTypeDocumentProcessor(ModelFactoryExtensionPoint modelFactories, StAXArtifactProcessor staxProcessor, Monitor monitor) { - super(null, null, staxProcessor, monitor); + super(null, null, null, staxProcessor, monitor); this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); } diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java index 07e1507449..f1608386ba 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java @@ -33,6 +33,7 @@ import org.apache.tuscany.sca.assembly.Callback; import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.ExtensionFactory; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; @@ -61,13 +62,15 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA /** * Constructs a new componentType processor. - * @param factory + * @param assemblyFactory * @param policyFactory * @param registry */ - public ComponentTypeProcessor(AssemblyFactory factory, PolicyFactory policyFactory, + public ComponentTypeProcessor(AssemblyFactory assemblyFactory, + ExtensionFactory extensionFactory, + PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor, StAXAttributeProcessor extensionAttributeProcessor, Monitor monitor) { - super(factory, policyFactory, extensionProcessor, monitor); + super(assemblyFactory, extensionFactory, policyFactory, extensionProcessor, monitor); } /** @@ -81,7 +84,10 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA StAXAttributeProcessor extensionAttributeProcessor, Monitor monitor) { super(modelFactories.getFactory(AssemblyFactory.class), - modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor); + modelFactories.getFactory(ExtensionFactory.class), + modelFactories.getFactory(PolicyFactory.class), + extensionProcessor, + monitor); } public ComponentType read(XMLStreamReader reader) throws ContributionReadException { diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java index bc74773d85..f630f22548 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java @@ -63,43 +63,52 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements /** * Construct a new composite processor - * @param assemblyFactory - * @param policyFactory * @param staxProcessor + * @param inputFactory + * @param scaDefnsSink + * @param monitor */ @Deprecated public CompositeDocumentProcessor(StAXArtifactProcessor staxProcessor, - XMLInputFactory inputFactory, - List scaDefnsSink, Monitor monitor) { - super(null, null, staxProcessor, monitor); + XMLInputFactory inputFactory, + List scaDefnsSink, + Monitor monitor) { + super(null, null, null, staxProcessor, monitor); this.inputFactory = inputFactory; this.scaDefnSink = scaDefnsSink; } + /** * Construct a new composite processor - * @param assemblyFactory - * @param policyFactory * @param staxProcessor + * @param inputFactory + * @param documentBuilderFactory + * @param scaDefnsSink + * @param monitor */ public CompositeDocumentProcessor(StAXArtifactProcessor staxProcessor, - XMLInputFactory inputFactory, - DocumentBuilderFactory documentBuilderFactory, - List scaDefnsSink, Monitor monitor) { - super(null, null, staxProcessor, monitor); + XMLInputFactory inputFactory, + DocumentBuilderFactory documentBuilderFactory, + List scaDefnsSink, + Monitor monitor) { + super(null, null, null, staxProcessor, monitor); this.documentBuilderFactory = documentBuilderFactory; this.inputFactory = inputFactory; this.scaDefnSink = scaDefnsSink; } + /** - * Constructs a new composite processor. + * Construct a new composite processor * @param modelFactories * @param staxProcessor + * @param monitor */ public CompositeDocumentProcessor(ModelFactoryExtensionPoint modelFactories, - StAXArtifactProcessor staxProcessor, Monitor monitor) { - super(null, null, staxProcessor, monitor); + StAXArtifactProcessor staxProcessor, + Monitor monitor) { + super(null, null, null, staxProcessor, monitor); this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); this.documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); } diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java index 285bcc448d..4df51ff11b 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java @@ -49,6 +49,7 @@ import org.apache.tuscany.sca.assembly.CompositeService; 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.ExtensionFactory; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.OperationsConfigurator; import org.apache.tuscany.sca.assembly.Property; @@ -102,10 +103,10 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt StAXAttributeProcessor extensionAttributeProcessor, Monitor monitor) { - this(modelFactories(extensionPoints), - extensionProcessor, - extensionAttributeProcessor, - monitor(extensionPoints)); + this(modelFactories(extensionPoints), + extensionProcessor, + extensionAttributeProcessor, + monitor(extensionPoints)); this.extensionAttributeProcessor = extensionAttributeProcessor; } @@ -124,6 +125,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt super(modelFactories.getFactory(ContributionFactory.class), modelFactories.getFactory(AssemblyFactory.class), + modelFactories.getFactory(ExtensionFactory.class), modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor); @@ -142,11 +144,12 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt */ public CompositeProcessor(ContributionFactory contributionFactory, AssemblyFactory assemblyFactory, + ExtensionFactory extensionFactory, PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor, StAXAttributeProcessor extensionAttributeProcessor, Monitor monitor) { - super(contributionFactory, assemblyFactory, policyFactory, extensionProcessor, monitor); + super(contributionFactory, assemblyFactory, extensionFactory, policyFactory, extensionProcessor, monitor); } public Composite read(XMLStreamReader reader) throws ContributionReadException { diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java index 4c5d6f8f49..0e6d8be1db 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java @@ -47,28 +47,32 @@ import org.apache.tuscany.sca.monitor.Monitor; public class ConstrainingTypeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor<ConstrainingType> { private XMLInputFactory inputFactory; + /** * Construct a new constrainingType processor. - * @param factory - * @param policyFactory + * * @param staxProcessor + * @param inputFactory + * @param monitor */ public ConstrainingTypeDocumentProcessor(StAXArtifactProcessor staxProcessor, - XMLInputFactory inputFactory, - Monitor monitor) { - super(null, null, staxProcessor, monitor); + XMLInputFactory inputFactory, + Monitor monitor) { + super(null, null, null, staxProcessor, monitor); this.inputFactory = inputFactory; } + /** * Constructs a new constrainingType processor. * @param modelFactories * @param staxProcessor + * @param monitor */ public ConstrainingTypeDocumentProcessor(ModelFactoryExtensionPoint modelFactories, - StAXArtifactProcessor staxProcessor, - Monitor monitor) { - super(null, null, staxProcessor, monitor); + StAXArtifactProcessor staxProcessor, + Monitor monitor) { + super(null, null, null, staxProcessor, monitor); this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); } diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java index 7b0751437a..730c320265 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java @@ -33,6 +33,7 @@ import org.apache.tuscany.sca.assembly.AbstractReference; import org.apache.tuscany.sca.assembly.AbstractService; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.ExtensionFactory; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -55,13 +56,16 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements /** * Construct a new constrainingType processor. - * @param factory + * @param assemblyFactory * @param policyFactory * @param extensionProcessor */ - public ConstrainingTypeProcessor(AssemblyFactory factory, PolicyFactory policyFactory, - StAXArtifactProcessor extensionProcessor, Monitor monitor) { - super(factory, policyFactory, extensionProcessor, monitor); + public ConstrainingTypeProcessor(AssemblyFactory assemblyFactory, + ExtensionFactory extensionFactory, + PolicyFactory policyFactory, + StAXArtifactProcessor extensionProcessor, + Monitor monitor) { + super(assemblyFactory, extensionFactory, policyFactory, extensionProcessor, monitor); } /** @@ -71,10 +75,13 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements * @param extensionProcessor */ public ConstrainingTypeProcessor(ModelFactoryExtensionPoint modelFactories, - StAXArtifactProcessor extensionProcessor, - Monitor monitor) { + StAXArtifactProcessor extensionProcessor, + Monitor monitor) { super(modelFactories.getFactory(AssemblyFactory.class), - modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor); + modelFactories.getFactory(ExtensionFactory.class), + modelFactories.getFactory(PolicyFactory.class), + extensionProcessor, + monitor); } public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException { diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java index a63ccdf151..29c1b649ec 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java @@ -35,13 +35,14 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Base; import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.ExtensionFactory; import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; 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.monitor.Monitor; import org.apache.tuscany.sca.policy.PolicyFactory; import org.apache.tuscany.sca.policy.PolicySetAttachPoint; @@ -60,12 +61,13 @@ public class DefaultBeanModelProcessor extends BaseAssemblyProcessor implements private Map<String, Method> getterMethods = new HashMap<String, Method>(); public DefaultBeanModelProcessor(AssemblyFactory assemblyFactory, - PolicyFactory policyFactory, - QName artifactType, - Class<Implementation> modelClass, - Object modelFactory, - Monitor monitor) { - super(assemblyFactory, policyFactory, null, monitor); + ExtensionFactory extensionFactory, + PolicyFactory policyFactory, + QName artifactType, + Class<Implementation> modelClass, + Object modelFactory, + Monitor monitor) { + super(assemblyFactory, extensionFactory, policyFactory, null, monitor); this.artifactType = artifactType; this.modelClass = modelClass; this.modelFactory = modelFactory; diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java index 32a3878db3..826e39baab 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.io.ByteArrayOutputStream; -import java.io.InputStream; +import java.io.StringReader; import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; @@ -33,11 +33,11 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.junit.After; -import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; /** @@ -47,77 +47,91 @@ import org.junit.Test; */ public class ReadWriteAnyAttributeTestCase { - private XMLInputFactory inputFactory; - private ExtensibleStAXArtifactProcessor staxProcessor; - private static final QName ATTRIBUTE = new QName("http://test", "customAttribute"); // implementation.java for CalculatorServiceComponent appears in a strange place as the // java implementation extension is not loaded and hence they are loaded as any elements private static final String XML = "<?xml version='1.0' encoding='UTF-8'?>"+ - "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\">"+ - "<service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\">"+ - "<interface.java interface=\"calculator.CalculatorService\" />"+ - "</service>"+ - "<component name=\"CalculatorServiceComponent\" customAttribute=\"customValue\">"+ - "<implementation.java class=\"calculator.CalculatorServiceImpl\" />"+ - "<reference name=\"addService\" target=\"AddServiceComponent\" />"+ - "<reference name=\"subtractService\" target=\"SubtractServiceComponent\" />"+ - "<reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" />"+ - "<reference name=\"divideService\" target=\"DivideServiceComponent\" />"+ - "</component>"+ - "<component name=\"AddServiceComponent\">"+ + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" " + + "xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" " + + "targetNamespace=\"http://calc\" " + + "name=\"Calculator\">"+ + "<component name=\"AddServiceComponent\" xmlns:test=\"http://test\" test:customAttribute=\"customValue\">"+ "<implementation.java class=\"calculator.AddServiceImpl\" />"+ - "</component>"+ - "<component name=\"SubtractServiceComponent\">"+ - "<implementation.java class=\"calculator.SubtractServiceImpl\" />"+ - "</component>"+ - "<component name=\"MultiplyServiceComponent\">"+ - "<implementation.java class=\"calculator.MultiplyServiceImpl\" />"+ - "</component>"+ - "<component name=\"DivideServiceComponent\">"+ - "<implementation.java class=\"calculator.DivideServiceImpl\" />"+ - "</component>"+ + "</component>"+ "</composite>"; - @Before - public void setUp() throws Exception { - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); - inputFactory = XMLInputFactory.newInstance(); - StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - - StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); - staxAttributeProcessors.addArtifactProcessor(new TestAttributeProcessor()); - - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); - } + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + - @After - public void tearDown() throws Exception { + /** + * Initialize the test environment + * This takes care to register attribute processors when provided + * + * @param attributeProcessor + * @throws Exception + */ + private void init(StAXAttributeProcessor<?> attributeProcessor) throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + + if(attributeProcessor != null) { + StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); + staxAttributeProcessors.addArtifactProcessor(attributeProcessor); + } + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); } + /** + * Read and Write a composite that has a extended attribute + * and a particular attribute processor + * @throws Exception + */ @Test - public void testReadComposite() throws Exception { - InputStream is = getClass().getResourceAsStream("CalculatorExtended.composite"); - XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite) staxProcessor.read(reader); - assertNotNull(composite); - is.close(); + @Ignore + public void testReadWriteCompositeWithAttributeProcessor() throws Exception { + init(new TestAttributeProcessor()); + + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + System.out.println(XML); + System.out.println(bos.toString()); + + assertEquals(XML, bos.toString()); } - + + /** + * Read and Write a composite that has a extended attribute + * but no particular processor for it + * @throws Exception + */ @Test - public void testWriteComposite() throws Exception { - InputStream is = getClass().getResourceAsStream("CalculatorExtended.composite"); - XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite) staxProcessor.read(reader); - assertNotNull(composite); - is.close(); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); - System.out.println(bos.toString()); - - assertEquals(XML, bos.toString()); + @Ignore + public void testDefaultReadWriteComposite() throws Exception { + init(null); + + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + System.out.println(XML); + System.out.println(bos.toString()); + + assertEquals(XML, bos.toString()); } } diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java index 64ff162ab7..c335af962c 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java @@ -41,81 +41,78 @@ import org.junit.Ignore; import org.junit.Test; public class ReadWriteAnyElementTestCase { - private static final String XML_RECURSIVE_EXTENDED_ELEMENT = - "<?xml version='1.0' encoding='UTF-8'?>" + - "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://temp\" name=\"RecursiveExtendedElement\">" + - "<unknownElement>" + - "<subUnknownElement1 attribute=\"anyAttribute\" />" + - "<subUnknownElement2 />" + - "</unknownElement>" + - "</composite>"; - - - private static final String XML_UNKNOWN_IMPL = - "<?xml version='1.0' encoding='UTF-8'?>" + + private static final String XML_RECURSIVE_EXTENDED_ELEMENT = + "<?xml version='1.0' encoding='UTF-8'?>" + + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://temp\" name=\"RecursiveExtendedElement\">" + + "<unknownElement>" + + "<subUnknownElement1 attribute=\"anyAttribute\" />" + + "<subUnknownElement2 />" + + "</unknownElement>" + + "</composite>"; + + private static final String XML_UNKNOWN_IMPL = + "<?xml version='1.0' encoding='UTF-8'?>" + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://temp\" name=\"aaaa\" autowire=\"false\">" + - "<component name=\"unknownImpl\">" + - "<implementation.unknown class=\"raymond\" />" + - "<service name= \"service\" requires=\"\">" + - "<binding.ws unknownAttribute=\"unknown\" />" + - "</service>" + - "</component>" + + "<component name=\"unknownImpl\">" + + "<implementation.unknown class=\"raymond\" />" + + "<service name= \"service\" requires=\"\">" + + "<binding.ws unknownAttribute=\"unknown\" />" + + "</service>" + + "</component>" + "</composite>"; - private XMLInputFactory inputFactory; - private ExtensibleStAXArtifactProcessor staxProcessor; - - @Before - public void setUp() throws Exception { - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); - ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); - inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); - - StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints - .getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, - inputFactory, XMLOutputFactory.newInstance(), null); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testReadWriteExtendedRecursiveElement() throws Exception { - XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_RECURSIVE_EXTENDED_ELEMENT)); - Composite composite = (Composite) staxProcessor.read(reader); - assertNotNull(composite); - reader.close(); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); - - // used for debug comparison - //System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT); - //System.out.println(bos.toString()); - - assertEquals(XML_RECURSIVE_EXTENDED_ELEMENT, bos.toString()); - bos.close(); - } - - //@Test - @Ignore() - public void testReadWriteUnknwonImpl() throws Exception { - XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL)); - Composite composite = (Composite) staxProcessor.read(reader); - assertNotNull(composite); - reader.close(); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); - - // used for debug comparison - System.out.println(XML_UNKNOWN_IMPL); - System.out.println(bos.toString()); - - assertEquals(XML_UNKNOWN_IMPL, bos.toString()); - bos.close(); - } + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + @Before + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, XMLOutputFactory.newInstance(), null); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testReadWriteExtendedRecursiveElement() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_RECURSIVE_EXTENDED_ELEMENT)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT); + System.out.println(bos.toString()); + + assertEquals(XML_RECURSIVE_EXTENDED_ELEMENT, bos.toString()); + bos.close(); + } + + // @Test + @Ignore() + public void testReadWriteUnknwonImpl() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML_UNKNOWN_IMPL); + // System.out.println(bos.toString()); + + assertEquals(XML_UNKNOWN_IMPL, bos.toString()); + bos.close(); + } } diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java index 691145a30e..84beebe466 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java @@ -36,7 +36,7 @@ import org.apache.tuscany.sca.contribution.service.ContributionWriteException; * @version $Rev$ $Date$ */ public class TestAttributeProcessor extends BaseStAXArtifactProcessor implements StAXAttributeProcessor<String> { - private static final QName ATTRIBUTE = new QName("http://test", "customAttribute"); + private static final QName ATTRIBUTE = new QName("http://test", "customAttribute", "test"); public QName getArtifactType() { return ATTRIBUTE; @@ -47,8 +47,7 @@ public class TestAttributeProcessor extends BaseStAXArtifactProcessor implements } public void write(String value, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - writer.setPrefix(ATTRIBUTE.getPrefix(), ATTRIBUTE.getNamespaceURI()); - writer.writeAttribute(ATTRIBUTE.getLocalPart(), value); + writer.writeAttribute(ATTRIBUTE.getPrefix(), ATTRIBUTE.getNamespaceURI(),ATTRIBUTE.getLocalPart(), value); } public Class<String> getModelType() { diff --git a/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.java b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.java new file mode 100644 index 0000000000..2ed02e214b --- /dev/null +++ b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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. + */ + +package org.apache.tuscany.sca.assembly; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.ExtensionImpl; + +public class DefaultExtensionFactory implements ExtensionFactory { + + public Extension createExtension() { + return new ExtensionImpl(); + } + + public Extension createExtension(QName name, Object value, boolean isAttribute) { + return new ExtensionImpl(name, value, isAttribute); + } + +} diff --git a/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java index 3577a94d1e..593b7de88b 100644 --- a/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java +++ b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java @@ -33,5 +33,12 @@ public interface Extensible { * @return a list of extension objects container in this model object */ List<Object> getExtensions(); + + /** + * Returns a list of attribute extensions contained in this model object + * + * @return a list of attribute extensions contained in this model object + */ + List<Extension> getAttributeExtensions(); } diff --git a/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.java b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.java new file mode 100644 index 0000000000..499c97c278 --- /dev/null +++ b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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. + */ +package org.apache.tuscany.sca.assembly; + +import javax.xml.namespace.QName; + +/** + * Base interface for storing contents of extensible assembly model objects. + * + * @version $Rev$ $Date$ + */ +public interface Extension { + + /** + * Return QName for the extension + * @return the extension QName + */ + QName getQName(); + + /** + * Set QName for the extension + * @param qName the extension QName + */ + void setQName(QName qName); + + /** + * Return the original extension value + * @return the extension value + */ + Object getValue(); + + /** + * Set the original extension value + * @param value the extension value + */ + void setValue(Object value); + + /** + * Return whether or not the extension is an attribute + * @return + */ + boolean isAttribute(); + + /** + * Set whether or not the extension is an attribute + * @param value + */ + void setIsAttribute(boolean isAttribute); +} diff --git a/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.java b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.java new file mode 100644 index 0000000000..214cf59748 --- /dev/null +++ b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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. + */ +package org.apache.tuscany.sca.assembly; + +import javax.xml.namespace.QName; + +public interface ExtensionFactory { + + Extension createExtension(); + + Extension createExtension(QName qName, Object value, boolean isAttribute); +} diff --git a/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java index 9a7ca09e43..0a2e25aa43 100644 --- a/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java +++ b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.Extension; /** * Convenience base class for extensible assembly model objects. @@ -30,6 +31,7 @@ import org.apache.tuscany.sca.assembly.Extensible; */ public abstract class ExtensibleImpl extends BaseImpl implements Extensible { private List<Object> extensions = new ArrayList<Object>(); + private List<Extension> attributeExtensions = new ArrayList<Extension>(); /** * Constructs a new base model object. @@ -40,5 +42,9 @@ public abstract class ExtensibleImpl extends BaseImpl implements Extensible { public List<Object> getExtensions() { return extensions; } + + public List<Extension> getAttributeExtensions() { + return attributeExtensions; + } } diff --git a/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.java b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.java new file mode 100644 index 0000000000..2753bcc091 --- /dev/null +++ b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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. + */ +package org.apache.tuscany.sca.assembly.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Extension; + +public class ExtensionImpl implements Extension { + private QName qName; + private Object value; + boolean isAttribute = false; + + public ExtensionImpl() { + + } + + public ExtensionImpl(QName qName, Object value, boolean isAttribute) { + this.qName = qName; + this.value = value; + this.isAttribute = isAttribute; + } + + public QName getQName() { + return qName; + } + + public void setQName(QName qName) { + this.qName = qName; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public boolean isAttribute() { + return isAttribute; + } + + public void setIsAttribute(boolean isAttribute) { + this.isAttribute = isAttribute; + } +} diff --git a/branches/sca-java-1.x/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.ExtensionFactory b/branches/sca-java-1.x/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.ExtensionFactory new file mode 100644 index 0000000000..bea25da958 --- /dev/null +++ b/branches/sca-java-1.x/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.ExtensionFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# 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. + +org.apache.tuscany.sca.assembly.DefaultExtensionFactory
\ No newline at end of file diff --git a/branches/sca-java-1.x/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java b/branches/sca-java-1.x/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java index 6fc5f9398e..a99b829e9c 100644 --- a/branches/sca-java-1.x/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java +++ b/branches/sca-java-1.x/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java @@ -28,6 +28,7 @@ import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Callback; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.Extension; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.InterfaceContract; @@ -182,6 +183,10 @@ public class TestRuntimeComponentService implements RuntimeComponentService { return null; } + public List<Extension> getAttributeExtensions() { + return null; + } + public List<Intent> getRequiredIntents() { return null; } diff --git a/branches/sca-java-1.x/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java b/branches/sca-java-1.x/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java index c93ddd9503..638a263a61 100644 --- a/branches/sca-java-1.x/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java +++ b/branches/sca-java-1.x/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java @@ -25,6 +25,7 @@ import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.Extension; import org.apache.tuscany.sca.assembly.OptimizableBinding; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.builder.AutomaticBinding; @@ -42,6 +43,7 @@ public class SCABindingImpl implements SCABinding, Extensible, PolicySetAttachPo private String name; private String uri; private List<Object> extensions = new ArrayList<Object>(); + private List<Extension> attributeExtensions = new ArrayList<Extension>(); private List<Intent> requiredIntents = new ArrayList<Intent>(); private List<PolicySet> policySets = new ArrayList<PolicySet>(); private IntentAttachPointType intentAttachPointType; @@ -106,15 +108,14 @@ public class SCABindingImpl implements SCABinding, Extensible, PolicySetAttachPo this.uri = uri; } - /** - * Returns a list of extension objects contained in this model object. - * - * @return a list of extension objects container in this model object - */ public List<Object> getExtensions() { return extensions; } - + + public List<Extension> getAttributeExtensions() { + return attributeExtensions; + } + /** * Returns true if the model element is unresolved. * diff --git a/branches/sca-java-1.x/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java b/branches/sca-java-1.x/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java index d816c2c9c6..a60376f870 100644 --- a/branches/sca-java-1.x/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java +++ b/branches/sca-java-1.x/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java @@ -30,6 +30,7 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.ConfiguredOperation; import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.Extension; import org.apache.tuscany.sca.assembly.OperationsConfigurator; import org.apache.tuscany.sca.assembly.builder.BindingBuilder; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; @@ -53,6 +54,7 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySetAttachPoint, private String uri; private boolean unresolved; private List<Object> extensions = new ArrayList<Object>(); + private List<Extension> attributeExtensions = new ArrayList<Extension>(); private List<Intent> requiredIntents = new ArrayList<Intent>(); private List<PolicySet> policySets = new ArrayList<PolicySet>(); private IntentAttachPointType intentAttachPointType; @@ -109,7 +111,11 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySetAttachPoint, public List<Object> getExtensions() { return extensions; } - + + public List<Extension> getAttributeExtensions() { + return attributeExtensions; + } + public String getLocation() { return location; } diff --git a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java b/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java index 2b868b9e45..6e6803a806 100644 --- a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java +++ b/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java @@ -18,28 +18,23 @@ */ package org.apache.tuscany.sca.contribution.processor.xml; +import static javax.xml.stream.XMLStreamConstants.CDATA; +import static javax.xml.stream.XMLStreamConstants.CHARACTERS; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.CHARACTERS; -import static javax.xml.stream.XMLStreamConstants.COMMENT; -import static javax.xml.stream.XMLStreamConstants.CDATA; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Stack; import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.QName; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; -import javax.xml.stream.events.Characters; import javax.xml.stream.events.XMLEvent; import org.apache.tuscany.sca.contribution.Constants; @@ -49,126 +44,121 @@ 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.monitor.Monitor; -import org.apache.tuscany.sca.contribution.processor.xml.XMLEventsStreamReader; public class AnyElementProcessor implements StAXArtifactProcessor<Object> { - private static final QName ANY_ELEMENT = new QName(Constants.XMLSCHEMA_NS, - "anyElement"); - - private XMLInputFactory xmlInputFactory; - @SuppressWarnings("unused") - private Monitor monitor; - //Map<String, NamespaceContext> map = new HashMap<String, NamespaceContext>(); - - public AnyElementProcessor(ModelFactoryExtensionPoint modelFactories, - Monitor monitor) { - xmlInputFactory = modelFactories.getFactory(XMLInputFactory.class); - this.monitor = monitor; - } - - public QName getArtifactType() { - return ANY_ELEMENT; - } - - public Class<Object> getModelType() { - return Object.class; - } - - /** - * Reads the contetns of the unknown elements and generates a custom - * implementation of XMLStreamReader i.e. XMLEventsStreamReader - * - * @param reader - * @return - * @throws XMLStreamException - */ - @SuppressWarnings("unchecked") - public Object read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { - - //Custom variables - String currentElement = null; - List eventsList = new ArrayList(); - - Map<String, NamespaceContext> eventContext = new HashMap<String, NamespaceContext>(); - - try{ - //Cast the block of unknown elements into document - XMLDocumentStreamReader docReader = new XMLDocumentStreamReader(reader); - - XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(docReader); - - while (xmlEventReader.hasNext()) { - XMLEvent event = xmlEventReader.nextEvent(); - - //Populate the eventContext map with the current element's name and corresponding NamesapceContext - if (currentElement != null && !(eventContext.containsKey(currentElement))) { - eventContext.put(currentElement, reader.getNamespaceContext()); - } - - //Populate the list with the XMLEvents - eventsList.add(event); - if (event.isStartElement()) { - currentElement = reader.getName().getLocalPart(); - } - if (event.isEndDocument()) { - return new XMLEventsStreamReader(eventsList, eventContext); - } - } - } - catch(Exception e){ - e.printStackTrace(); - } - return null; - } - - /** - * Writes unknown portions back to the writer - * - * @param model - * @param writer - */ - public void write(Object model, XMLStreamWriter writer) - throws XMLStreamException { - if (!(model instanceof XMLStreamReader)) { - return; - } - XMLStreamReader reader = (XMLStreamReader) model; - - int event = reader.getEventType(); - while (reader.hasNext()) { - switch (event) { - case START_ELEMENT: - - writer.writeStartElement(reader.getPrefix(), reader - .getLocalName(), reader.getNamespaceURI()); - for (int i = 1; i <= reader.getAttributeCount(); i++) { - writer.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), - reader.getAttributeLocalName(i), reader.getAttributeValue(i)); - } - break; - - case CHARACTERS: - writer.writeCharacters(reader.getText()); - break; - - case CDATA: - writer.writeCData(reader.getText()); - break; - - case END_ELEMENT: - writer.writeEndElement(); - break; - } - if (reader.hasNext()) { - event = reader.next(); - } - } - } - - public void resolve(Object model, ModelResolver resolver) - throws ContributionResolveException { - // TODO Auto-generated method stub - - } + private static final QName ANY_ELEMENT = new QName(Constants.XMLSCHEMA_NS, "anyElement"); + + private XMLInputFactory xmlInputFactory; + @SuppressWarnings("unused") + private Monitor monitor; + + // Map<String, NamespaceContext> map = new HashMap<String,NamespaceContext>(); + + public AnyElementProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + xmlInputFactory = modelFactories.getFactory(XMLInputFactory.class); + this.monitor = monitor; + } + + public QName getArtifactType() { + return ANY_ELEMENT; + } + + public Class<Object> getModelType() { + return Object.class; + } + + /** + * Reads the contetns of the unknown elements and generates a custom + * implementation of XMLStreamReader i.e. XMLEventsStreamReader + * + * @param reader + * @return + * @throws XMLStreamException + */ + @SuppressWarnings("unchecked") + public Object read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + + // Custom variables + String currentElement = null; + List eventsList = new ArrayList(); + + Map<String, NamespaceContext> eventContext = new HashMap<String, NamespaceContext>(); + + try { + // Cast the block of unknown elements into document + XMLDocumentStreamReader docReader = new XMLDocumentStreamReader(reader); + + XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(docReader); + + while (xmlEventReader.hasNext()) { + XMLEvent event = xmlEventReader.nextEvent(); + + // Populate the eventContext map with the current element's name + // and corresponding NamesapceContext + if (currentElement != null && !(eventContext.containsKey(currentElement))) { + eventContext.put(currentElement, reader.getNamespaceContext()); + } + + // Populate the list with the XMLEvents + eventsList.add(event); + if (event.isStartElement()) { + currentElement = reader.getName().getLocalPart(); + } + if (event.isEndDocument()) { + return new XMLEventsStreamReader(eventsList, eventContext); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * Writes unknown portions back to the writer + * + * @param model + * @param writer + */ + public void write(Object model, XMLStreamWriter writer) throws XMLStreamException { + if (!(model instanceof XMLStreamReader)) { + return; + } + XMLStreamReader reader = (XMLStreamReader)model; + + int event = reader.getEventType(); + while (reader.hasNext()) { + switch (event) { + case START_ELEMENT: + + writer.writeStartElement(reader.getPrefix(), reader.getLocalName(), reader.getNamespaceURI()); + for (int i = 1; i <= reader.getAttributeCount(); i++) { + writer.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), reader + .getAttributeLocalName(i), reader.getAttributeValue(i)); + } + break; + + case CHARACTERS: + writer.writeCharacters(reader.getText()); + break; + + case CDATA: + writer.writeCData(reader.getText()); + break; + + case END_ELEMENT: + writer.writeEndElement(); + break; + } + if (reader.hasNext()) { + event = reader.next(); + } + } + } + + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + // TODO Auto-generated method stub + + } } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java index f23ebc2c36..dfc4e9f57a 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java @@ -31,6 +31,7 @@ import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.AssemblyFactory; +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.resolver.ModelResolver; @@ -251,6 +252,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends // Specific initialization for the DefaultBeanModelProcessor ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + ExtensionFactory extensionFactory = modelFactories.getFactory(ExtensionFactory.class); PolicyFactory policyFactory = modelFactories.getFactory(PolicyFactory.class); try { Class<StAXArtifactProcessor> processorClass = @@ -264,6 +266,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends } Constructor<StAXArtifactProcessor> constructor = processorClass.getConstructor(AssemblyFactory.class, + ExtensionFactory.class, PolicyFactory.class, QName.class, Class.class, @@ -271,6 +274,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends Monitor.class); processor = constructor.newInstance(assemblyFactory, + extensionFactory, policyFactory, artifactType, getModelType(), diff --git a/branches/sca-java-1.x/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java b/branches/sca-java-1.x/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java index f2c517b092..9d874262e9 100644 --- a/branches/sca-java-1.x/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java +++ b/branches/sca-java-1.x/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java @@ -26,12 +26,13 @@ import org.apache.tuscany.sca.assembly.ComponentProperty; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Extension; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.IntentAttachPointType; import org.apache.tuscany.sca.policy.PolicySet; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.GenericBeanDefinition; /** @@ -63,6 +64,7 @@ public class BeanComponentImpl extends GenericBeanDefinition implements Componen private List<Intent> requiredIntents = new ArrayList<Intent>(); private List<PolicySet> policySets = new ArrayList<PolicySet>(); private List<Object> extensions = new ArrayList<Object>(); + private List<Extension> attributeExtensions = new ArrayList<Extension>(); private boolean unresolved = false; private BeanDefinitionRegistry beanRegistry; @@ -210,6 +212,10 @@ public class BeanComponentImpl extends GenericBeanDefinition implements Componen return extensions; } + public List<Extension> getAttributeExtensions() { + return attributeExtensions; + } + public boolean isUnresolved() { return unresolved; } diff --git a/branches/sca-java-1.x/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java b/branches/sca-java-1.x/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java index 49abfb4162..493ffe3798 100644 --- a/branches/sca-java-1.x/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java +++ b/branches/sca-java-1.x/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java @@ -23,6 +23,7 @@ import java.util.List; import org.apache.tuscany.sca.assembly.ConfiguredOperation; import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Extension; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; @@ -30,8 +31,8 @@ import org.apache.tuscany.sca.implementation.java.BaseJavaImplementation; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.IntentAttachPointType; import org.apache.tuscany.sca.policy.PolicySet; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.GenericBeanDefinition; /** @@ -46,6 +47,7 @@ public class BeanBaseJavaImplementationImpl extends GenericBeanDefinition implem private List<Service> services = new ArrayList<Service>(); private ConstrainingType constrainingType; private List<Object> extensions = new ArrayList<Object>(); + private List<Extension> attributeExtensions = new ArrayList<Extension>(); private boolean unresolved; private BeanDefinitionRegistry beanRegistry; private String uri; @@ -177,6 +179,10 @@ public class BeanBaseJavaImplementationImpl extends GenericBeanDefinition implem return extensions; } + public List<Extension> getAttributeExtensions() { + return attributeExtensions; + } + public boolean isUnresolved() { return unresolved; } |