Coverage Report - org.mule.config.builders.ContainerReference
 
Classes in this File Line Coverage Branch Coverage Complexity
ContainerReference
0%
0/20
0%
0/3
4
 
 1  
 /*
 2  
  * $Id: ContainerReference.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.config.builders;
 12  
 
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.impl.container.ContainerKeyPair;
 15  
 import org.mule.umo.manager.ContainerException;
 16  
 import org.mule.umo.manager.UMOContainerContext;
 17  
 
 18  
 import java.util.List;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.apache.commons.beanutils.BeanUtils;
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 
 25  
 /**
 26  
  * <code>ContainerReference</code> maintains a container reference for the
 27  
  * MuleXmlConfigurationBuilder that gets wired once the configuration documents have
 28  
  * been loaded.
 29  
  */
 30  
 public class ContainerReference
 31  
 {
 32  
     /**
 33  
      * logger used by this class
 34  
      */
 35  0
     protected static final Log logger = LogFactory.getLog(ContainerReference.class);
 36  
 
 37  
     private String propertyName;
 38  
     private String containerRef;
 39  
     private String container;
 40  
     private Object object;
 41  
     private boolean required;
 42  
 
 43  
     public ContainerReference(String propertyName,
 44  
                               String containerRef,
 45  
                               Object object,
 46  
                               boolean required,
 47  
                               String container)
 48  0
     {
 49  0
         this.propertyName = propertyName;
 50  0
         this.containerRef = containerRef;
 51  0
         this.container = container;
 52  0
         this.object = object;
 53  0
         this.required = required;
 54  0
     }
 55  
 
 56  
     public void resolveReference(UMOContainerContext ctx) throws ContainerException
 57  
     {
 58  0
         Object comp = ctx.getComponent(new ContainerKeyPair(container, containerRef, required));
 59  0
         if (comp == null)
 60  
         {
 61  0
             return;
 62  
         }
 63  
 
 64  
         try
 65  
         {
 66  0
             if (object instanceof Map)
 67  
             {
 68  0
                 ((Map) object).put(propertyName, comp);
 69  
             }
 70  0
             else if (object instanceof List)
 71  
             {
 72  0
                 ((List) object).add(comp);
 73  
             }
 74  
             else
 75  
             {
 76  0
                 BeanUtils.setProperty(object, propertyName, comp);
 77  
             }
 78  
         }
 79  0
         catch (Exception e)
 80  
         {
 81  0
             throw new ContainerException(
 82  
                 CoreMessages.cannotSetPropertyOnObjectWithParamType(propertyName, 
 83  
                     object.getClass(), comp.getClass()), e);
 84  0
         }
 85  0
     }
 86  
 }