diff options
Diffstat (limited to 'branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl')
4 files changed, 986 insertions, 0 deletions
diff --git a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java new file mode 100644 index 0000000000..3019ad676f --- /dev/null +++ b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java @@ -0,0 +1,540 @@ +/* + * 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.binding.jms.impl; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.List; + +import javax.jms.DeliveryMode; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; + +/** + * Models a binding to a JMS resource. + */ + +public class JMSBinding implements Binding { + + /** + * Clone the binding + */ + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + // properties required to implement the Tuscany + // binding extension SPI + private String uri = null; + private String name = null; + private boolean unresolved = false; + private List<Object> extensions = new ArrayList<Object>(); + + // Properties required to describe the JMS + // binding model + + // <binding.jms correlationScheme="string"? Not yet implemented in binding + // initialContextFactory="xs:anyURI"? + // jndiURL="xs:anyURI"? + // requestConnection="QName"? Not yet implemented in binding + // responseConnection="QName"? Not yet implemented in binding + // operationProperties="QName"? Not yet implemented in binding + // ...> + private String correlationScheme = JMSBindingConstants.CORRELATE_MSG_ID; + private String initialContextFactoryName = JMSBindingConstants.DEFAULT_CONTEXT_FACTORY_NAME; + private String jndiURL = JMSBindingConstants.DEFAULT_JNDI_URL; + // private String requestConnection = null; + // private String responseConnection = null; + // private String operationProperties = null; + // + // <destination name="xs:anyURI" + // type="string"? Not yet implemented in binding + // create="string"?> Not yet implemented in binding + // <property name="NMTOKEN" Not yet implemented in binding + // type="NMTOKEN">* Not yet implemented in binding + // </destination>? + private String destinationName = JMSBindingConstants.DEFAULT_DESTINATION_NAME; + private String destinationType = JMSBindingConstants.DESTINATION_TYPE_QUEUE; + private String destinationCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + // + // <connectionFactory name="xs:anyURI" Not yet implemented in binding + // create="string"?> Not yet implemented in binding + // <property name="NMTOKEN" Not yet implemented in binding + // type="NMTOKEN">* Not yet implemented in binding + // </connectionFactory>? + private String connectionFactoryName = JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME; + private String connectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + // + // <activationSpec name="xs:anyURI" Not yet implemented in binding + // create="string"?> Not yet implemented in binding + // <property name="NMTOKEN" Not yet implemented in binding + // type="NMTOKEN">* Not yet implemented in binding + // </activationSpec>? + private String activationSpecName = null; + private String activationSpecCreate = null; + // + // <response> + // <destination name="xs:anyURI" + // type="string"? Not yet implemented in binding + // create="string"?> Not yet implemented in binding + // <property name="NMTOKEN" Not yet implemented in binding + // type="NMTOKEN">* Not yet implemented in binding + // </destination>? + private String responseDestinationName = JMSBindingConstants.DEFAULT_RESPONSE_DESTINATION_NAME; + private String responseDestinationType = JMSBindingConstants.DESTINATION_TYPE_QUEUE; + private String responseDestinationCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + // + // <connectionFactory name="xs:anyURI" Not yet implemented in binding + // create="string"?> Not yet implemented in binding + // <property name="NMTOKEN" Not yet implemented in binding + // type="NMTOKEN">* Not yet implemented in binding + // </connectionFactory>? + private String responseConnectionFactoryName = JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME; + private String responseConnectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + // + // <activationSpec name="xs:anyURI" Not yet implemented in binding + // create="string"?> Not yet implemented in binding + // <property name="NMTOKEN" Not yet implemented in binding + // type="NMTOKEN">* Not yet implemented in binding + // </activationSpec>? + private String responseActivationSpecName = null; + private String responseActivationSpecCreate = null; + // </response>? + // + // <resourceAdapter name="NMTOKEN">? Not yet implemented in binding + // <property name="NMTOKEN" Not yet implemented in binding + // type="NMTOKEN">* Not yet implemented in binding + // </resourceAdapter>? + // private String resourceAdapterName = null; + // + // <headers JMSType="string"? Not yet implemented in binding + // JMSCorrelationId="string"? Not yet implemented in binding + // JMSDeliveryMode="string"? Not yet implemented in binding + // JMSTimeToLive="int"? Not yet implemented in binding + // JMSPriority="string"?> Not yet implemented in binding + // <property name="NMTOKEN" Not yet implemented in binding + // type="NMTOKEN">* Not yet implemented in binding + // </headers>? + // private String jmsType = null; + // private String jmsCorrelationId = null; + private int jmsDeliveryMode = DeliveryMode.NON_PERSISTENT; // Maps to javax.jms.DeliveryMode + private int jmsTimeToLive = JMSBindingConstants.DEFAULT_TIME_TO_LIVE; + private int jmsPriority = JMSBindingConstants.DEFAULT_PRIORITY; + // + // <operationProperties name="string" Not yet implemented in binding + // nativeOperation="string"?> Not yet implemented in binding + // <property name="NMTOKEN" Not yet implemented in binding + // type="NMTOKEN">* Not yet implemented in binding + // <headers JMSType="string"? Not yet implemented in binding + // JMSCorrelationId="string"? Not yet implemented in binding + // JMSDeliveryMode="string"? Not yet implemented in binding + // JMSTimeToLive="int"? Not yet implemented in binding + // JMSPriority="string"?> Not yet implemented in binding + // <property name="NMTOKEN" Not yet implemented in binding + // type="NMTOKEN">* Not yet implemented in binding + // </headers>? + // </operationProperties>* + // </binding.jms> + + // Other properties not directly related to the + // XML definition of the JMS binding + + // Provides the name of the factory that interfaces to the + // JMS API for us. + private String jmsResourceFactoryName = JMSBindingConstants.DEFAULT_RF_CLASSNAME; + + // Message processors used to deal with the request + // and response messages + public String requestMessageProcessorName = JMSBindingConstants.DEFAULT_MP_CLASSNAME; + public String responseMessageProcessorName = JMSBindingConstants.DEFAULT_MP_CLASSNAME; + + // The JMS message property used to hold the name of the + // operation being called + private String operationSelectorPropertyName = JMSBindingConstants.DEFAULT_OPERATION_PROP_NAME; + + // If the operation selector is derived automatically from the service + // interface it's stored here + private String operationSelectorName = null; + + // Set true if messages are sent/received in XML format + private boolean xmlFormat = true; + + // TODO ..... + private String replyTo; + + // Methods required by the Tuscany SPI + + /** + * No arg constructor used by the JSMBindingFactoryImpl to create JMS binding model objects + */ + public JMSBinding() { + super(); + } + + /** + * Returns the binding URI. + * + * @return the binding uri + */ + public String getURI() { + return this.uri; + } + + /** + * Sets the binding URI. + * + * @param uri the binding uri + */ + public void setURI(String uri) { + this.uri = uri; + } + + /** + * Returns the binding name. + * + * @return the binding name + */ + public String getName() { + return this.name; + } + + /** + * Sets the binding name. + * + * @param name the binding name + */ + public void setName(String name) { + this.name = name; + } + + public boolean isUnresolved() { + return this.unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public List<Object> getExtensions() { + return extensions; + } + + // Methods for getting/setting JMS binding model information + // as derived from the XML of the binding.jms element + + public void setCorrelationScheme(String correlationScheme) { + this.correlationScheme = correlationScheme; + } + + public String getCorrelationScheme() { + return correlationScheme; + } + + public String getInitialContextFactoryName() { + return initialContextFactoryName; + } + + public void setInitialContextFactoryName(String initialContextFactoryName) { + this.initialContextFactoryName = initialContextFactoryName; + } + + public String getJndiURL() { + return this.jndiURL; + } + + public void setJndiURL(String jndiURL) { + this.jndiURL = jndiURL; + } + + public String getDestinationName() { + return destinationName; + } + + public void setDestinationName(String destinationName) { + this.destinationName = destinationName; + } + + public String getDestinationType() { + return destinationType; + } + + public void setDestinationType(String destinationType) { + this.destinationType = destinationType; + } + + public String getDestinationCreate() { + return this.destinationCreate; + } + + public void setDestinationCreate(String create) { + this.destinationCreate = create; + } + + public String getConnectionFactoryName() { + return connectionFactoryName; + } + + public void setConnectionFactoryName(String connectionFactoryName) { + this.connectionFactoryName = connectionFactoryName; + } + + public String getConnectionFactoryCreate() { + return this.connectionFactoryCreate; + } + + public void setConnectionFactoryCreate(String create) { + this.connectionFactoryCreate = create; + } + + public String getActivationSpecName() { + return activationSpecName; + } + + public void setActivationSpecName(String activationSpecName) { + this.activationSpecName = activationSpecName; + } + + public String getActivationSpecCreate() { + return this.activationSpecCreate; + } + + public void setActivationSpecCreate(String create) { + this.activationSpecCreate = create; + } + + public String getResponseDestinationName() { + return this.responseDestinationName; + } + + public void setResponseDestinationName(String name) { + this.responseDestinationName = name; + } + + public String getResponseDestinationType() { + return this.responseDestinationType; + } + + public void setResponseDestinationType(String type) { + this.responseDestinationType = type; + } + + public String getResponseDestinationCreate() { + return this.responseDestinationCreate; + } + + public void setResponseDestinationCreate(String create) { + this.responseDestinationCreate = create; + } + + public String getResponseConnectionFactoryName() { + return responseConnectionFactoryName; + } + + public void setResponseConnectionFactoryName(String connectionFactoryName) { + this.responseConnectionFactoryName = connectionFactoryName; + } + + public String getResponseConnectionFactoryCreate() { + return this.responseConnectionFactoryCreate; + } + + public void setResponseConnectionFactoryCreate(String create) { + this.responseConnectionFactoryCreate = create; + } + + public String getResponseActivationSpecName() { + return responseActivationSpecName; + } + + public void setResponseActivationSpecName(String activationSpecName) { + this.responseActivationSpecName = activationSpecName; + } + + public String getResponseActivationSpecCreate() { + return this.responseActivationSpecCreate; + } + + public void setResponseActivationSpecCreate(String create) { + this.responseActivationSpecCreate = create; + } + + public int getDeliveryMode() { + return jmsDeliveryMode; + } + + public void setDeliveryMode(int deliveryMode) { + this.jmsDeliveryMode = deliveryMode; + } + + public int getTimeToLive() { + return jmsTimeToLive; + } + + public void setTimeToLive(int timeToLive) { + this.jmsTimeToLive = timeToLive; + } + + public int getPriority() { + return jmsPriority; + } + + public void setPriority(int priority) { + this.jmsPriority = priority; + } + + // operations to manage the other information required by the + // JMS binding + + public String getJmsResourceFactoryName() { + return jmsResourceFactoryName; + } + + public void setJmsResourceFactoryName(String jmsResourceFactoryName) { + this.jmsResourceFactoryName = jmsResourceFactoryName; + } + +// public JMSResourceFactory getJmsResourceFactory() { +// return (JMSResourceFactory)instantiate(null, jmsResourceFactoryName); +// } + + public void setRequestMessageProcessorName(String name) { + this.requestMessageProcessorName = name; + } + + public String getRequestMessageProcessorName() { + return requestMessageProcessorName; + } + + public JMSMessageProcessor getRequestMessageProcessor() { + return (JMSMessageProcessor)instantiate(null, requestMessageProcessorName); + } + + public void setResponseMessageProcessorName(String name) { + this.responseMessageProcessorName = name; + } + + public String getResponseMessageProcessorName() { + return responseMessageProcessorName; + } + + public JMSMessageProcessor getResponseMessageProcessor() { + return (JMSMessageProcessor)instantiate(null, responseMessageProcessorName); + } + + public String getOperationSelectorPropertyName() { + return operationSelectorPropertyName; + } + + public void setOperationSelectorPropertyName(String operationSelectorPropertyName) { + this.operationSelectorPropertyName = operationSelectorPropertyName; + } + + public String getOperationSelectorName() { + return operationSelectorName; + } + + public void setOperationSelectorName(String operationSelectorName) { + this.operationSelectorName = operationSelectorName; + } + + public boolean getXMLFormat() { + return xmlFormat; + } + + public void setXMLFormat(boolean b) { + this.xmlFormat = b; + } + + /** + * Used to create instances of the JMSResourceFactory and RequestMessageProcessor and ResponseMessageProcessor from + * sting based classname provided in the configuration + * + * @param cl classloader + * @param className the string based classname to load and instantiate + * @return the new object + */ + private Object instantiate(ClassLoader cl, String className) { + Object instance; + if (cl == null) { + cl = this.getClass().getClassLoader(); + } + + try { + Class clazz; + + try { + clazz = cl.loadClass(className); + } catch (ClassNotFoundException e) { + clazz = this.getClass().getClassLoader().loadClass(className); + } + + Constructor constructor = clazz.getDeclaredConstructor(new Class[] {JMSBinding.class}); + instance = constructor.newInstance(this); + + } catch (Throwable e) { + throw new JMSBindingException("Exception instantiating OperationAndDataBinding class", e); + } + + return instance; + } + + /** + * The validation rules for the JMS model are relatively complicated to they all live together here + */ + public void validate() throws JMSBindingException { + /* + * first fix up anything now the model has been read + */ + + if (getDestinationName().equals(JMSBindingConstants.DEFAULT_DESTINATION_NAME)) { + /* + * No desitnation name has been set so make sure that the runtime is able to create one automatically + */ + setDestinationCreate(JMSBindingConstants.CREATE_IF_NOT_EXIST); + } + + if (getResponseDestinationName().equals(JMSBindingConstants.DEFAULT_RESPONSE_DESTINATION_NAME)) { + /* + * No repsonse desitination name has been set so make sure that the runtime is able to create one + * automatically + */ + setResponseDestinationCreate(JMSBindingConstants.CREATE_IF_NOT_EXIST); + } + + /* + * Now some cross field validation + */ + + // connection factory doesn't contradict detsination type + // connection factory and activation spec are mutually exclusive + // TODO check spec for all validations + } + + // TODO... + + public String getReplyTo() { + return replyTo; + } + + public void setReplyTo(String replyTo) { + this.replyTo = replyTo; + } + +} diff --git a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java new file mode 100644 index 0000000000..0f4e309bf2 --- /dev/null +++ b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java @@ -0,0 +1,58 @@ +/* + * 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.binding.jms.impl; + +import java.util.Arrays; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorImpl; + +public interface JMSBindingConstants { + + // Contants used when describing the JMS binding + // model and for setting up defaults + public final static String BINDING_JMS = "binding.jms"; + public final static QName BINDING_JMS_QNAME = new QName(Constants.SCA10_NS, BINDING_JMS); + public final static String CORRELATE_MSG_ID = "requestmsgidtocorrelid"; + public final static String CORRELATE_CORRELATION_ID = "requestcorrelidtocorrelid"; + public final static String CORRELATE_NONE = "none"; + public final static List<String> VALID_CORRELATION_SCHEMES = + Arrays.asList(new String[] {CORRELATE_MSG_ID, CORRELATE_CORRELATION_ID, CORRELATE_NONE}); + public final static String DESTINATION_TYPE_QUEUE = "queue"; // 0 + public final static String DESTINATION_TYPE_TOPIC = "topic"; // 1 + public final static List<String> VALID_DESTINATION_TYPES = + Arrays.asList(new String[] {DESTINATION_TYPE_QUEUE, DESTINATION_TYPE_TOPIC}); + public final static String CREATE_ALWAYS = "always"; + public final static String CREATE_NEVER = "never"; + public final static String CREATE_IF_NOT_EXIST = "ifnotexist"; + public final static String DEFAULT_DESTINATION_NAME = "NODESTINATION"; + public final static String DEFAULT_RESPONSE_DESTINATION_NAME = "NORESPONSEDESTINATION"; + public final static String DEFAULT_CONNECTION_FACTORY_NAME = "ConnectionFactory"; + public final static String DEFAULT_CONTEXT_FACTORY_NAME = "org.apache.activemq.jndi.ActiveMQInitialContextFactory"; + public final static String DEFAULT_JNDI_URL = "tcp://localhost:61616"; + public final static int DEFAULT_TIME_TO_LIVE = 10000; // in milli seconds + public final static int DEFAULT_PRIORITY = 1; + public final static String DEFAULT_RF_CLASSNAME = "org.apache.tuscany.sca.host.jms.activemq.JMSResourceFactoryImpl"; + public final static String DEFAULT_MP_CLASSNAME = JMSMessageProcessorImpl.class.getName(); + public final static String DEFAULT_OPERATION_PROP_NAME = "scaOperationName"; + +} diff --git a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingException.java b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingException.java new file mode 100644 index 0000000000..60cd33d9bb --- /dev/null +++ b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingException.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.binding.jms.impl; + +public class JMSBindingException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public JMSBindingException() { + super(); + } + + public JMSBindingException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + + public JMSBindingException(String arg0) { + super(arg0); + } + + public JMSBindingException(Throwable arg0) { + super(arg0); + } + +} diff --git a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java new file mode 100644 index 0000000000..c8fecd1d23 --- /dev/null +++ b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java @@ -0,0 +1,348 @@ +/* + * 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.binding.jms.impl; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_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.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.policy.PolicyFactory; + +/** + * A processor to read the XML that describes the JMS binding... + * + * <binding.jms correlationScheme="string"? + * initialContextFactory="xs:anyURI"? + * jndiURL="xs:anyURI"? + * requestConnection="QName"? + * responseConnection="QName"? + * operationProperties="QName"? + * ...> + * + * <destination name="xs:anyURI" type="string"? create="string"?> + * <property name="NMTOKEN" type="NMTOKEN">* + * </destination>? + * + * <connectionFactory name="xs:anyURI" create="string"?> + * <property name="NMTOKEN" type="NMTOKEN">* + * </connectionFactory>? + * + * <activationSpec name="xs:anyURI" create="string"?> + * <property name="NMTOKEN" type="NMTOKEN">* + * </activationSpec>? + * + * <response> + * <destination name="xs:anyURI" type="string"? create="string"?> + * <property name="NMTOKEN" type="NMTOKEN">* + * </destination>? + * + * <connectionFactory name="xs:anyURI" create="string"?> + * <property name="NMTOKEN" type="NMTOKEN">* + * </connectionFactory>? + * + * <activationSpec name="xs:anyURI" create="string"?> + * <property name="NMTOKEN" type="NMTOKEN">* + * </activationSpec>? + * </response>? + * + * <resourceAdapter name="NMTOKEN">? + * <property name="NMTOKEN" type="NMTOKEN">* + * </resourceAdapter>? + * + * <headers JMSType="string"? + * JMSCorrelationId="string"? + * JMSDeliveryMode="string"? + * JMSTimeToLive="int"? + * JMSPriority="string"?> + * <property name="NMTOKEN" type="NMTOKEN">* + * </headers>? + * + * <operationProperties name="string" nativeOperation="string"?> + * <property name="NMTOKEN" type="NMTOKEN">* + * <headers JMSType="string"? + * JMSCorrelationId="string"? + * JMSDeliveryMode="string"? + * JMSTimeToLive="int"? + * JMSPriority="string"?> + * <property name="NMTOKEN" type="NMTOKEN">* + * </headers>? + * </operationProperties>* + * </binding.jms> + */ + +public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { + + private PolicyFactory policyFactory; + private PolicyAttachPointProcessor policyProcessor; + + public JMSBindingProcessor(ModelFactoryExtensionPoint modelFactories) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + } + + public QName getArtifactType() { + return JMSBindingConstants.BINDING_JMS_QNAME; + } + + public Class<JMSBinding> getModelType() { + return JMSBinding.class; + } + + public JMSBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + JMSBinding jmsBinding = new JMSBinding(); + + // Read policies + policyProcessor.readPolicies(jmsBinding, reader); + + // Read binding name + String name = reader.getAttributeValue(null, "name"); + if (name != null) { + jmsBinding.setName(name); + } + + // Read binding URI + String uri = reader.getAttributeValue(null, "uri"); + if (uri != null) { + jmsBinding.setURI(uri); + System.err.println("JMS Binding doesn't process uri yet"); + } + + // Read correlation scheme + String correlationScheme = reader.getAttributeValue(null, "correlationScheme"); + if (correlationScheme != null && correlationScheme.length() > 0) { + if (JMSBindingConstants.VALID_CORRELATION_SCHEMES.contains(correlationScheme.toLowerCase())) { + jmsBinding.setCorrelationScheme(correlationScheme); + } else { + throw new JMSBindingException("invalid correlationScheme: " + correlationScheme); + } + System.err.println("JMS Binding doesn't process correlationScheme yet"); + } + + // Read initial context factory + String initialContextFactory = reader.getAttributeValue(null, "initialContextFactory"); + if (initialContextFactory != null && initialContextFactory.length() > 0) { + jmsBinding.setInitialContextFactoryName(initialContextFactory); + } + + // Read jndi URL + String jndiURL = reader.getAttributeValue(null, "jndiURL"); + if (jndiURL != null && jndiURL.length() > 0) { + jmsBinding.setJndiURL(jndiURL); + } + + // Read requestConnection + // TODO + // Read reponseConnection + // TODO + // Read operationProperties + // TODO + + // Read subelements of binding.jms + boolean endFound = false; + while (!endFound) { + switch (reader.next()) { + case START_ELEMENT: + String elementName = reader.getName().getLocalPart(); + if ("destination".equals(elementName)) { + parseDestination(reader, jmsBinding); + } else if ("connectionFactory".equals(elementName)) { + parseConnectionFactory(reader, jmsBinding); + } else if ("activationSpec".equals(elementName)) { + parseActivationSpec(reader, jmsBinding); + } else if ("response".equals(elementName)) { + parseResponse(reader, jmsBinding); + } else if ("resourceAdapter".equals(elementName)) { + parseResourceAdapter(reader, jmsBinding); + } else if ("headers".equals(elementName)) { + parseHeaders(reader, jmsBinding); + } else if ("operationProperties".equals(elementName)) { + parseOperationProperties(reader, jmsBinding); + } + reader.next(); + break; + case END_ELEMENT: + QName x = reader.getName(); + if (x.equals(JMSBindingConstants.BINDING_JMS_QNAME)) { + endFound = true; + } else { + throw new RuntimeException("Incomplete binding.jms definition found unexpected element " + x + .toString()); + } + } + } + + jmsBinding.validate(); + + return jmsBinding; + } + + public void resolve(JMSBinding model, ModelResolver resolver) throws ContributionResolveException { + } + + public void write(JMSBinding rmiBinding, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + // Write a <binding.jms> + writer.writeStartElement(Constants.SCA10_NS, JMSBindingConstants.BINDING_JMS); + + // FIXME Implement + + writer.writeEndElement(); + } + + private void parseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setDestinationName(name); + } + + String type = reader.getAttributeValue(null, "type"); + if (type != null && type.length() > 0) { + if (JMSBindingConstants.DESTINATION_TYPE_QUEUE.equalsIgnoreCase(type)) { + jmsBinding.setDestinationType(JMSBindingConstants.DESTINATION_TYPE_QUEUE); + } else if (JMSBindingConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(type)) { + jmsBinding.setDestinationType(JMSBindingConstants.DESTINATION_TYPE_TOPIC); + } else { + throw new RuntimeException("invalid destination type: " + type); + } + System.err.println("JMS Binding doesn't process destination type yet"); + } + + String create = reader.getAttributeValue(null, "create"); + if (create != null && create.length() > 0) { + jmsBinding.setDestinationCreate(create); + } + } + + private void parseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setConnectionFactoryName(name); + } else { + throw new RuntimeException("missing connectionFactory name"); + } + } + + private void parseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setActivationSpecName(name); + System.err.println("JMS Binding doesn't process activationSpec yet"); + } else { + throw new RuntimeException("missing ActivationSpec name"); + } + } + + private void parseResponseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setResponseDestinationName(name); + } + + String type = reader.getAttributeValue(null, "type"); + if (type != null && type.length() > 0) { + if (JMSBindingConstants.DESTINATION_TYPE_QUEUE.equalsIgnoreCase(type)) { + jmsBinding.setResponseDestinationType(JMSBindingConstants.DESTINATION_TYPE_QUEUE); + } else if (JMSBindingConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(type)) { + jmsBinding.setResponseDestinationType(JMSBindingConstants.DESTINATION_TYPE_TOPIC); + } else { + throw new RuntimeException("invalid response destination type: " + type); + } + System.err.println("JMS Binding doesn't process response destination type yet"); + } + + String create = reader.getAttributeValue(null, "create"); + if (create != null && create.length() > 0) { + jmsBinding.setResponseDestinationCreate(create); + } + } + + private void parseResponseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setResponseConnectionFactoryName(name); + System.err.println("JMS Binding doesn't process response connectionFactory yet"); + } else { + throw new RuntimeException("missing response connectionFactory name"); + } + } + + private void parseResponseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setResponseActivationSpecName(name); + System.err.println("JMS Binding doesn't process response activationSpec yet"); + } else { + throw new RuntimeException("missing response ActivationSpec name"); + } + } + + private void parseResponse(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + // Read subelements of response + while (true) { + switch (reader.next()) { + case START_ELEMENT: + String elementName = reader.getName().getLocalPart(); + if ("destination".equals(elementName)) { + parseResponseDestination(reader, jmsBinding); + } else if ("connectionFactory".equals(elementName)) { + parseResponseConnectionFactory(reader, jmsBinding); + } else if ("activationSpec".equals(elementName)) { + parseResponseActivationSpec(reader, jmsBinding); + } + reader.next(); + break; + case END_ELEMENT: + QName x = reader.getName(); + if (x.getLocalPart().equals("response")) { + return; + } else { + throw new RuntimeException( + "Incomplete binding.jms/response definition found unexpected element " + x + .toString()); + } + } + } + } + + private void parseResourceAdapter(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + System.err.println("JMS Binding doesn't process resourceAdapter yet"); + } + + private void parseHeaders(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + System.err.println("JMS Binding doesn't process headers yet"); + } + + private void parseOperationProperties(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + System.err.println("JMS Binding doesn't process operationProperties yet"); + } + +} |