diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-02 22:45:54 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-02 22:45:54 +0000 |
commit | 6b614afbc3f08ded00a70bf9cf976d9bad12b4a7 (patch) | |
tree | 410ae74a08c76bae0e4b868c6e56bcbd2140e717 | |
parent | 5dc6635594ad4a6f08ecf61ac30b82333a418686 (diff) |
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
Diffstat (limited to '')
19 files changed, 475 insertions, 428 deletions
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<Impleme public void write(ImplementationXYZ implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { // Write <implementation.xyz> 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<ConfiguredOperation>, 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 <operation> 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<Confi break; } } - + return configuredOp; } - + public void write(ConfiguredOperation configuredOperation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { // Write an <operation> - policyProcessor.writePolicyPrefixes(configuredOperation, writer); writer.writeStartElement(Constants.SCA10_NS, OPERATION); policyProcessor.writePolicyAttributes(configuredOperation, writer); @@ -91,15 +90,15 @@ public class ConfiguredOperationProcessor implements StAXArtifactProcessor<Confi } writer.writeEndElement(); } - + public void resolve(ConfiguredOperation configuredOperation, ModelResolver resolver) throws ContributionResolveException { } - + public QName getArtifactType() { return OPERATION_QNAME; } - + public Class<ConfiguredOperation> 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<PolicySet> applicablePolicySets = policySetAttachPoint.getApplicablePolicySets(); @@ -140,7 +140,7 @@ public class PolicyAttachPointProcessor extends BaseStAXArtifactProcessor implem } } } - + /** * Write policies * @param attachPoint @@ -160,15 +160,6 @@ public class PolicyAttachPointProcessor extends BaseStAXArtifactProcessor implem } /** - * 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 * @param operation @@ -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<Intent> requiredIntents = new ArrayList<Intent>(); 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<PolicySet> resolvedPolicySets = new ArrayList<PolicySet>(); 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<SCABinding>, Constants{ - + private SCABindingFactory scaBindingFactory; private ExtensionFactory extensionFactory; private PolicyFactory policyFactory; private IntentAttachPointTypeFactory intentAttachPointTypeFactory; - private PolicyAttachPointProcessor policyProcessor; + private PolicyAttachPointProcessor policyProcessor; private StAXAttributeProcessor<Object> 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<SCABinding>, 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<SCABinding>, 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<SCABinding>, 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<SCABinding>, C scaBinding.getAttributeExtensions().add(attributeExtension); } } - } + } // Skip to end element while (reader.hasNext()) { @@ -137,15 +137,14 @@ public class SCABindingProcessor implements StAXArtifactProcessor<SCABinding>, 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 <binding.sca> - policyProcessor.writePolicyPrefixes(scaBinding, writer); writer.writeStartElement(Constants.SCA10_NS, BINDING_SCA); policyProcessor.writePolicyAttributes(scaBinding, writer); @@ -153,20 +152,20 @@ public class SCABindingProcessor implements StAXArtifactProcessor<SCABinding>, 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<XMLType>(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN); + addDataType(dataTypes, dt, helpers); + } + } + seeAlso = getSeeAlso(javaInterface.getCallbackClass()); + if (seeAlso != null) { + for (Class<?> cls : seeAlso) { + DataType dt = new DataTypeImpl<XMLType>(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<WebServ private ConfiguredOperationProcessor configuredOperationProcessor; private StAXAttributeProcessor<Object> 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<WebServ this.intentAttachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); this.monitor = monitor; this.configuredOperationProcessor = new ConfiguredOperationProcessor(modelFactories, this.monitor); - + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); StAXAttributeProcessorExtensionPoint attributeExtensionPoint = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); this.extensionAttributeProcessor = new ExtensibleStAXAttributeProcessor(attributeExtensionPoint ,inputFactory, outputFactory, this.monitor); } - + /** * Report a warning. - * + * * @param problem * @param model * @param message data @@ -122,10 +122,10 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ monitor.problem(problem); } } - + /** * Report an error. - * + * * @param problem * @param model * @param message data @@ -134,12 +134,12 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ if (monitor != null) { Problem problem = new ProblemImpl(this.getClass().getName(), "binding-wsxml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); - } + } } /** * Report an exception. - * + * * @param problem * @param model * @param exception @@ -148,7 +148,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ if (monitor != null) { Problem problem = new ProblemImpl(this.getClass().getName(), "binding-wsxml-validation-messages", Severity.ERROR, model, message, ex); monitor.problem(problem); - } + } } public WebServiceBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { @@ -237,12 +237,12 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ // Read wsdlLocation wsBinding.setLocation(reader.getAttributeValue(WSDLI_NS, WSDL_LOCATION)); - + // Handle extended attributes for (int a = 0; a < reader.getAttributeCount(); a++) { QName attributeName = reader.getAttributeName(a); if( attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI() != WSDLI_NS && 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; @@ -294,7 +294,6 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ XMLStreamException { // Write a <binding.ws> - policyProcessor.writePolicyPrefixes(wsBinding, writer); writer.writeStartElement(Constants.SCA10_NS, BINDING_WS); policyProcessor.writePolicyAttributes(wsBinding, writer); @@ -361,7 +360,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ extensionAttributeProcessor.write(extension, writer); } } - + if (wsBinding.getEndPointReference() != null) { EndPointReferenceHelper.writeEndPointReference(wsBinding.getEndPointReference(), writer); } @@ -370,10 +369,10 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ } public void resolve(WebServiceBinding model, ModelResolver resolver) throws ContributionResolveException { - + if (model == null || !model.isUnresolved()) return; - + WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); wsdlDefinition.setUnresolved(true); wsdlDefinition.setNamespace(model.getNamespace()); @@ -384,7 +383,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ ContributionResolveException ce = new ContributionResolveException(e.getCause()); error("ContributionResolveException", wsdlDefinition, ce); //throw ce; - } + } if (resolved != null && !resolved.isUnresolved()) { wsdlDefinition.setDefinition(resolved.getDefinition()); @@ -435,8 +434,8 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ ContributionResolveException ce = new ContributionResolveException("WSDL binding operation output name " + operation.getOutput().getName() + " does not match with PortType Definition"); error("ContributionResolveException", wsdlDefinition, ce); } - } - + } + WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); WSDLInterface wsdlInterface = null; try { @@ -444,7 +443,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ interfaceContract.setInterface(wsdlInterface); model.setBindingInterfaceContract(interfaceContract); } catch (InvalidInterfaceException e) { - warning("InvalidInterfaceException", wsdlFactory, model.getName()); + warning("InvalidInterfaceException", wsdlFactory, model.getName()); } } } diff --git a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java b/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java index 70398deaa9..d326324a5d 100644 --- a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java +++ b/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java @@ -6,15 +6,15 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations - * under the License. + * under the License. */ package org.apache.tuscany.sca.contribution.processor.xml; @@ -60,7 +60,7 @@ public class XMLDocumentStreamReader implements XMLStreamReader { } this.realReader = realReader; - + if (realReader instanceof XMLFragmentStreamReader) { ((XMLFragmentStreamReader)realReader).init(); } @@ -142,7 +142,11 @@ public class XMLDocumentStreamReader implements XMLStreamReader { } public String getCharacterEncodingScheme() { + if (isDelegating()) { return realReader.getCharacterEncodingScheme(); + } else { + return "UTF-8"; + } } public String getElementText() throws XMLStreamException { @@ -412,7 +416,7 @@ public class XMLDocumentStreamReader implements XMLStreamReader { state = STATE_COMPLETED; } else if (!realReader.hasNext()) { state = STATE_COMPLETE_AT_NEXT; - } + } if (fragment && returnEvent == END_ELEMENT) { level--; if (level == -1) { diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java index 84ac93313d..a451316883 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java @@ -208,7 +208,7 @@ public abstract class BaseStAXArtifactProcessor { break; } } - writer.setPrefix(prefix, uri); + // writer.setPrefix(prefix, uri); return prefix; } @@ -484,7 +484,7 @@ public abstract class BaseStAXArtifactProcessor { break; } } - writer.setPrefix(prefix, uri); + // writer.setPrefix(prefix, uri); writer.writeNamespace(prefix, uri); return prefix + ":" + qname.getLocalPart(); } @@ -516,7 +516,7 @@ public abstract class BaseStAXArtifactProcessor { break; } } - writer.setPrefix(prefix, uri); + // writer.setPrefix(prefix, uri); writer.writeNamespace(prefix, uri); } } diff --git a/branches/sca-java-1.x/modules/databinding-jaxb/pom.xml b/branches/sca-java-1.x/modules/databinding-jaxb/pom.xml index e10d4ac495..fea6048954 100644 --- a/branches/sca-java-1.x/modules/databinding-jaxb/pom.xml +++ b/branches/sca-java-1.x/modules/databinding-jaxb/pom.xml @@ -39,13 +39,11 @@ <artifactId>tuscany-databinding</artifactId> <version>1.6-SNAPSHOT</version> </dependency> - <!-- <dependency> <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-interface-java-xml</artifactId> + <artifactId>tuscany-interface-java</artifactId> <version>1.6-SNAPSHOT</version> </dependency> - --> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> 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<DataType> getDataTypes(Operation op, boolean useWrapper) { List<DataType> dataTypes = new ArrayList<DataType>(); 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<XMLType>(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN)); + } + } + seeAlso = getSeeAlso(javaInterface.getCallbackClass()); + if (seeAlso != null) { + for (Class<?> cls : seeAlso) { + dataTypes.add(new DataTypeImpl<XMLType>(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<JavaIm this.configuredOperationProcessor = new ConfiguredOperationProcessor(modelFactories, this.monitor); this.extensionAttributeProcessor = extensionAttributeProcessor; } - + /** * Report a error. - * + * * @param problems * @param message * @param model @@ -110,12 +110,12 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm if (monitor != null) { Problem problem = new ProblemImpl(this.getClass().getName(), "impl-javaxml-validation-messages", Severity.ERROR, model, message,(Object[])messageParameters); monitor.problem(problem); - } + } } - + /** * Report a exception. - * + * * @param problems * @param message * @param model @@ -124,32 +124,32 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm if (monitor != null) { Problem problem = new ProblemImpl(this.getClass().getName(), "impl-javaxml-validation-messages", Severity.ERROR, model, message, ex); monitor.problem(problem); - } + } } public JavaImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { // Read an <implementation.java> 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<JavaIm } } - + // read operation elements if exists or skip unto end element int event; @@ -193,7 +193,6 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm XMLStreamException { // Write an <implementation.java> - policyProcessor.writePolicyPrefixes(javaImplementation, writer); writer.writeStartElement(Constants.SCA10_NS, IMPLEMENTATION_JAVA); policyProcessor.writePolicyAttributes(javaImplementation, writer); @@ -207,7 +206,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm extensionAttributeProcessor.write(extension, writer); } } - + writer.writeEndElement(); } @@ -222,8 +221,8 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm //throw new ContributionResolveException(new ClassNotFoundException(javaImplementation.getName())); return; } - - javaImplementation.setJavaClass(javaClass); + + javaImplementation.setJavaClass(javaClass); try { javaFactory.createJavaImplementation(javaImplementation, javaImplementation.getJavaClass()); @@ -233,7 +232,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm //throw ce; return; } - + javaImplementation.setUnresolved(false); mergeComponentType(resolver, javaImplementation); diff --git a/branches/sca-java-1.x/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java b/branches/sca-java-1.x/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java index 646b5db617..d1c72861e3 100644 --- a/branches/sca-java-1.x/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java +++ b/branches/sca-java-1.x/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.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; @@ -35,7 +35,7 @@ import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; /** * Test writing Java implementations. - * + * * @version $Rev$ $Date$ */ public class WriteTestCase extends TestCase { @@ -43,22 +43,24 @@ public class WriteTestCase extends TestCase { private StAXArtifactProcessor<Object> 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. --> <composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:calc="http://sample.calculator" requires="cns:tuscanyIntent_1" targetNamespace="http://sample.calculator" - xmlns:cns="http://test" + xmlns:cns="http://test" name="Calculator"> <service name="CalculatorService" promote="CalculatorServiceComponent"> @@ -51,16 +51,16 @@ <component name="DivideServiceComponent"> <implementation.java class="calculator.DivideServiceImpl"/> </component> - + <component name="AnotherCalculatorServiceComponent" requires="cns:tuscanyIntent_4"> <implementation.java class="calculator.CalculatorServiceImpl" requires="cns:tuscanyIntent_5"> <operation name="add" requires="cns:tuscanyIntent_6"/> - </implementation.java> + </implementation.java> </component> - + <component name="YetAnotherCalculatorServiceComponent" requires="cns:tuscanyIntent_4"> <implementation.java class="calculator.CalculatorServiceImpl" requires="cns:tuscanyIntent_6.qualified1"> <operation name="add" requires="cns:tuscanyIntent_6.qualified2" policySets="cns:tuscanyPolicySet_4"/> - </implementation.java> + </implementation.java> </component> </composite> 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 <implementation.jee> - 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 <implementation.spring.../> - * 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<SpringImplementation> { - - 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. - * - * <implementation.spring.../> 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 - * <implementation.spring location="..." /> - */ - public void write(SpringImplementation springImplementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - - // Write <implementation.spring> - 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<SpringImplementation> getModelType() { - return SpringImplementation.class; - } - -} // end class SpringArtifactProcessor +import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ * SpringArtifactProcessor is responsible for processing the XML of an <implementation.spring.../>
+ * 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<SpringImplementation> {
+
+ 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.
+ *
+ * <implementation.spring.../> 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
+ * <implementation.spring location="..." />
+ */
+ public void write(SpringImplementation springImplementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write <implementation.spring>
+ 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<SpringImplementation> 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<WidgetImplementation> { 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<Widg // Read the location attribute specifying the location of the resources String location = reader.getAttributeValue(null, "location"); - if (location != null) { + if (location != null) { implementation = implementationFactory.createWidgetImplementation(); implementation.setLocation(location); implementation.setUnresolved(true); @@ -131,7 +131,7 @@ public class WidgetImplementationProcessor implements StAXArtifactProcessor<Widg } public void resolve(WidgetImplementation implementation, ModelResolver resolver) throws ContributionResolveException { - + if (implementation != null) { // Resolve the resource directory location Artifact artifact = contributionFactory.createArtifact(); @@ -139,13 +139,13 @@ public class WidgetImplementationProcessor implements StAXArtifactProcessor<Widg Artifact resolved = resolver.resolveModel(Artifact.class, artifact); if (resolved.getLocation() != null) { try { - implementation.setLocationURL(new URL(resolved.getLocation())); - + implementation.setLocationURL(new URL(resolved.getLocation())); + //introspect implementation - WidgetImplementationIntrospector widgetIntrospector = + WidgetImplementationIntrospector widgetIntrospector = new WidgetImplementationIntrospector(assemblyFactory, implementation); widgetIntrospector.introspectImplementation(); - + implementation.setUnresolved(false); } catch (IOException e) { ContributionResolveException ce = new ContributionResolveException(e); @@ -154,23 +154,22 @@ public class WidgetImplementationProcessor implements StAXArtifactProcessor<Widg } } else { error("CouldNotResolveLocation", resolver, implementation.getLocation()); - //throw new ContributionResolveException("Could not resolve implementation.widget location: " + implementation.getLocation()); + //throw new ContributionResolveException("Could not resolve implementation.widget location: " + implementation.getLocation()); } } } public void write(WidgetImplementation implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - + // Write <implementation.widget> - 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<EchoBinding> 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 <implementation.pojo> * 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<POJOImplementation> { 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<POJOIm } public POJOImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { - + // Read an <implementation.pojo> 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<POJOIm throw new ContributionResolveException("Class could not be resolved: " + implementation.getPOJOName()); } implementation.setPOJOClass(pojoClass); - + // Check to see if we have a .componentType file describing the POJO class ComponentType componentType = assemblyFactory.createComponentType(); componentType.setUnresolved(true); componentType.setURI(implementation.getURI() + ".componentType"); componentType = resolver.resolveModel(ComponentType.class, componentType); if (!componentType.isUnresolved()) { - + // We have a component type description, merge it into the POJO model implementation.getServices().addAll(componentType.getServices()); implementation.getReferences().addAll(componentType.getReferences()); implementation.getProperties().addAll(componentType.getProperties()); - + } else { - + // We have no component type description, simply introspect the POJO and // create a single Service for it Service service = assemblyFactory.createService(); @@ -153,22 +153,21 @@ public class POJOImplementationProcessor implements StAXArtifactProcessor<POJOIm service.setInterfaceContract(interfaceContract); implementation.getServices().add(service); } - + // Mark the implementation resolved now implementation.setUnresolved(false); } public void write(POJOImplementation implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - + // Write <implementation.pojo> 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(); } } |