Coverage Report - org.mule.ra.MuleActivationSpec
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleActivationSpec
24%
12/49
12%
2/16
1.812
 
 1  
 /*
 2  
  * $Id: MuleActivationSpec.java 10129 2007-12-21 20:33:11Z dfeist $
 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  16
 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  
     private String modelName;
 46  
 
 47  
     public Properties getPropertiesMap()
 48  
     {
 49  0
         return propertiesMap;
 50  
     }
 51  
 
 52  
     public void setPropertiesMap(Properties propertiesMap)
 53  
     {
 54  0
         this.propertiesMap = propertiesMap;
 55  0
     }
 56  
 
 57  
     public void setPropertiesMap(String properties)
 58  
     {
 59  0
         String[] pairs = StringUtils.splitAndTrim(properties, ",");
 60  0
         Properties props = new Properties();
 61  
 
 62  0
         for (int i = 0; i < pairs.length; i++)
 63  
         {
 64  0
             String pair = pairs[i];
 65  0
             int x = pair.indexOf('=');
 66  0
             if (x == -1)
 67  
             {
 68  0
                 props.setProperty(pair, null);
 69  
             }
 70  
             else
 71  
             {
 72  0
                 props.setProperty(pair.substring(0, x), pair.substring(x + 1));
 73  
             }
 74  
         }
 75  
 
 76  0
         this.setPropertiesMap(props);
 77  0
     }
 78  
 
 79  
     public String getEndpointName()
 80  
     {
 81  0
         return endpointName;
 82  
     }
 83  
 
 84  
     public void setEndpointName(String endpointName)
 85  
     {
 86  0
         this.endpointName = endpointName;
 87  0
     }
 88  
 
 89  
     public String getConnectorName()
 90  
     {
 91  0
         return connectorName;
 92  
     }
 93  
 
 94  
     public void setConnectorName(String connectorName)
 95  
     {
 96  0
         this.connectorName = connectorName;
 97  0
     }
 98  
 
 99  
     public int getCreateConnector()
 100  
     {
 101  0
         return createConnector;
 102  
     }
 103  
 
 104  
     public void setCreateConnector(int createConnector)
 105  
     {
 106  0
         this.createConnector = createConnector;
 107  0
     }
 108  
 
 109  
     public String getEndpoint()
 110  
     {
 111  12
         return endpoint;
 112  
     }
 113  
 
 114  
     public void setEndpoint(String endpoint)
 115  
     {
 116  8
         this.endpoint = endpoint;
 117  
 
 118  8
     }
 119  
 
 120  
     public void validate() throws InvalidPropertyException
 121  
     {
 122  
         try
 123  
         {
 124  0
             this.endpointURI = new MuleEndpointURI(endpoint);
 125  
         }
 126  0
         catch (MalformedEndpointException e)
 127  
         {
 128  0
             throw new InvalidPropertyException(e);
 129  0
         }
 130  
 
 131  0
         if (propertiesMap != null)
 132  
         {
 133  0
             propertiesMap.putAll(this.endpointURI.getParams());
 134  
         }
 135  
         else
 136  
         {
 137  0
             propertiesMap = this.endpointURI.getParams();
 138  
         }
 139  0
         if (endpoint == null)
 140  
         {
 141  0
             throw new InvalidPropertyException("endpoint is null");
 142  
         }
 143  
 
 144  0
         if (endpointURI == null)
 145  
         {
 146  0
             throw new InvalidPropertyException("endpointURI is null");
 147  
         }
 148  0
     }
 149  
 
 150  
     public ResourceAdapter getResourceAdapter()
 151  
     {
 152  8
         return resourceAdapter;
 153  
     }
 154  
 
 155  
     public void setResourceAdapter(ResourceAdapter resourceAdapter) throws ResourceException
 156  
     {
 157  
         // spec section 5.3.3
 158  4
         if (this.resourceAdapter != null)
 159  
         {
 160  0
             throw new ResourceException("ResourceAdapter already set");
 161  
         }
 162  4
         if (!(resourceAdapter instanceof MuleResourceAdapter))
 163  
         {
 164  0
             throw new ResourceException("ResourceAdapter is not of type: "
 165  0
                                         + MuleResourceAdapter.class.getName());
 166  
         }
 167  4
         this.resourceAdapter = (MuleResourceAdapter)resourceAdapter;
 168  4
     }
 169  
 
 170  
         public String getModelName() {
 171  18
                 return modelName;
 172  
         }
 173  
 
 174  
         public void setModelName(String modelName) {
 175  8
                 this.modelName = modelName;
 176  8
         }
 177  
 }