From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/binding/jms/JMSBindingBuilder.java | 137 +++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java (limited to 'sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java') diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java new file mode 100644 index 0000000000..f1359ed492 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java @@ -0,0 +1,137 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.binding.jms; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.BindingBuilderExtension; +import org.apache.tuscany.spi.model.BoundReferenceDefinition; +import org.apache.tuscany.spi.model.BoundServiceDefinition; + +import commonj.sdo.helper.TypeHelper; + +/** + * Builds a Service or Reference for an RMI binding. + * + * @version $Rev$ $Date$ + */ + +public class JMSBindingBuilder extends BindingBuilderExtension { + + private static String DEFAULT_JMS_RESOURCE_FACTORY = "org.apache.tuscany.binding.jms.SimpleJMSResourceFactory"; + private static String DEFAULT_OPERATION_SELECTOR = "org.apache.tuscany.binding.jms.DefaultOperationSelector"; + + protected Class getBindingType() { + return JMSBinding.class; + } + + @SuppressWarnings({"unchecked"}) + public Service build(CompositeComponent parent, + BoundServiceDefinition serviceDefinition, + DeploymentContext deploymentContext) { + + JMSBinding jmsBinding = serviceDefinition.getBinding(); + Class interfaze = serviceDefinition.getServiceContract().getInterfaceClass(); + TypeHelper typeHelper = (TypeHelper) deploymentContext.getExtension(TypeHelper.class.getName()); + if(typeHelper==null) typeHelper = TypeHelper.INSTANCE; + + JMSResourceFactory jmsResourceFactory = getJMSResourceFactory(jmsBinding); + OperationSelector opSec = getOperationSelector(jmsBinding); + + return new JMSService(serviceDefinition.getName(),parent, wireService, jmsBinding, jmsResourceFactory,opSec,interfaze,typeHelper); + } + + @SuppressWarnings({"unchecked"}) + public Reference build(CompositeComponent parent, + BoundReferenceDefinition referenceDefinition, + DeploymentContext deploymentContext) { + + String name = referenceDefinition.getName(); + Class interfaze = referenceDefinition.getServiceContract().getInterfaceClass(); + + JMSBinding jmsBinding = referenceDefinition.getBinding(); + JMSResourceFactory jmsResourceFactory = getJMSResourceFactory(jmsBinding); + OperationSelector opSec = getOperationSelector(jmsBinding); + + return new JMSReference(name,parent,wireService, jmsBinding, jmsResourceFactory,opSec,interfaze); + + } + + private JMSResourceFactory getJMSResourceFactory(JMSBinding jmsBinding) { + String className = jmsBinding.getJmsResourceFactoryName(); + if (className != null && !className.equals("")){ + try { + Class factoryClass = Class.forName(className != null ? className : DEFAULT_JMS_RESOURCE_FACTORY); + Constructor constructor = factoryClass.getDeclaredConstructor(new Class[]{JMSBinding.class}); + return (JMSResourceFactory) constructor.newInstance(jmsBinding); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + return new SimpleJMSResourceFactory(jmsBinding); + }else{ + return new SimpleJMSResourceFactory(jmsBinding); + } + + } + + + private OperationSelector getOperationSelector(JMSBinding jmsBinding) { + String className = jmsBinding.getOperationSelectorName(); + + if (className != null && !className.equals("")){ + try { + Class factoryClass = Class.forName(className != null ? className : DEFAULT_OPERATION_SELECTOR); + Constructor constructor = factoryClass.getDeclaredConstructor(new Class[]{JMSBinding.class}); + return (OperationSelector) constructor.newInstance(jmsBinding); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + return new DefaultOperationSelector(jmsBinding); + }else{ + return new DefaultOperationSelector(jmsBinding); + } + } +} -- cgit v1.2.3