diff options
Diffstat (limited to 'branches/sca-java-1.x/modules/binding-jms/src')
3 files changed, 61 insertions, 39 deletions
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<ConfiguredOperation> configuredOperations = new ArrayList<ConfiguredOperation>(); + // 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<String, Map<String, BindingProperty>> operationPropertiesProperties = new HashMap<String, Map<String,BindingProperty>>(); 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<JMSBinding> { +public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<JMSBinding> { private PolicyFactory policyFactory; private PolicyAttachPointProcessor policyProcessor; private ConfiguredOperationProcessor configuredOperationProcessor; @@ -256,11 +257,11 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { 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<JMSBinding> { 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<JMSBinding> { // 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<JMSBinding> { public void write(JMSBinding jmsBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { // Write a <binding.jms> - 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<JMSBinding> { 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<JMSBinding> { 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 |