1 10 11 package org.mule.impl.container; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.mule.config.i18n.Message; 16 import org.mule.config.i18n.Messages; 17 import org.mule.umo.lifecycle.InitialisationException; 18 import org.mule.umo.manager.ContainerException; 19 import org.mule.umo.manager.ObjectNotFoundException; 20 import org.mule.umo.manager.UMOContainerContext; 21 22 import java.io.Reader ; 23 import java.util.Iterator ; 24 import java.util.TreeMap ; 25 26 30 public class MultiContainerContext implements UMOContainerContext 31 { 32 35 protected static final Log logger = LogFactory.getLog(MultiContainerContext.class); 36 37 private String name = "multi"; 38 private TreeMap containers = new TreeMap (); 39 40 public MultiContainerContext() 41 { 42 addContainer(new MuleContainerContext()); 43 addContainer(new DescriptorContainerContext()); 44 } 45 46 public void setName(String name) 47 { 48 } 50 51 public String getName() 52 { 53 return name; 54 } 55 56 public void addContainer(UMOContainerContext container) 57 { 58 if (containers.containsKey(container.getName())) 59 { 60 throw new IllegalArgumentException (new Message(Messages.CONTAINER_X_ALREADY_REGISTERED, 61 container.getName()).toString()); 62 } 63 containers.put(container.getName(), container); 64 } 65 66 public UMOContainerContext removeContainer(String name) 67 { 68 return (UMOContainerContext)containers.remove(name); 69 } 70 71 public Object getComponent(Object key) throws ObjectNotFoundException 72 { 73 ContainerKeyPair realKey = null; 75 String cause = null; 76 if (key instanceof String ) 77 { 78 realKey = new ContainerKeyPair(null, key); 79 } 80 else 81 { 82 realKey = (ContainerKeyPair)key; 83 } 84 85 Object component = null; 86 UMOContainerContext container; 87 if (realKey.getContainerName() != null) 88 { 89 container = (UMOContainerContext)containers.get(realKey.getContainerName()); 90 if (container != null) 91 { 92 return container.getComponent(realKey); 93 } 94 else 95 { 96 throw new ObjectNotFoundException("Container: " + realKey.getContainerName()); 97 } 98 } 99 100 for (Iterator iterator = containers.values().iterator(); iterator.hasNext();) 101 { 102 container = (UMOContainerContext)iterator.next(); 103 try 104 { 105 component = container.getComponent(realKey); 106 } 107 catch (ObjectNotFoundException e) 108 { 109 if (logger.isDebugEnabled()) 110 { 111 logger.debug("Object: '" + realKey + "' not found in container: " + container.getName(), 112 e.getCause()); 113 } 114 if (e.getCause() != null){ 115 cause = cause + " " + e.getCause().toString(); 116 } 117 } 118 if (component != null) 119 { 120 if (logger.isDebugEnabled()) 121 { 122 logger.debug("Object: '" + realKey + "' found in container: " + container.getName()); 123 } 124 break; 125 } 126 } 127 if (component == null) 128 { 129 if (realKey.isRequired()) 130 { 131 throw new ObjectNotFoundException(realKey.toString() + " " + cause); 132 } 133 else if (logger.isDebugEnabled()) 134 { 135 logger.debug("Component reference not found: " + realKey.toFullString()); 136 return null; 137 } 138 } 139 return component; 140 } 141 142 public void configure(Reader configuration, String doctype, String encoding) throws ContainerException 143 { 144 } 146 147 public void dispose() 148 { 149 UMOContainerContext container; 150 for (Iterator iterator = containers.values().iterator(); iterator.hasNext();) 151 { 152 container = (UMOContainerContext)iterator.next(); 153 container.dispose(); 154 } 155 containers.clear(); 156 containers = null; 157 } 158 159 public void initialise() throws InitialisationException 160 { 161 } 163 164 } 165 | Popular Tags |