1 10 11 package org.mule.config.builders; 12 13 import org.apache.commons.beanutils.BeanUtils; 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 import org.mule.config.i18n.Message; 17 import org.mule.config.i18n.Messages; 18 import org.mule.impl.container.ContainerKeyPair; 19 import org.mule.umo.manager.ContainerException; 20 import org.mule.umo.manager.UMOContainerContext; 21 22 import java.util.List ; 23 import java.util.Map ; 24 25 30 public class ContainerReference 31 { 32 35 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 { 49 this.propertyName = propertyName; 50 this.containerRef = containerRef; 51 this.container = container; 52 this.object = object; 53 this.required = required; 54 } 55 56 public void resolveReference(UMOContainerContext ctx) throws ContainerException 57 { 58 Object comp = ctx.getComponent(new ContainerKeyPair(container, containerRef, required)); 59 if (comp == null) return; 60 61 try 62 { 63 if (object instanceof Map ) 64 { 65 ((Map )object).put(propertyName, comp); 66 } 67 else if (object instanceof List ) 68 { 69 ((List )object).add(comp); 70 } 71 else 72 { 73 BeanUtils.setProperty(object, propertyName, comp); 74 } 75 } 76 catch (Exception e) 77 { 78 throw new ContainerException(new Message(Messages.CANT_SET_PROP_X_ON_X_OF_TYPE_X, propertyName, 79 object.getClass().getName(), comp.getClass().getName())); 80 } 81 } 82 } 83 | Popular Tags |