1 16 package org.apache.cocoon.acting; 17 18 import org.apache.avalon.framework.configuration.Configuration; 19 import org.apache.avalon.framework.configuration.ConfigurationException; 20 import org.apache.avalon.framework.configuration.SAXConfigurationHandler; 21 import org.apache.cocoon.Constants; 22 import org.apache.cocoon.components.source.SourceUtil; 23 import org.apache.cocoon.environment.SourceResolver; 24 import org.apache.excalibur.source.Source; 25 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 39 public abstract class AbstractComplementaryConfigurableAction extends ConfigurableServiceableAction { 40 private static Map configurations = new HashMap (); 41 42 50 protected Configuration getConfiguration(String descriptor) throws ConfigurationException { 51 boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT; 52 if (this.settings.containsKey("reloadable")) 53 reloadable = Boolean.valueOf((String ) this.settings.get("reloadable")).booleanValue(); 54 return this.getConfiguration(descriptor, null, reloadable); 55 } 56 57 61 protected Configuration getConfiguration(String descriptor, boolean reloadable) throws ConfigurationException { 62 return this.getConfiguration( descriptor, null, reloadable ); 63 } 64 65 71 protected Configuration getConfiguration(String descriptor, SourceResolver resolver, boolean reloadable) throws ConfigurationException { 72 ConfigurationHelper conf = null; 73 74 if (descriptor == null) { 75 throw new ConfigurationException("The form descriptor is not set!"); 76 } 77 78 synchronized (AbstractComplementaryConfigurableAction.configurations) { 79 Source resource = null; 80 try { 81 resource = resolver.resolveURI(descriptor); 82 conf = (ConfigurationHelper) AbstractComplementaryConfigurableAction.configurations.get(resource.getURI()); 83 if (conf == null || (reloadable && conf.lastModified != resource.getLastModified())) { 84 getLogger().debug("(Re)Loading " + descriptor); 85 86 if (conf == null) { 87 conf = new ConfigurationHelper(); 88 } 89 90 SAXConfigurationHandler builder = new SAXConfigurationHandler(); 91 SourceUtil.parse(this.manager, resource, builder); 92 93 conf.lastModified = resource.getLastModified(); 94 conf.configuration = builder.getConfiguration(); 95 96 AbstractComplementaryConfigurableAction.configurations.put(resource.getURI(), conf); 97 } else { 98 getLogger().debug("Using cached configuration for " + descriptor); 99 } 100 } catch (Exception e) { 101 getLogger().error("Could not configure Database mapping environment", e); 102 throw new ConfigurationException("Error trying to load configurations for resource: " 103 + (resource == null ? "null" : resource.getURI())); 104 } finally { 105 resolver.release(resource); 106 } 107 } 108 109 return conf.configuration; 110 } 111 } 112 | Popular Tags |