Coverage Report - org.mule.extras.spring.config.MuleObjectNameProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleObjectNameProcessor
83%
20/24
72%
26/36
3.75
 
 1  
 /*
 2  
  * $Id: MuleObjectNameProcessor.java 8094 2007-08-28 15:36:50Z ashaposhnikov $
 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.extras.spring.config;
 12  
 
 13  
 import org.mule.impl.endpoint.MuleEndpoint;
 14  
 import org.mule.umo.UMODescriptor;
 15  
 import org.mule.umo.endpoint.UMOEndpoint;
 16  
 import org.mule.umo.manager.UMOAgent;
 17  
 import org.mule.umo.model.UMOModel;
 18  
 import org.mule.umo.provider.UMOConnector;
 19  
 import org.mule.umo.transformer.UMOTransformer;
 20  
 import org.mule.util.MuleObjectHelper;
 21  
 
 22  
 import org.springframework.beans.BeansException;
 23  
 import org.springframework.beans.factory.config.BeanPostProcessor;
 24  
 
 25  
 /**
 26  
  * <code>MuleObjectNameProcessor</code> is used to set spring ids to Mule object
 27  
  * names so the the bean id and name property on the object don't both have to be
 28  
  * set.
 29  
  */
 30  
 
 31  44
 public class MuleObjectNameProcessor implements BeanPostProcessor
 32  
 {
 33  44
     private boolean overwrite = false;
 34  
 
 35  
     public Object postProcessBeforeInitialization(Object o, String s) throws BeansException
 36  
     {
 37  2310
         if (!MuleObjectHelper.class.getName().equals(s))
 38  
         {
 39  2306
             if (o instanceof UMOConnector)
 40  
             {
 41  26
                 if (((UMOConnector)o).getName() == null || overwrite)
 42  
                 {
 43  26
                     ((UMOConnector)o).setName(s);
 44  
                 }
 45  
             }                                  
 46  2280
             else if (o instanceof UMOTransformer)
 47  
             {
 48  118
                 ((UMOTransformer)o).setName(s);
 49  
             }
 50  2162
             else if (o instanceof UMOEndpoint)
 51  
             {
 52  
                 // spring uses the class name of the object as the name if no other
 53  
                 // id is set; this is no good for endpoints
 54  402
                 if ((((UMOEndpoint)o).getName() == null || overwrite)
 55  
                     && s.indexOf(MuleEndpoint.class.getName()) == -1)
 56  
                 {
 57  34
                     ((UMOEndpoint)o).setName(s);
 58  
                 }
 59  
             }
 60  1760
             else if (o instanceof UMODescriptor)
 61  
             {
 62  52
                 if (((UMODescriptor)o).getName() == null || overwrite)
 63  
                 {
 64  52
                     ((UMODescriptor)o).setName(s);
 65  
                 }
 66  
             }
 67  1708
             else if (o instanceof UMOModel)
 68  
             {
 69  20
                 if (((UMOModel)o).getName() == null || overwrite)
 70  
                 {
 71  0
                     ((UMOModel)o).setName(s);
 72  
                 }
 73  
             }
 74  1688
             else if (o instanceof UMOAgent)
 75  
             {
 76  20
                 ((UMOAgent)o).setName(s);
 77  
             }
 78  
         }
 79  2306
         return o;
 80  
     }
 81  
 
 82  
     public Object postProcessAfterInitialization(Object o, String s) throws BeansException
 83  
     {
 84  2306
         return o;
 85  
     }
 86  
 
 87  
     public boolean isOverwrite()
 88  
     {
 89  0
         return overwrite;
 90  
     }
 91  
 
 92  
     public void setOverwrite(boolean overwrite)
 93  
     {
 94  0
         this.overwrite = overwrite;
 95  0
     }
 96  
 
 97  
 }