Coverage Report - org.mule.impl.MuleDescriptor
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleDescriptor
46%
41/90
60%
12/20
1.5
 
 1  
 /*
 2  
  * $Id: MuleDescriptor.java 10415 2008-01-21 10:46:37Z 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.impl;
 12  
 
 13  
 import org.mule.MuleException;
 14  
 import org.mule.config.PoolingProfile;
 15  
 import org.mule.config.QueueProfile;
 16  
 import org.mule.config.ThreadingProfile;
 17  
 import org.mule.impl.container.DescriptorContainerKeyPair;
 18  
 import org.mule.umo.UMODescriptor;
 19  
 import org.mule.umo.UMOInterceptor;
 20  
 import org.mule.umo.endpoint.UMOEndpoint;
 21  
 import org.mule.umo.routing.UMOInboundRouterCollection;
 22  
 import org.mule.umo.routing.UMONestedRouterCollection;
 23  
 import org.mule.umo.routing.UMOOutboundRouterCollection;
 24  
 import org.mule.umo.routing.UMOResponseRouterCollection;
 25  
 import org.mule.umo.transformer.UMOTransformer;
 26  
 import org.mule.util.FileUtils;
 27  
 
 28  
 import java.beans.ExceptionListener;
 29  
 import java.io.FileInputStream;
 30  
 import java.util.List;
 31  
 import java.util.Map;
 32  
 import java.util.Properties;
 33  
 
 34  
 import org.apache.commons.logging.Log;
 35  
 import org.apache.commons.logging.LogFactory;
 36  
 
 37  
 /**
 38  
  * <code>MuleDescriptor</code> describes all the properties for a Mule UMO. New
 39  
  * Mule UMOs can be initialised as needed from their descriptor.
 40  
  *
 41  
  */
 42  
 
 43  
 public class MuleDescriptor extends ImmutableMuleDescriptor implements UMODescriptor
 44  
 {
 45  
     public static final String DEFAULT_INSTANCE_REF_NAME = "_instanceRef";
 46  
     /**
 47  
      * logger used by this class
 48  
      */
 49  4
     private static Log logger = LogFactory.getLog(MuleDescriptor.class);
 50  
 
 51  
     public MuleDescriptor(String name)
 52  
     {
 53  16
         super();
 54  16
         this.name = name;
 55  16
     }
 56  
 
 57  
     public MuleDescriptor(MuleDescriptor descriptor)
 58  
     {
 59  0
         super(descriptor);
 60  0
     }
 61  
 
 62  
     /**
 63  
      * Default constructor. Initalises common properties for the MuleConfiguration
 64  
      * object
 65  
      *
 66  
      * @see org.mule.config.MuleConfiguration
 67  
      */
 68  
     public MuleDescriptor()
 69  
     {
 70  406
         super();
 71  406
     }
 72  
 
 73  
     public void setThreadingProfile(ThreadingProfile threadingProfile)
 74  
     {
 75  0
         this.threadingProfile = threadingProfile;
 76  0
     }
 77  
 
 78  
     /*
 79  
      * (non-Javadoc)
 80  
      *
 81  
      * @see org.mule.umo.UMODescriptor#setExceptionListener(org.mule.umo.UMOExceptionStrategy)
 82  
      */
 83  
     public void setExceptionListener(ExceptionListener listener)
 84  
     {
 85  404
         if (listener == null)
 86  
         {
 87  2
             throw new IllegalArgumentException("Exception Strategy cannot be null");
 88  
         }
 89  402
         this.exceptionListener = listener;
 90  402
         logger.debug("Using exception strategy: " + listener.getClass().getName());
 91  402
     }
 92  
 
 93  
     /*
 94  
      * (non-Javadoc)
 95  
      *
 96  
      * @see org.mule.umo.UMODescriptor#setName(java.lang.String)
 97  
      */
 98  
     public void setName(String newName)
 99  
     {
 100  402
         if (newName == null)
 101  
         {
 102  2
             throw new IllegalArgumentException("Name cannot be null");
 103  
         }
 104  400
         name = newName;
 105  400
     }
 106  
 
 107  
     /*
 108  
      * (non-Javadoc)
 109  
      *
 110  
      * @see org.mule.transformers.HasTransformer#setOutboundTransformer(org.mule.umo.transformer.UMOTransformer)
 111  
      */
 112  
     public void setOutboundTransformer(UMOTransformer transformer)
 113  
     {
 114  0
         outboundTransformer = transformer;
 115  0
     }
 116  
 
 117  
     /*
 118  
      * (non-Javadoc)
 119  
      *
 120  
      * @see org.mule.umo.UMODescriptor#setResponseTransformer(UMOTransformer)
 121  
      */
 122  
     public void setResponseTransformer(UMOTransformer transformer)
 123  
     {
 124  0
         responseTransformer = transformer;
 125  0
     }
 126  
 
 127  
     /*
 128  
      * (non-Javadoc)
 129  
      *
 130  
      * @see org.mule.umo.UMODescriptor#getPropertiesForURI(java.util.Properties)
 131  
      */
 132  
     public void setProperties(Map props)
 133  
     {
 134  2
         properties = props;
 135  2
         String delegate = (String) properties.get(MULE_PROPERTY_DOT_PROPERTIES);
 136  2
         if (delegate != null)
 137  
         {
 138  
             try
 139  
             {
 140  0
                 FileInputStream is = new FileInputStream(FileUtils.newFile(delegate));
 141  0
                 Properties dProps = new Properties();
 142  0
                 dProps.load(is);
 143  0
                 properties.putAll(dProps);
 144  
             }
 145  0
             catch (Exception e)
 146  
             {
 147  0
                 logger.warn(MULE_PROPERTY_DOT_PROPERTIES + " was set  to " + delegate
 148  
                             + " but the file could not be read, exception is: " + e.getMessage());
 149  0
             }
 150  
         }
 151  2
     }
 152  
 
 153  
     /*
 154  
      * (non-Javadoc)
 155  
      *
 156  
      * @see org.mule.umo.UMODescriptor#setVersion(long)
 157  
      */
 158  
     public void setVersion(String ver)
 159  
     {
 160  0
         version = ver;
 161  0
     }
 162  
 
 163  
     /*
 164  
      * (non-Javadoc)
 165  
      *
 166  
      * @see org.mule.umo.UMODescriptor#setInboundEndpoint(org.mule.impl.UMOEndpoint)
 167  
      */
 168  
     public void setInboundEndpoint(UMOEndpoint endpoint) throws MuleException
 169  
     {
 170  26
         inboundEndpoint = endpoint;
 171  26
         if (inboundEndpoint != null)
 172  
         {
 173  26
             inboundEndpoint.setType(UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
 174  26
             if (inboundEndpoint.getTransformer() != null)
 175  
             {
 176  0
                 inboundTransformer = inboundEndpoint.getTransformer();
 177  
             }
 178  
         }
 179  26
     }
 180  
 
 181  
     /*
 182  
      * (non-Javadoc)
 183  
      *
 184  
      * @see org.mule.umo.UMODescriptor#setOutboundEndpoint(org.mule.impl.UMO
 185  
      *      ProviderDescriptor)
 186  
      */
 187  
     public void setOutboundEndpoint(UMOEndpoint endpoint) throws MuleException
 188  
     {
 189  398
         outboundEndpoint = endpoint;
 190  398
         if (outboundEndpoint != null)
 191  
         {
 192  380
             outboundEndpoint.setType(UMOEndpoint.ENDPOINT_TYPE_SENDER);
 193  380
             if (outboundEndpoint.getTransformer() != null)
 194  
             {
 195  0
                 outboundTransformer = outboundEndpoint.getTransformer();
 196  
             }
 197  
         }
 198  
 
 199  398
     }
 200  
 
 201  
     /*
 202  
      * (non-Javadoc)
 203  
      *
 204  
      * @see org.mule.transformers.HasTransformer#setInboundTransformer(org.mule.umo.transformer.UMOTransformer)
 205  
      */
 206  
     public void setInboundTransformer(UMOTransformer transformer)
 207  
     {
 208  0
         inboundTransformer = transformer;
 209  0
     }
 210  
 
 211  
     /*
 212  
      * (non-Javadoc)
 213  
      *
 214  
      * @see org.mule.umo.UMODescriptor#addinteceptor(org.mule.umo.UMOInterceptor)
 215  
      */
 216  
     public void addInterceptor(UMOInterceptor inteceptor)
 217  
     {
 218  0
         if (inteceptor != null)
 219  
         {
 220  0
             intecerptorList.add(inteceptor);
 221  
         }
 222  0
     }
 223  
 
 224  
     public void setInterceptors(List inteceptorList)
 225  
     {
 226  0
         this.intecerptorList = inteceptorList;
 227  0
     }
 228  
 
 229  
     /*
 230  
      * (non-Javadoc)
 231  
      *
 232  
      * @see org.mule.umo.UMODescriptor#setPoolingProfile(UMOPoolingProfile)
 233  
      */
 234  
     public void setPoolingProfile(PoolingProfile poolingProfile)
 235  
     {
 236  0
         this.poolingProfile = poolingProfile;
 237  0
     }
 238  
 
 239  
     public void setQueueProfile(QueueProfile queueProfile)
 240  
     {
 241  2
         this.queueProfile = queueProfile;
 242  2
     }
 243  
 
 244  
     /*
 245  
      * (non-Javadoc)
 246  
      *
 247  
      * @see org.mule.umo.UMODescriptor#setImplementation(java.lang.String)
 248  
      */
 249  
     public void setImplementation(Object reference)
 250  
     {
 251  414
         if (reference == null)
 252  
         {
 253  4
             throw new IllegalArgumentException("ImplementationReference cannot be null");
 254  
         }
 255  410
         implementationReference = reference;
 256  410
     }
 257  
 
 258  
     public void setImplementationInstance(Object instance)
 259  
     {
 260  0
         if (name == null)
 261  
         {
 262  0
             throw new IllegalArgumentException("UMODescriptor.name may not be null");
 263  
         }
 264  0
         properties.put(DEFAULT_INSTANCE_REF_NAME, instance);
 265  0
         setImplementation(new DescriptorContainerKeyPair(name, DEFAULT_INSTANCE_REF_NAME));
 266  0
     }
 267  
 
 268  
     public void setInboundRouter(UMOInboundRouterCollection router)
 269  
     {
 270  22
         this.inboundRouter = router;
 271  22
     }
 272  
 
 273  
     public void setOutboundRouter(UMOOutboundRouterCollection router)
 274  
     {
 275  0
         outboundRouter = router;
 276  0
     }
 277  
 
 278  
     public void setNestedRouter(UMONestedRouterCollection router)
 279  
     {
 280  0
         nestedRouter = router;
 281  0
     }
 282  
 
 283  
     public void setContainerManaged(boolean value)
 284  
     {
 285  2
         containerManaged = value;
 286  2
     }
 287  
 
 288  
     public void addInitialisationCallback(InitialisationCallback callback)
 289  
     {
 290  0
         initialisationCallbacks.add(callback);
 291  0
     }
 292  
 
 293  
     /**
 294  
      * Response Routers control how events are returned in a request/response call.
 295  
      * It cn be use to aggregate response events before returning, thus acting as a
 296  
      * Join in a forked process. This can be used to make request/response calls a
 297  
      * lot more efficient as independent tasks can be forked, execute concurrently
 298  
      * and then join before the request completes
 299  
      *
 300  
      * @param router the response router for this component
 301  
      * @see org.mule.umo.routing.UMOResponseRouterCollection
 302  
      */
 303  
     public void setResponseRouter(UMOResponseRouterCollection router)
 304  
     {
 305  0
         this.responseRouter = router;
 306  0
     }
 307  
 
 308  
     /**
 309  
      * Determines if only a single instance of this component is created. This is
 310  
      * useful when a component hands off event processing to another engine such as
 311  
      * Rules processing or Bpel and the processing engine allocates and manages its
 312  
      * own threads.
 313  
      *
 314  
      * @param singleton true if this component is a singleton
 315  
      */
 316  
     public void setSingleton(boolean singleton)
 317  
     {
 318  0
         this.singleton = singleton;
 319  0
     }
 320  
 
 321  
     /**
 322  
      * Sets the initial state of this component
 323  
      *
 324  
      * @param state the initial state of this component
 325  
      */
 326  
     public void setInitialState(String state)
 327  
     {
 328  2
         this.initialState = state;
 329  2
     }
 330  
 
 331  
     public void setEncoding(String encoding)
 332  
     {
 333  0
         this.encoding = encoding;
 334  0
     }
 335  
 
 336  
     /**
 337  
      * Sets the name of the contaier where the object for this descriptor resides. If
 338  
      * this value is 'none' the 'implementaiton' attributed is expected to be a fully
 339  
      * qualified class name that will be instanciated.
 340  
      *
 341  
      * @param containerName the container name, or null if it is not known - in which
 342  
      *            case each container will be queried for the component
 343  
      *            implementation.
 344  
      */
 345  
     public void setContainer(String containerName)
 346  
     {
 347  0
         this.container = containerName;
 348  0
     }
 349  
 
 350  
 
 351  
     public void setModelName(String modelName)
 352  
     {
 353  0
         this.modelName = modelName;
 354  0
     }
 355  
 }