From 3e33552da0eaa898a0d8773e7f22862985f8be63 Mon Sep 17 00:00:00 2001 From: beckerdo Date: Wed, 4 Mar 2009 15:44:36 +0000 Subject: TUSCANY-2897 JMSBinding model should be QNames not Strings git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@750052 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/resources/definitions.xml | 5 +-- .../tuscany/sca/assembly/DefinitionElement.java | 40 +++++++++++++++++ .../tuscany/sca/binding/jms/impl/JMSBinding.java | 47 +++++++++++++++---- .../sca/binding/jms/impl/JMSBindingProcessor.java | 52 +++++++++------------- .../binding-jms-validation-messages.properties | 1 + .../definitions/xml/SCADefinitionsProcessor.java | 7 +++ 6 files changed, 110 insertions(+), 42 deletions(-) create mode 100644 branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefinitionElement.java diff --git a/branches/sca-java-1.x/itest/jms-definitions/src/main/resources/definitions.xml b/branches/sca-java-1.x/itest/jms-definitions/src/main/resources/definitions.xml index ff389c7014..07b9f4aaa8 100644 --- a/branches/sca-java-1.x/itest/jms-definitions/src/main/resources/definitions.xml +++ b/branches/sca-java-1.x/itest/jms-definitions/src/main/resources/definitions.xml @@ -18,10 +18,9 @@ * under the License. --> + targetNamespace="http://jms" > - + diff --git a/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefinitionElement.java b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefinitionElement.java new file mode 100644 index 0000000000..366a736ad8 --- /dev/null +++ b/branches/sca-java-1.x/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefinitionElement.java @@ -0,0 +1,40 @@ + /* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +/** + * Contains information inherited from an SCA definitions document. + * + * @version $Rev$ $Date$ + */ +public interface DefinitionElement { + /** + * Returns the target namespace inherited from an SCA definition document + * @return the namespace + */ + String getTargetNamespace(); + + /** + * Sets the target namespace inherited from an SCA definition document + * + * @param ns the target namespace for this SCA Definition + */ + void setTargetNamespace(String ns); + +} diff --git a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java index 2236c7fee7..92350a6310 100644 --- a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java +++ b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java @@ -24,9 +24,11 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import javax.xml.namespace.QName; import java.util.TreeSet; import org.apache.tuscany.sca.assembly.BindingRRB; +import org.apache.tuscany.sca.assembly.DefinitionElement; import org.apache.tuscany.sca.assembly.ConfiguredOperation; import org.apache.tuscany.sca.assembly.OperationSelector; import org.apache.tuscany.sca.assembly.OperationsConfigurator; @@ -42,7 +44,7 @@ import org.apache.tuscany.sca.policy.PolicySetAttachPoint; * @version $Rev$ $Date$ */ -public class JMSBinding implements BindingRRB, PolicySetAttachPoint, OperationsConfigurator { +public class JMSBinding implements BindingRRB, PolicySetAttachPoint, OperationsConfigurator, DefinitionElement { @Override public Object clone() throws CloneNotSupportedException { @@ -66,6 +68,9 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint, OperationsC // properties required to describe configured operations private List configuredOperations = new ArrayList(); + // properties required by DefinitionElement @575803A + private String targetNamespace; + // Properties required to describe the JMS binding model private String correlationScheme = JMSBindingConstants.CORRELATE_MSG_ID; @@ -133,8 +138,8 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint, OperationsC private Map> operationPropertiesProperties = new HashMap>(); private String jmsSelector; - private String requestConnectionName; - private String responseConnectionName; + private QName requestConnectionName; + private QName responseConnectionName; private JMSBinding requestConnectionBinding; private JMSBinding responseConnectionBinding; @@ -646,18 +651,19 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint, OperationsC this.jmsSelector = jmsSelector; } - public String getRequestConnectionName() { + public QName getRequestConnectionName() { return requestConnectionName; } - public void setRequestConnectionName(String requestConnectionName) { + public void setRequestConnectionName(QName requestConnectionName) { this.requestConnectionName = requestConnectionName; } - public void setResponseConnectionName(String responseConnectionName) { + public void setResponseConnectionName(QName responseConnectionName) { this.responseConnectionName = responseConnectionName; } - public String getResponseConnectionName() { + + public QName getResponseConnectionName() { return responseConnectionName; } @@ -740,6 +746,21 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint, OperationsC this.configuredOperations = configuredOperations; } + public String getTargetNamespace() { + return targetNamespace; + } + + public void setTargetNamespace(String ns) { + targetNamespace = ns; + } + + // hashCode() is here because binding elements in definitions documents are added + // to the model resolver hashmap. The namespace and name are keys. + @Override + public int hashCode() { + return (String.valueOf(getTargetNamespace()) + String.valueOf(getName())).hashCode(); + } + @Override public boolean equals( Object object ) { return ( object instanceof JMSBinding ) && equals( (JMSBinding) object ); @@ -752,10 +773,20 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint, OperationsC * @return boolean stating whether objects are equal */ public boolean equals( JMSBinding binding ) { + // If the target namespace is set, this binding came from a definitions document. + // The target namespace and name are used as keys for doing model resolver hashmap lookups. + // Only the target namespace and name can be compared. + if (this.targetNamespace != null) { + if ( !optStringEquals( this.targetNamespace, binding.getTargetNamespace() )) return false; + if ( !optStringEquals( this.name, binding.getName() )) return false; + return true; + } + // Test all fields for equality. // First test simple fields to quickly weed out mismatches. if ( !optStringEquals( this.uri, binding.getURI() )) return false; if ( !optStringEquals( this.name, binding.getName() )) return false; + if ( !optStringEquals( this.targetNamespace, binding.getTargetNamespace() )) return false; if ( !optStringEquals( this.destinationName, binding.getDestinationName() )) return false; if ( !optStringEquals( this.correlationScheme, binding.getCorrelationScheme() )) return false; if ( !optStringEquals( this.initialContextFactoryName, binding.getInitialContextFactoryName() )) return false; @@ -814,7 +845,7 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint, OperationsC * @param p2 property list 2 * @return whether or not properties are equal */ - public static boolean optStringEquals( String s1, String s2 ) { + public static boolean optStringEquals( Object s1, Object s2 ) { if ( s1 == null && s2 == null ) return true; if ( s1 != null && s2 == null ) return false; if ( s1 == null && s2 != null ) return false; diff --git a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java index 6d6a14e191..10d86e5536 100644 --- a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java +++ b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java @@ -48,6 +48,7 @@ import org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObje import org.apache.tuscany.sca.binding.jms.wireformat.jmstext.WireFormatJMSText; import org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; @@ -131,7 +132,7 @@ import org.apache.tuscany.sca.policy.PolicyFactory; * @version $Rev$ $Date$ */ -public class JMSBindingProcessor implements StAXArtifactProcessor { +public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { private PolicyFactory policyFactory; private PolicyAttachPointProcessor policyProcessor; private ConfiguredOperationProcessor configuredOperationProcessor; @@ -256,11 +257,11 @@ public class JMSBindingProcessor implements StAXArtifactProcessor { String requestConnectionName = reader.getAttributeValue(null, "requestConnection"); if (requestConnectionName != null && requestConnectionName.length() > 0) { - jmsBinding.setRequestConnectionName(requestConnectionName); + jmsBinding.setRequestConnectionName(getQNameValue(reader, requestConnectionName)); } String responseConnectionName = reader.getAttributeValue(null, "responseConnection"); if (responseConnectionName != null && responseConnectionName.length() > 0) { - jmsBinding.setResponseConnectionName(responseConnectionName); + jmsBinding.setResponseConnectionName(getQNameValue(reader, responseConnectionName)); } // Read sub-elements of binding.jms @@ -361,28 +362,23 @@ public class JMSBindingProcessor implements StAXArtifactProcessor { public void resolve(JMSBinding model, ModelResolver resolver) throws ContributionResolveException { if (model.getRequestConnectionName() != null) { - model.setRequestConnectionBinding(getConnectionBinding(model.getRequestConnectionName(), resolver)); + model.setRequestConnectionBinding(getConnectionBinding(model, "requestConnection", model.getRequestConnectionName(), resolver)); } if (model.getResponseConnectionName() != null) { - model.setResponseConnectionBinding(getConnectionBinding(model.getResponseConnectionName(), resolver)); + model.setResponseConnectionBinding(getConnectionBinding(model, "responseConnection", model.getResponseConnectionName(), resolver)); } } @SuppressWarnings("unchecked") - private JMSBinding getConnectionBinding(String bindingName, ModelResolver resolver) { - if (resolver instanceof ExtensibleModelResolver) { - DefaultModelResolver dr = (DefaultModelResolver)((ExtensibleModelResolver) resolver).getDefaultModelResolver(); - Map models = dr.getModels(); - for (Object o : models.keySet()) { - if (o instanceof JMSBinding) { - JMSBinding binding = (JMSBinding) o; - if (bindingName.equals(binding.getName())) { - return binding; - } - } - } - } - return null; + private JMSBinding getConnectionBinding(JMSBinding model, String attrName, QName bindingName, ModelResolver resolver) { + JMSBinding binding = new JMSBinding(); + binding.setTargetNamespace(bindingName.getNamespaceURI()); + binding.setName(bindingName.getLocalPart()); + binding.setUnresolved(true); + binding = resolver.resolveModel(JMSBinding.class, binding); + if (binding.isUnresolved()) + error("BindingNotFound", model, attrName, bindingName); + return binding; } private void parseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { @@ -833,8 +829,8 @@ public class JMSBindingProcessor implements StAXArtifactProcessor { // 156 • /binding.jms/@responseConnection – identifies a binding.jms element that is present in a // 157 definition document, whose response child element is used to define the values for this binding. In // 158 this case this binding.jms element MUST NOT contain a response element. - String responseConnectionName = jmsBinding.getResponseConnectionName(); - if (( responseConnectionName != null ) && ( responseConnectionName.length() > 0 )) { + QName responseConnectionName = jmsBinding.getResponseConnectionName(); + if (( responseConnectionName != null ) && ( responseConnectionName.getLocalPart().length() > 0 )) { String responseDestinationName = jmsBinding.getResponseDestinationName(); if (( responseDestinationName != null ) && (responseDestinationName.length() > 0)) { error("ResponseAttrElement", jmsBinding, responseConnectionName, responseDestinationName ); @@ -870,7 +866,9 @@ public class JMSBindingProcessor implements StAXArtifactProcessor { public void write(JMSBinding jmsBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { // Write a - writer.writeStartElement(Constants.SCA10_NS, JMSBindingConstants.BINDING_JMS); + writeStart(writer, Constants.SCA10_NS, JMSBindingConstants.BINDING_JMS, + new XAttr("requestConnection", jmsBinding.getRequestConnectionName()), + new XAttr("responseConnection", jmsBinding.getResponseConnectionName())); if (jmsBinding.getName() != null) { writer.writeAttribute("name", jmsBinding.getName()); @@ -902,14 +900,6 @@ public class JMSBindingProcessor implements StAXArtifactProcessor { writer.writeAttribute("jndiURL", jmsBinding.getJndiURL()); } - if ( jmsBinding.getRequestConnectionName() != null ) { - writer.writeAttribute("requestConnection", jmsBinding.getRequestConnectionName()); - } - - if ( jmsBinding.getResponseConnectionName() != null ) { - writer.writeAttribute("responseConnection", jmsBinding.getResponseConnectionName()); - } - if ( jmsBinding.containsHeaders() ) { writeHeaders( jmsBinding, writer); } @@ -945,7 +935,7 @@ public class JMSBindingProcessor implements StAXArtifactProcessor { writeConfiguredOperations( jmsBinding, writer ); - writer.writeEndElement(); + writeEnd(writer); } /** diff --git a/branches/sca-java-1.x/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties b/branches/sca-java-1.x/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties index cd2a5f30ed..75bf06df1f 100644 --- a/branches/sca-java-1.x/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties +++ b/branches/sca-java-1.x/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties @@ -46,3 +46,4 @@ DestinationQueueContradiction = Destination type queue contradicts connection fa DestinationTopicContradiction = Destination type topic contradicts connection factory name: {0} ConnectionFactoryActivationSpecContradiction = Connection factory \"{0}\" and activation specification \"{0}\" are mutually exclusive ResponseAttrElement = Response connection \"{0}\" and response element \"{1}\" are mutually exclusive +BindingNotFound = {0} refers to a binding definition {1} which is not found diff --git a/branches/sca-java-1.x/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java b/branches/sca-java-1.x/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java index b87d890866..0bea894854 100644 --- a/branches/sca-java-1.x/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java +++ b/branches/sca-java-1.x/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java @@ -32,6 +32,7 @@ import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.DefinitionElement; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -123,6 +124,8 @@ public class SCADefinitionsProcessor extends BaseStAXArtifactProcessor implement definitions.getPolicySets().add(policySet); } else if ( extension instanceof Binding ) { Binding binding = (Binding)extension; + if (binding instanceof DefinitionElement) + ((DefinitionElement)binding).setTargetNamespace(targetNamespace); definitions.getBindings().add(binding); } else if ( extension instanceof IntentAttachPointType ) { IntentAttachPointType type = (IntentAttachPointType)extension; @@ -217,6 +220,10 @@ public class SCADefinitionsProcessor extends BaseStAXArtifactProcessor implement resolver.addModel(implType); } + for (Object binding : scaDefns.getBindings() ) { + resolver.addModel(binding); + } + // now resolve everything to ensure that any references between // artifacts are satisfied -- cgit v1.2.3