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