Coverage Report - org.mule.ra.MuleActivationSpec
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleActivationSpec
0%
0/46
0%
0/8
1.929
 
 1  
 /*
 2  
  * $Id: MuleActivationSpec.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.ra;
 12  
 
 13  
 import org.mule.impl.endpoint.MuleEndpointURI;
 14  
 import org.mule.umo.endpoint.MalformedEndpointException;
 15  
 import org.mule.umo.endpoint.UMOEndpointURI;
 16  
 import org.mule.util.StringUtils;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Properties;
 20  
 
 21  
 import javax.resource.ResourceException;
 22  
 import javax.resource.spi.ActivationSpec;
 23  
 import javax.resource.spi.InvalidPropertyException;
 24  
 import javax.resource.spi.ResourceAdapter;
 25  
 
 26  
 /**
 27  
  * <code>MuleActivationSpec</code> defines the contract between a Message Driven
 28  
  * Bean (MDB) and the Mule Resource Adapter. This spec holds the configuration values
 29  
  * used to register inbound communication with the Resource Adapter
 30  
  */
 31  0
 public class MuleActivationSpec implements ActivationSpec, Serializable
 32  
 {
 33  
     /**
 34  
      * Serial version
 35  
      */
 36  
     private static final long serialVersionUID = 735353511874563914L;
 37  
 
 38  
     private Properties propertiesMap;
 39  
     private String endpointName;
 40  
     private String connectorName;
 41  
     private int createConnector;
 42  
     private MuleResourceAdapter resourceAdapter;
 43  
     private String endpoint;
 44  
     private UMOEndpointURI endpointURI;
 45  
 
 46  
     public Properties getPropertiesMap()
 47  
     {
 48  0
         return propertiesMap;
 49  
     }
 50  
 
 51  
     public void setPropertiesMap(Properties propertiesMap)
 52  
     {
 53  0
         this.propertiesMap = propertiesMap;
 54  0
     }
 55  
 
 56  
     public void setPropertiesMap(String properties)
 57  
     {
 58  0
         String[] pairs = StringUtils.splitAndTrim(properties, ",");
 59  0
         Properties props = new Properties();
 60  
 
 61  0
         for (int i = 0; i < pairs.length; i++)
 62  
         {
 63  0
             String pair = pairs[i];
 64  0
             int x = pair.indexOf('=');
 65  0
             if (x == -1)
 66  
             {
 67  0
                 props.setProperty(pair, null);
 68  
             }
 69  
             else
 70  
             {
 71  0
                 props.setProperty(pair.substring(0, x), pair.substring(x + 1));
 72  
             }
 73  
         }
 74  
 
 75  0
         this.setPropertiesMap(props);
 76  0
     }
 77  
 
 78  
     public String getEndpointName()
 79  
     {
 80  0
         return endpointName;
 81  
     }
 82  
 
 83  
     public void setEndpointName(String endpointName)
 84  
     {
 85  0
         this.endpointName = endpointName;
 86  0
     }
 87  
 
 88  
     public String getConnectorName()
 89  
     {
 90  0
         return connectorName;
 91  
     }
 92  
 
 93  
     public void setConnectorName(String connectorName)
 94  
     {
 95  0
         this.connectorName = connectorName;
 96  0
     }
 97  
 
 98  
     public int getCreateConnector()
 99  
     {
 100  0
         return createConnector;
 101  
     }
 102  
 
 103  
     public void setCreateConnector(int createConnector)
 104  
     {
 105  0
         this.createConnector = createConnector;
 106  0
     }
 107  
 
 108  
     public String getEndpoint()
 109  
     {
 110  0
         return endpoint;
 111  
     }
 112  
 
 113  
     public void setEndpoint(String endpoint)
 114  
     {
 115  0
         this.endpoint = endpoint;
 116  
 
 117  0
     }
 118  
 
 119  
     public void validate() throws InvalidPropertyException
 120  
     {
 121  
         try
 122  
         {
 123  0
             this.endpointURI = new MuleEndpointURI(endpoint);
 124  
         }
 125  0
         catch (MalformedEndpointException e)
 126  
         {
 127  0
             throw new InvalidPropertyException(e);
 128  0
         }
 129  
 
 130  0
         if (propertiesMap != null)
 131  
         {
 132  0
             propertiesMap.putAll(this.endpointURI.getParams());
 133  
         }
 134  
         else
 135  
         {
 136  0
             propertiesMap = this.endpointURI.getParams();
 137  
         }
 138  0
         if (endpoint == null)
 139  
         {
 140  0
             throw new InvalidPropertyException("endpoint is null");
 141  
         }
 142  
 
 143  0
         if (endpointURI == null)
 144  
         {
 145  0
             throw new InvalidPropertyException("endpointURI is null");
 146  
         }
 147  0
     }
 148  
 
 149  
     public ResourceAdapter getResourceAdapter()
 150  
     {
 151  0
         return resourceAdapter;
 152  
     }
 153  
 
 154  
     public void setResourceAdapter(ResourceAdapter resourceAdapter) throws ResourceException
 155  
     {
 156  
         // spec section 5.3.3
 157  0
         if (this.resourceAdapter != null)
 158  
         {
 159  0
             throw new ResourceException("ResourceAdapter already set");
 160  
         }
 161  0
         if (!(resourceAdapter instanceof MuleResourceAdapter))
 162  
         {
 163  0
             throw new ResourceException("ResourceAdapter is not of type: "
 164  0
                                         + MuleResourceAdapter.class.getName());
 165  
         }
 166  0
         this.resourceAdapter = (MuleResourceAdapter)resourceAdapter;
 167  0
     }
 168  
 }