From 6b614afbc3f08ded00a70bf9cf976d9bad12b4a7 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 2 Sep 2009 22:45:54 +0000 Subject: Merge from 1.5.1: 1) Fix for TUSCANY-3238 2) Remove calls to XMLStreamWriter.setPrefix() as writeNamespace() invokes it internally (TUSCANY-3212) git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@810726 13f79535-47bb-0310-9956-ffa450edef68 --- .../xyz/ImplementationXYZProcessor.java | 4 - .../assembly/xml/ConfiguredOperationProcessor.java | 29 +- .../assembly/xml/PolicyAttachPointProcessor.java | 31 +- .../sca/binding/sca/xml/SCABindingProcessor.java | 43 +- .../ws/wsdlgen/Interface2WSDLGenerator.java | 32 ++ .../binding/ws/xml/WebServiceBindingProcessor.java | 45 +- .../processor/xml/XMLDocumentStreamReader.java | 14 +- .../processor/BaseStAXArtifactProcessor.java | 6 +- .../sca-java-1.x/modules/databinding-jaxb/pom.xml | 4 +- .../sca/databinding/jaxb/JAXBContextHelper.java | 32 ++ .../helper/impl/BindingSCDLProcessor.java | 21 +- .../java/xml/JavaImplementationProcessor.java | 37 +- .../sca/implementation/java/xml/WriteTestCase.java | 14 +- .../implementation/java/xml/Calculator.composite | 16 +- .../jee/xml/JEEImplementationProcessor.java | 1 - .../spring/xml/SpringImplementationProcessor.java | 465 ++++++++++----------- .../widget/WidgetImplementationProcessor.java | 51 ++- .../main/java/echo/impl/EchoBindingProcessor.java | 7 +- .../pojo/impl/POJOImplementationProcessor.java | 51 ++- 19 files changed, 475 insertions(+), 428 deletions(-) (limited to 'branches/sca-java-1.x') diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/implementation/xyz/ImplementationXYZProcessor.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/implementation/xyz/ImplementationXYZProcessor.java index e70d22a0f6..792732e73f 100644 --- a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/implementation/xyz/ImplementationXYZProcessor.java +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/implementation/xyz/ImplementationXYZProcessor.java @@ -28,16 +28,13 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.artifact.xyz.XYZ; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.ComponentType; -import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ClassReference; 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.InvalidInterfaceException; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.PolicyFactory; @@ -149,7 +146,6 @@ public class ImplementationXYZProcessor implements StAXArtifactProcessor element - policyProcessor.writePolicyPrefixes(implementation, writer); writer.writeStartElement(IMPLEMENTATION_XYZ.getNamespaceURI(), IMPLEMENTATION_XYZ.getLocalPart()); policyProcessor.writePolicyAttributes(implementation, writer); diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java index aa4980fcb6..0f062dbda5 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.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; @@ -34,8 +34,8 @@ 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.policy.PolicyFactory; import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.policy.PolicyFactory; /** * Processor for dealing with 'operation' elements from composite definitions @@ -43,27 +43,27 @@ import org.apache.tuscany.sca.monitor.Monitor; * @version $Rev$ $Date$ */ public class ConfiguredOperationProcessor implements StAXArtifactProcessor, Constants{ - + private AssemblyFactory assemblyFactory; private PolicyAttachPointProcessor policyProcessor; private PolicyFactory policyFactory; private Monitor monitor; - + public ConfiguredOperationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); this.monitor = monitor; } - + public ConfiguredOperation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { ConfiguredOperation configuredOp = assemblyFactory.createConfiguredOperation(); - + //Read an configuredOp.setName(reader.getAttributeValue(null, NAME)); configuredOp.setContractName(reader.getAttributeValue(null, SERVICE)); configuredOp.setUnresolved(true); - + // Read policies policyProcessor.readPolicies(configuredOp, reader); @@ -73,15 +73,14 @@ public class ConfiguredOperationProcessor implements StAXArtifactProcessor - policyProcessor.writePolicyPrefixes(configuredOperation, writer); writer.writeStartElement(Constants.SCA10_NS, OPERATION); policyProcessor.writePolicyAttributes(configuredOperation, writer); @@ -91,15 +90,15 @@ public class ConfiguredOperationProcessor implements StAXArtifactProcessor getModelType() { return ConfiguredOperation.class; } diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java index fc4e10654d..44be1b6de1 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.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; @@ -43,9 +43,9 @@ import org.apache.tuscany.sca.policy.PolicySetAttachPoint; * @version $Rev$ $Date$ */ public class PolicyAttachPointProcessor extends BaseStAXArtifactProcessor implements Constants { - + private PolicyFactory policyFactory; - + public PolicyAttachPointProcessor(PolicyFactory policyFactory) { this.policyFactory = policyFactory; } @@ -123,7 +123,7 @@ public class PolicyAttachPointProcessor extends BaseStAXArtifactProcessor implem policySets.add(policySet); } } - + value = reader.getAttributeValue(SCA10_TUSCANY_NS, APPLICABLE_POLICY_SETS); if (value != null) { List applicablePolicySets = policySetAttachPoint.getApplicablePolicySets(); @@ -140,7 +140,7 @@ public class PolicyAttachPointProcessor extends BaseStAXArtifactProcessor implem } } } - + /** * Write policies * @param attachPoint @@ -159,15 +159,6 @@ public class PolicyAttachPointProcessor extends BaseStAXArtifactProcessor implem writePolicyAttributes(attachPoint, (Operation)null, writer); } - /** - * Write policies - * @param attachPoint - * @return - */ - public void writePolicyPrefixes(Object attachPoint, XMLStreamWriter writer) throws XMLStreamException { - writePolicyPrefixes(attachPoint, (Operation)null, writer); - } - /** * Write policies associated with an operation * @param attachPoint @@ -234,14 +225,14 @@ public class PolicyAttachPointProcessor extends BaseStAXArtifactProcessor implem } return new XAttr(Constants.POLICY_SETS, qnames); } - + public void resolvePolicies(Object attachPoint, ModelResolver resolver) { if ( attachPoint instanceof PolicySetAttachPoint ) { PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint; - + List requiredIntents = new ArrayList(); Intent resolvedIntent = null; - + if ( policySetAttachPoint.getRequiredIntents() != null && policySetAttachPoint.getRequiredIntents().size() > 0 ) { for ( Intent intent : policySetAttachPoint.getRequiredIntents() ) { resolvedIntent = resolver.resolveModel(Intent.class, intent); @@ -250,7 +241,7 @@ public class PolicyAttachPointProcessor extends BaseStAXArtifactProcessor implem policySetAttachPoint.getRequiredIntents().clear(); policySetAttachPoint.getRequiredIntents().addAll(requiredIntents); } - + if ( policySetAttachPoint.getPolicySets() != null && policySetAttachPoint.getPolicySets().size() > 0 ) { List resolvedPolicySets = new ArrayList(); PolicySet resolvedPolicySet = null; diff --git a/branches/sca-java-1.x/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java b/branches/sca-java-1.x/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java index 8c82ef2378..034aaf0339 100644 --- a/branches/sca-java-1.x/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java +++ b/branches/sca-java-1.x/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.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.binding.sca.xml; @@ -52,21 +52,21 @@ import org.apache.tuscany.sca.policy.PolicySetAttachPoint; */ public class SCABindingProcessor implements StAXArtifactProcessor, Constants{ - + private SCABindingFactory scaBindingFactory; private ExtensionFactory extensionFactory; private PolicyFactory policyFactory; private IntentAttachPointTypeFactory intentAttachPointTypeFactory; - private PolicyAttachPointProcessor policyProcessor; + private PolicyAttachPointProcessor policyProcessor; private StAXAttributeProcessor extensionAttributeProcessor; - + private Monitor monitor; protected static final String BINDING_SCA = "binding.sca"; protected static final QName BINDING_SCA_QNAME = new QName(Constants.SCA10_NS, BINDING_SCA); - public SCABindingProcessor(ModelFactoryExtensionPoint modelFactories, + public SCABindingProcessor(ModelFactoryExtensionPoint modelFactories, StAXArtifactProcessor extensionProcessor, StAXAttributeProcessor extensionAttributeProcessor, Monitor monitor) { @@ -74,9 +74,9 @@ public class SCABindingProcessor implements StAXArtifactProcessor, C this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.intentAttachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); - + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); - this.extensionAttributeProcessor = extensionAttributeProcessor; + this.extensionAttributeProcessor = extensionAttributeProcessor; this.monitor = monitor; } @@ -95,10 +95,10 @@ public class SCABindingProcessor implements StAXArtifactProcessor, C bindingType.setName(getArtifactType()); bindingType.setUnresolved(true); ((PolicySetAttachPoint)scaBinding).setType(bindingType); - + // Read policies policyProcessor.readPolicies(scaBinding, reader); - + // Read binding name String name = reader.getAttributeValue(null, NAME); if (name != null) { @@ -110,12 +110,12 @@ public class SCABindingProcessor implements StAXArtifactProcessor, C if (uri != null) { scaBinding.setURI(uri); } - + // Handle extended attributes for (int a = 0; a < reader.getAttributeCount(); a++) { QName attributeName = reader.getAttributeName(a); if( attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) { - if( (! Constants.SCA10_NS.equals(attributeName.getNamespaceURI()) && + if( (! Constants.SCA10_NS.equals(attributeName.getNamespaceURI()) && (! Constants.SCA10_TUSCANY_NS.equals(attributeName.getNamespaceURI()) ))) { Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); Extension attributeExtension; @@ -127,7 +127,7 @@ public class SCABindingProcessor implements StAXArtifactProcessor, C scaBinding.getAttributeExtensions().add(attributeExtension); } } - } + } // Skip to end element while (reader.hasNext()) { @@ -137,15 +137,14 @@ public class SCABindingProcessor implements StAXArtifactProcessor, C } return scaBinding; } - + public void resolve(SCABinding model, ModelResolver resolver) throws ContributionResolveException { policyProcessor.resolvePolicies(model, resolver); - } + } public void write(SCABinding scaBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { // Write - policyProcessor.writePolicyPrefixes(scaBinding, writer); writer.writeStartElement(Constants.SCA10_NS, BINDING_SCA); policyProcessor.writePolicyAttributes(scaBinding, writer); @@ -153,20 +152,20 @@ public class SCABindingProcessor implements StAXArtifactProcessor, C if (scaBinding.getName() != null) { writer.writeAttribute(NAME, scaBinding.getName()); } - + // Write binding URI if (scaBinding.getURI() != null) { writer.writeAttribute(URI, scaBinding.getURI()); } - + // Write extended attributes for(Extension extension : scaBinding.getAttributeExtensions()) { if(extension.isAttribute()) { extensionAttributeProcessor.write(extension, writer); } - } - + } + writer.writeEndElement(); } - + } diff --git a/branches/sca-java-1.x/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java b/branches/sca-java-1.x/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java index 3cc2cb68d0..dd47d23f6b 100644 --- a/branches/sca-java-1.x/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java +++ b/branches/sca-java-1.x/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java @@ -43,6 +43,7 @@ import javax.wsdl.Types; import javax.wsdl.WSDLException; import javax.wsdl.extensions.schema.Schema; import javax.wsdl.factory.WSDLFactory; +import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -55,6 +56,7 @@ import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.JavaOperation; import org.apache.tuscany.sca.interfacedef.util.ElementInfo; @@ -246,8 +248,38 @@ public class Interface2WSDLGenerator { addDataType(dataTypes, dt4, helpers); } } + // Adding classes referenced by @XmlSeeAlso in the java interface + if (intf instanceof JavaInterface) { + JavaInterface javaInterface = (JavaInterface)intf; + Class[] seeAlso = getSeeAlso(javaInterface.getJavaClass()); + if (seeAlso != null) { + for (Class cls : seeAlso) { + DataType dt = new DataTypeImpl(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN); + addDataType(dataTypes, dt, helpers); + } + } + seeAlso = getSeeAlso(javaInterface.getCallbackClass()); + if (seeAlso != null) { + for (Class cls : seeAlso) { + DataType dt = new DataTypeImpl(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN); + addDataType(dataTypes, dt, helpers); + } + } + } return dataTypes; } + + private static Class[] getSeeAlso(Class interfaze) { + if (interfaze == null) { + return null; + } + XmlSeeAlso seeAlso = interfaze.getAnnotation(XmlSeeAlso.class); + if (seeAlso == null) { + return null; + } else { + return seeAlso.value(); + } + } public Definition generate(Interface interfaze, WSDLDefinition wsdlDefinition) throws WSDLException { diff --git a/branches/sca-java-1.x/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java b/branches/sca-java-1.x/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java index 0b09fdd507..a3dfcc3c5b 100644 --- a/branches/sca-java-1.x/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java +++ b/branches/sca-java-1.x/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.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.binding.ws.xml; @@ -89,9 +89,9 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor extensionAttributeProcessor; private Monitor monitor; - + public WebServiceBindingProcessor(ExtensionPointRegistry extensionPoints, Monitor monitor) { - + this.extensionPoints = extensionPoints; ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); this.policyFactory = modelFactories.getFactory(PolicyFactory.class); @@ -102,16 +102,16 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor 0) { - if( (! Constants.SCA10_NS.equals(attributeName.getNamespaceURI()) && + if( (! Constants.SCA10_NS.equals(attributeName.getNamespaceURI()) && (! Constants.SCA10_TUSCANY_NS.equals(attributeName.getNamespaceURI()) ))) { Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); Extension attributeExtension; @@ -294,7 +294,6 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor - policyProcessor.writePolicyPrefixes(wsBinding, writer); writer.writeStartElement(Constants.SCA10_NS, BINDING_WS); policyProcessor.writePolicyAttributes(wsBinding, writer); @@ -361,7 +360,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessortuscany-databinding 1.6-SNAPSHOT - javax.xml.bind jaxb-api diff --git a/branches/sca-java-1.x/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java b/branches/sca-java-1.x/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java index 2e8a4fc385..95aa6d1402 100644 --- a/branches/sca-java-1.x/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java +++ b/branches/sca-java-1.x/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java @@ -37,6 +37,7 @@ import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.bind.annotation.XmlType; import javax.xml.namespace.QName; @@ -47,6 +48,8 @@ import org.apache.tuscany.sca.databinding.util.LRUCache; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; import org.apache.tuscany.sca.interfacedef.util.XMLType; @@ -98,6 +101,18 @@ public class JAXBContextHelper { return createJAXBContext(dataType); } + + private static Class[] getSeeAlso(Class interfaze) { + if (interfaze == null) { + return null; + } + XmlSeeAlso seeAlso = interfaze.getAnnotation(XmlSeeAlso.class); + if (seeAlso == null) { + return null; + } else { + return seeAlso.value(); + } + } public static JAXBContext createJAXBContext(DataType dataType) throws JAXBException { return createJAXBContext(findClasses(dataType)); @@ -298,6 +313,23 @@ public class JAXBContextHelper { private static List getDataTypes(Operation op, boolean useWrapper) { List dataTypes = new ArrayList(); getDataTypes(dataTypes, op, useWrapper); + // Adding classes referenced by @XmlSeeAlso in the java interface + Interface interface1 = op.getInterface(); + if (interface1 instanceof JavaInterface) { + JavaInterface javaInterface = (JavaInterface)interface1; + Class[] seeAlso = getSeeAlso(javaInterface.getJavaClass()); + if (seeAlso != null) { + for (Class cls : seeAlso) { + dataTypes.add(new DataTypeImpl(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN)); + } + } + seeAlso = getSeeAlso(javaInterface.getCallbackClass()); + if (seeAlso != null) { + for (Class cls : seeAlso) { + dataTypes.add(new DataTypeImpl(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN)); + } + } + } return dataTypes; } diff --git a/branches/sca-java-1.x/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/BindingSCDLProcessor.java b/branches/sca-java-1.x/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/BindingSCDLProcessor.java index 8a83f630e9..8b99701baa 100644 --- a/branches/sca-java-1.x/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/BindingSCDLProcessor.java +++ b/branches/sca-java-1.x/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/BindingSCDLProcessor.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.extension.helper.impl; @@ -45,7 +45,7 @@ import org.apache.tuscany.sca.extension.helper.utils.AbstractBinding; /** * An SCDL ArtifactProcessor which uses the Binding class getters/setters * to define the SCDL attributes. - * + * * TODO: merge this with SCDLProcessor * * @version $Rev$ $Date$ @@ -126,7 +126,7 @@ public class BindingSCDLProcessor implements StAXArtifactProcessor { //FIXME: none of the attributes of Binding seem to be working with PojoBinding // For now at least read the binding URI String uri = reader.getAttributeValue(null, "uri"); - + if (elementTextSetter != null) { try { String value = reader.getElementText(); @@ -144,7 +144,7 @@ public class BindingSCDLProcessor implements StAXArtifactProcessor { if (!(impl instanceof Binding)) { impl = new PojoBinding(impl); - + //FIXME: none of the attributes of Binding seem to be working with PojoBinding // For now at least read the binding URI if (uri != null) { @@ -161,8 +161,8 @@ public class BindingSCDLProcessor implements StAXArtifactProcessor { //FIXME: none of the attributes of Binding seem to be working with PojoBinding // For now at least write the binding URI - - // Find a namespace prefix and write the element + + // Find a namespace prefix and write the element String prefix = writer.getPrefix(scdlQName.getNamespaceURI()); if (prefix == null) { NamespaceContext nsc = writer.getNamespaceContext(); @@ -172,9 +172,10 @@ public class BindingSCDLProcessor implements StAXArtifactProcessor { break; } } - writer.setPrefix(prefix, scdlQName.getNamespaceURI()); + // writer.setPrefix(prefix, scdlQName.getNamespaceURI()); } writer.writeStartElement(scdlQName.getNamespaceURI(), scdlQName.getLocalPart()); + writer.writeNamespace(prefix, scdlQName.getNamespaceURI()); // Write the binding URI attribute String uri; @@ -186,7 +187,7 @@ public class BindingSCDLProcessor implements StAXArtifactProcessor { if (uri != null) { writer.writeAttribute("uri", uri); } - + writer.writeEndElement(); } diff --git a/branches/sca-java-1.x/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java b/branches/sca-java-1.x/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java index b80440959b..7445209672 100644 --- a/branches/sca-java-1.x/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java +++ b/branches/sca-java-1.x/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.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.implementation.java.xml; @@ -98,10 +98,10 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor JavaImplementation javaImplementation = javaFactory.createJavaImplementation(); - + /*if ( javaImplementation instanceof PolicySetAttachPoint ) { IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType(); implType.setName(getArtifactType()); implType.setUnresolved(true); ((PolicySetAttachPoint)javaImplementation).setType(implType); }*/ - + javaImplementation.setUnresolved(true); javaImplementation.setName(reader.getAttributeValue(null, CLASS)); // Read policies policyProcessor.readPolicies(javaImplementation, reader); - + // Handle extended attributes for (int a = 0; a < reader.getAttributeCount(); a++) { QName attributeName = reader.getAttributeName(a); if( attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) { - if( (! Constants.SCA10_NS.equals(attributeName.getNamespaceURI()) && + if( (! Constants.SCA10_NS.equals(attributeName.getNamespaceURI()) && (! Constants.SCA10_TUSCANY_NS.equals(attributeName.getNamespaceURI()) ))) { Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); Extension attributeExtension; @@ -163,7 +163,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor - policyProcessor.writePolicyPrefixes(javaImplementation, writer); writer.writeStartElement(Constants.SCA10_NS, IMPLEMENTATION_JAVA); policyProcessor.writePolicyAttributes(javaImplementation, writer); @@ -207,7 +206,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor staxProcessor; private XMLInputFactory inputFactory; private XMLOutputFactory outputFactory; - + @Override public void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); inputFactory = XMLInputFactory.newInstance(); outputFactory = XMLOutputFactory.newInstance(); + // outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); } public void testReadWriteComposite() throws Exception { - InputStream is = getClass().getResourceAsStream("Calculator.composite"); + InputStream is = getClass().getResourceAsStream("default.composite"); Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is)); assertNotNull(composite); ByteArrayOutputStream bos = new ByteArrayOutputStream(); staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + System.out.println(new String(bos.toByteArray())); } } diff --git a/branches/sca-java-1.x/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/Calculator.composite b/branches/sca-java-1.x/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/Calculator.composite index a58fa0c072..c6a077ffa6 100644 --- a/branches/sca-java-1.x/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/Calculator.composite +++ b/branches/sca-java-1.x/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/Calculator.composite @@ -7,21 +7,21 @@ * 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. --> @@ -51,16 +51,16 @@ - + - + - + - + diff --git a/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java b/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java index bb66d8f0ca..9059d2da26 100644 --- a/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java +++ b/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java @@ -304,7 +304,6 @@ public class JEEImplementationProcessor extends BaseStAXArtifactProcessor implem public void write(JEEImplementation implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { // Write - policyProcessor.writePolicyPrefixes(implementation, writer); writeStart(writer, IMPLEMENTATION_JEE.getNamespaceURI(), IMPLEMENTATION_JEE.getLocalPart(), new XAttr("archive", implementation.getArchive())); diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java index ec8a6a961e..a4840cfef6 100644 --- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java +++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java @@ -1,234 +1,233 @@ -/* - * 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.implementation.spring.xml; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.ComponentType; -import org.apache.tuscany.sca.assembly.xml.Constants; -import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; -import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; -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.implementation.spring.SpringImplementation; -import org.apache.tuscany.sca.implementation.spring.introspect.SpringXMLComponentTypeLoader; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; +/* + * 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.implementation.spring.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +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.implementation.spring.SpringImplementation; +import org.apache.tuscany.sca.implementation.spring.introspect.SpringXMLComponentTypeLoader; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; import org.apache.tuscany.sca.monitor.impl.ProblemImpl; -import org.apache.tuscany.sca.policy.PolicyFactory; - -/** - * SpringArtifactProcessor is responsible for processing the XML of an - * element in an SCA SCDL file. - * - * @version $Rev: 511195 $ $Date: 2007-02-24 02:29:46 +0000 (Sat, 24 Feb 2007) $ - */ -public class SpringImplementationProcessor implements StAXArtifactProcessor { - - private static final String LOCATION = "location"; - private static final String IMPLEMENTATION_SPRING = "implementation.spring"; - private static final QName IMPLEMENTATION_SPRING_QNAME = new QName(Constants.SCA10_NS, IMPLEMENTATION_SPRING); - private static final String MSG_LOCATION_MISSING = "Reading implementation.spring - location attribute missing"; - - private AssemblyFactory assemblyFactory; - private JavaInterfaceFactory javaFactory; - private PolicyFactory policyFactory; - private PolicyAttachPointProcessor policyProcessor; - private Monitor monitor; - - private ModelFactoryExtensionPoint factories; - - public SpringImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { - this.factories = modelFactories; - this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - this.javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); - this.policyFactory = modelFactories.getFactory(PolicyFactory.class); - this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); - this.monitor = monitor; - } - - /** - * 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(), "impl-spring-validation-messages", Severity.ERROR, model, message, ex); - monitor.problem(problem); - } - } - - /** - * 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(), "impl-spring-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); - } - } - - /* - * Read the XML and parse out the attributes. - * - * has a single required attribute: - * "location" - which is the target URI of of an archive file or a directory that contains the Spring - * application context files. - * If the resource identified by the location attribute is an archive file, then the file - * META-INF/MANIFEST.MF is read from the archive. - * If the location URI identifies a directory, then META-INF/MANIFEST.MF must exist - * underneath that directory. - * If the manifest file contains a header "Spring-Context" of the format: - * Spring-Context ::= path ( ';' path )* - * - * Where path is a relative path with respect to the location URI, then the set of paths - * specified in the header identify the context configuration files. - * If there is no MANIFEST.MF file or no Spring-Context header within that file, - * then the default behaviour is to build an application context using all the *.xml files - * in the METAINF/spring directory. - */ - public SpringImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { - - // Create the Spring implementation - SpringImplementation springImplementation = null; - - // Read the location attribute for the spring implementation - String springLocation = reader.getAttributeValue(null, LOCATION); - if (springLocation != null) { - springImplementation = new SpringImplementation(); - springImplementation.setLocation(springLocation); - springImplementation.setUnresolved(true); - processComponentType(springImplementation); - } else { - error("LocationAttributeMissing", reader); - //throw new ContributionReadException(MSG_LOCATION_MISSING); - } - - // Read policies - policyProcessor.readPolicies(springImplementation, reader); - - // Skip to end element - while (reader.hasNext()) { - if (reader.next() == END_ELEMENT && IMPLEMENTATION_SPRING_QNAME.equals(reader.getName())) { - break; - } - } // end while - - return springImplementation; - } // end read - - /* - * Handles the component type for the Spring implementation - * @param springImplementation - a Spring implementation. The component type information - * is created for this implementation - * - */ - private void processComponentType(SpringImplementation springImplementation) { - - // Create a ComponentType and mark it unresolved - ComponentType componentType = assemblyFactory.createComponentType(); - componentType.setUnresolved(true); - springImplementation.setComponentType(componentType); - } // end processComponentType - - /* - * Write out the XML representation of the Spring implementation - * - */ - public void write(SpringImplementation springImplementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - - // Write - policyProcessor.writePolicyPrefixes(springImplementation, writer); - writer.writeStartElement(Constants.SCA10_NS, IMPLEMENTATION_SPRING); - policyProcessor.writePolicyAttributes(springImplementation, writer); - - if (springImplementation.getLocation() != null) { - writer.writeAttribute(LOCATION, springImplementation.getLocation()); - } - - writer.writeEndElement(); - - } // end write - - /** - * Resolves the Spring implementation - loads the Spring application-context XML and - * derives the spring implementation componentType from it - */ - public void resolve(SpringImplementation springImplementation, ModelResolver resolver) - throws ContributionResolveException { - - if (springImplementation == null) - return; - - /* Load the Spring component type by reading the Spring application context */ - SpringXMLComponentTypeLoader springLoader = - new SpringXMLComponentTypeLoader(factories, assemblyFactory, javaFactory, policyFactory); - try { - // Load the Spring Implementation information from its application context file... - springLoader.load(springImplementation, resolver); - } catch (ContributionReadException e) { - ContributionResolveException ce = new ContributionResolveException(e); - error("ContributionResolveException", resolver, ce); - throw ce; - } - - ComponentType ct = springImplementation.getComponentType(); - if (ct.isUnresolved()) { - // If the introspection fails to resolve, try to find a side file... - ComponentType componentType = resolver.resolveModel(ComponentType.class, ct); - if (componentType.isUnresolved()) { - error("UnableToResolveComponentType", resolver); - //throw new ContributionResolveException("SpringArtifactProcessor: unable to resolve componentType for Spring component"); - } else { - springImplementation.setComponentType(componentType); - springImplementation.setUnresolved(false); - } - - } // end if - - } // end method resolve - - public QName getArtifactType() { - return IMPLEMENTATION_SPRING_QNAME; - } - - public Class getModelType() { - return SpringImplementation.class; - } - -} // end class SpringArtifactProcessor +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * SpringArtifactProcessor is responsible for processing the XML of an + * element in an SCA SCDL file. + * + * @version $Rev: 511195 $ $Date: 2007-02-24 02:29:46 +0000 (Sat, 24 Feb 2007) $ + */ +public class SpringImplementationProcessor implements StAXArtifactProcessor { + + private static final String LOCATION = "location"; + private static final String IMPLEMENTATION_SPRING = "implementation.spring"; + private static final QName IMPLEMENTATION_SPRING_QNAME = new QName(Constants.SCA10_NS, IMPLEMENTATION_SPRING); + private static final String MSG_LOCATION_MISSING = "Reading implementation.spring - location attribute missing"; + + private AssemblyFactory assemblyFactory; + private JavaInterfaceFactory javaFactory; + private PolicyFactory policyFactory; + private PolicyAttachPointProcessor policyProcessor; + private Monitor monitor; + + private ModelFactoryExtensionPoint factories; + + public SpringImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + this.factories = modelFactories; + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + this.javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + this.monitor = monitor; + } + + /** + * 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(), "impl-spring-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + /** + * 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(), "impl-spring-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /* + * Read the XML and parse out the attributes. + * + * has a single required attribute: + * "location" - which is the target URI of of an archive file or a directory that contains the Spring + * application context files. + * If the resource identified by the location attribute is an archive file, then the file + * META-INF/MANIFEST.MF is read from the archive. + * If the location URI identifies a directory, then META-INF/MANIFEST.MF must exist + * underneath that directory. + * If the manifest file contains a header "Spring-Context" of the format: + * Spring-Context ::= path ( ';' path )* + * + * Where path is a relative path with respect to the location URI, then the set of paths + * specified in the header identify the context configuration files. + * If there is no MANIFEST.MF file or no Spring-Context header within that file, + * then the default behaviour is to build an application context using all the *.xml files + * in the METAINF/spring directory. + */ + public SpringImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + + // Create the Spring implementation + SpringImplementation springImplementation = null; + + // Read the location attribute for the spring implementation + String springLocation = reader.getAttributeValue(null, LOCATION); + if (springLocation != null) { + springImplementation = new SpringImplementation(); + springImplementation.setLocation(springLocation); + springImplementation.setUnresolved(true); + processComponentType(springImplementation); + } else { + error("LocationAttributeMissing", reader); + //throw new ContributionReadException(MSG_LOCATION_MISSING); + } + + // Read policies + policyProcessor.readPolicies(springImplementation, reader); + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && IMPLEMENTATION_SPRING_QNAME.equals(reader.getName())) { + break; + } + } // end while + + return springImplementation; + } // end read + + /* + * Handles the component type for the Spring implementation + * @param springImplementation - a Spring implementation. The component type information + * is created for this implementation + * + */ + private void processComponentType(SpringImplementation springImplementation) { + + // Create a ComponentType and mark it unresolved + ComponentType componentType = assemblyFactory.createComponentType(); + componentType.setUnresolved(true); + springImplementation.setComponentType(componentType); + } // end processComponentType + + /* + * Write out the XML representation of the Spring implementation + * + */ + public void write(SpringImplementation springImplementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write + writer.writeStartElement(Constants.SCA10_NS, IMPLEMENTATION_SPRING); + policyProcessor.writePolicyAttributes(springImplementation, writer); + + if (springImplementation.getLocation() != null) { + writer.writeAttribute(LOCATION, springImplementation.getLocation()); + } + + writer.writeEndElement(); + + } // end write + + /** + * Resolves the Spring implementation - loads the Spring application-context XML and + * derives the spring implementation componentType from it + */ + public void resolve(SpringImplementation springImplementation, ModelResolver resolver) + throws ContributionResolveException { + + if (springImplementation == null) + return; + + /* Load the Spring component type by reading the Spring application context */ + SpringXMLComponentTypeLoader springLoader = + new SpringXMLComponentTypeLoader(factories, assemblyFactory, javaFactory, policyFactory); + try { + // Load the Spring Implementation information from its application context file... + springLoader.load(springImplementation, resolver); + } catch (ContributionReadException e) { + ContributionResolveException ce = new ContributionResolveException(e); + error("ContributionResolveException", resolver, ce); + throw ce; + } + + ComponentType ct = springImplementation.getComponentType(); + if (ct.isUnresolved()) { + // If the introspection fails to resolve, try to find a side file... + ComponentType componentType = resolver.resolveModel(ComponentType.class, ct); + if (componentType.isUnresolved()) { + error("UnableToResolveComponentType", resolver); + //throw new ContributionResolveException("SpringArtifactProcessor: unable to resolve componentType for Spring component"); + } else { + springImplementation.setComponentType(componentType); + springImplementation.setUnresolved(false); + } + + } // end if + + } // end method resolve + + public QName getArtifactType() { + return IMPLEMENTATION_SPRING_QNAME; + } + + public Class getModelType() { + return SpringImplementation.class; + } + +} // end class SpringArtifactProcessor diff --git a/branches/sca-java-1.x/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java b/branches/sca-java-1.x/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java index fdaaf703bb..595f526bc9 100644 --- a/branches/sca-java-1.x/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java +++ b/branches/sca-java-1.x/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.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.implementation.widget; @@ -43,54 +43,54 @@ import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; import org.apache.tuscany.sca.monitor.impl.ProblemImpl; - /** + * * Implements a StAX artifact processor for Widget implementations. * * @version $Rev$ $Date$ */ public class WidgetImplementationProcessor implements StAXArtifactProcessor { private static final QName IMPLEMENTATION_WIDGET = new QName(Constants.SCA10_TUSCANY_NS, "implementation.widget"); - + private AssemblyFactory assemblyFactory; private ContributionFactory contributionFactory; private WidgetImplementationFactory implementationFactory; private Monitor monitor; - + public WidgetImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); contributionFactory = modelFactories.getFactory(ContributionFactory.class); - implementationFactory = new WidgetImplementationFactory(modelFactories); + implementationFactory = new WidgetImplementationFactory(modelFactories); this.monitor = monitor; } - + /** * 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(), "impl-widget-validation-messages", Severity.ERROR, model, message, ex); + Problem problem = monitor.createProblem(this.getClass().getName(), "impl-widget-validation-messages", Severity.ERROR, model, message, ex); monitor.problem(problem); } } - + /** * 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(), "impl-widget-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + Problem problem = monitor.createProblem(this.getClass().getName(), "impl-widget-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); } - } + } public QName getArtifactType() { // Returns the QName of the XML element processed by this processor @@ -111,7 +111,7 @@ public class WidgetImplementationProcessor implements StAXArtifactProcessor - writer.setPrefix("widget",IMPLEMENTATION_WIDGET.getNamespaceURI()); writer.writeStartElement(IMPLEMENTATION_WIDGET.getNamespaceURI(), IMPLEMENTATION_WIDGET.getLocalPart()); writer.writeNamespace("widget",IMPLEMENTATION_WIDGET.getNamespaceURI()); - - + + if (implementation.getLocation() != null) { writer.writeAttribute("location", implementation.getLocation()); } - + writer.writeEndElement(); } } diff --git a/branches/sca-java-1.x/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingProcessor.java b/branches/sca-java-1.x/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingProcessor.java index 1a2b5bfe89..865ddca329 100644 --- a/branches/sca-java-1.x/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingProcessor.java +++ b/branches/sca-java-1.x/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingProcessor.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 echo.impl; @@ -91,7 +91,6 @@ public class EchoBindingProcessor implements StAXArtifactProcessor public void write(EchoBinding echoBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - policyProcessor.writePolicyPrefixes(echoBinding, writer); writer.writeStartElement(BINDING_ECHO.getNamespaceURI(), BINDING_ECHO.getLocalPart()); policyProcessor.writePolicyAttributes(echoBinding, writer); diff --git a/branches/sca-java-1.x/samples/implementation-pojo-extension/src/main/java/pojo/impl/POJOImplementationProcessor.java b/branches/sca-java-1.x/samples/implementation-pojo-extension/src/main/java/pojo/impl/POJOImplementationProcessor.java index 44a2cc0aa8..5476c80cdd 100644 --- a/branches/sca-java-1.x/samples/implementation-pojo-extension/src/main/java/pojo/impl/POJOImplementationProcessor.java +++ b/branches/sca-java-1.x/samples/implementation-pojo-extension/src/main/java/pojo/impl/POJOImplementationProcessor.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 pojo.impl; @@ -48,25 +48,25 @@ import pojo.POJOImplementationFactory; /** * Implements a STAX based artifact processor for POJO implementations. - * + * * The artifact processor is responsible for processing * elements in SCA assembly XML composite files and populating the POJO * implementation model, resolving its references to other artifacts in the SCA - * contribution, and optionally write the model back to SCA assembly XML. + * contribution, and optionally write the model back to SCA assembly XML. */ public class POJOImplementationProcessor implements StAXArtifactProcessor { private static final QName IMPLEMENTATION_POJO = new QName("http://pojo", "implementation.pojo"); - + private AssemblyFactory assemblyFactory; private JavaInterfaceFactory javaFactory; private POJOImplementationFactory pojoImplementationFactory; private PolicyFactory policyFactory; private PolicyAttachPointProcessor policyProcessor; - + public POJOImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { - + // Get the assembly and Java interface factories as we'll need them to - // create model objects + // create model objects assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); policyFactory = modelFactories.getFactory(PolicyFactory.class); @@ -85,36 +85,36 @@ public class POJOImplementationProcessor implements StAXArtifactProcessor element POJOImplementation implementation = pojoImplementationFactory.createPOJOImplementation(); - + // Read policies policyProcessor.readPolicies(implementation, reader); - + // Read the POJO class attribute. String className = reader.getAttributeValue(null, "class"); implementation.setPOJOName(className); - + // Mark the POJO model unresolved to track the fact that it's not // completely initialized, its class is not loaded yet and services // and references not initialized either implementation.setUnresolved(true); - + // Skip to end element while (reader.hasNext()) { if (reader.next() == END_ELEMENT && IMPLEMENTATION_POJO.equals(reader.getName())) { break; } } - + return implementation; } public void resolve(POJOImplementation implementation, ModelResolver resolver) throws ContributionResolveException { - + // Resolve the POJO implementation - + // First resolve its class ClassReference classReference = new ClassReference(implementation.getPOJOName()); classReference = resolver.resolveModel(ClassReference.class, classReference); @@ -123,21 +123,21 @@ public class POJOImplementationProcessor implements StAXArtifactProcessor element - policyProcessor.writePolicyPrefixes(implementation, writer); writer.writeStartElement(IMPLEMENTATION_POJO.getNamespaceURI(), IMPLEMENTATION_POJO.getLocalPart()); policyProcessor.writePolicyAttributes(implementation, writer); - + if (implementation.getPOJOName() != null) { writer.writeAttribute("class", implementation.getPOJOName()); } - + writer.writeEndElement(); } } -- cgit v1.2.3