1 10 11 package org.mule.impl.container; 12 13 import org.mule.MuleManager; 14 import org.mule.umo.manager.ContainerException; 15 import org.mule.umo.manager.ObjectNotFoundException; 16 import org.mule.util.TemplateParser; 17 18 import java.io.Reader ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 39 public class PropertiesContainerContext extends AbstractContainerContext 40 { 41 42 protected Map systemProperties; 43 protected Map properties; 44 protected boolean loadSystemProperties = true; 45 protected boolean enableTemplates = false; 46 47 protected TemplateParser templateParser = TemplateParser.createAntStyleParser(); 48 49 public PropertiesContainerContext() 50 { 51 super("properties"); 52 } 53 54 public void configure(Reader configuration) throws ContainerException 55 { 56 throw new UnsupportedOperationException ("configure"); 57 } 58 59 70 public Object getComponent(Object key) throws ObjectNotFoundException 71 { 72 if (key == null) 73 { 74 throw new ObjectNotFoundException("null"); 75 } 76 Object value = MuleManager.getInstance().getProperty(key.toString()); 77 if (value == null) 78 { 79 throw new ObjectNotFoundException(key.toString()); 80 } 81 if (value instanceof String && enableTemplates) 82 { 83 value = templateParser.parse(MuleManager.getInstance().getProperties(), value.toString()); 84 } 85 return value; 86 } 87 88 public Map getSystemProperties() 89 { 90 return systemProperties; 91 } 92 93 public void setSystemProperties(Map properties) 94 { 95 this.systemProperties = properties; 96 String value; 97 Map.Entry entry; 98 if (systemProperties != null) 99 { 100 for (Iterator iterator = systemProperties.entrySet().iterator(); iterator.hasNext();) 101 { 102 entry = (Map.Entry )iterator.next(); 103 value = entry.getValue().toString(); 104 value = templateParser.parse(systemProperties, value); 105 value = templateParser.parse(MuleManager.getInstance().getProperties(), value); 106 System.setProperty(entry.getKey().toString(), value); 107 } 108 } 109 110 if (loadSystemProperties) 111 { 112 Map props = System.getProperties(); 113 114 for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();) 115 { 116 entry = (Map.Entry )iterator.next(); 117 value = entry.getValue().toString(); 118 value = templateParser.parse(MuleManager.getInstance().getProperties(), value.toString()); 119 MuleManager.getInstance().setProperty(entry.getKey(), value); 120 } 121 } 122 } 123 124 public Map getProperties() 125 { 126 return properties; 127 } 128 129 public void setProperties(Map properties) 130 { 131 this.properties = properties; 132 if (properties != null) 133 { 134 Map.Entry entry; 135 String value; 136 for (Iterator iterator = properties.entrySet().iterator(); iterator.hasNext();) 137 { 138 entry = (Map.Entry )iterator.next(); 139 value = entry.getValue().toString(); 140 value = templateParser.parse(MuleManager.getInstance().getProperties(), value); 141 MuleManager.getInstance().setProperty(entry.getKey(), value); 142 } 143 } 144 } 145 } 146 | Popular Tags |