1 16 package org.apache.cocoon.webapps.authentication.configuration; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.apache.avalon.framework.configuration.Configuration; 22 import org.apache.avalon.framework.configuration.ConfigurationException; 23 import org.apache.cocoon.ProcessingException; 24 import org.apache.excalibur.source.SourceParameters; 25 26 33 public final class ApplicationConfiguration 34 implements java.io.Serializable { 35 36 37 private String name; 38 39 40 private String loadResource; 41 42 43 private String saveResource; 44 45 46 private SourceParameters loadResourceParameters; 47 48 49 private SourceParameters saveResourceParameters; 50 51 52 private boolean loadOnDemand = false; 53 54 55 private HandlerConfiguration handler; 56 57 58 private Map configurations; 59 60 61 private boolean saveOnLogout = false; 62 63 66 public ApplicationConfiguration(HandlerConfiguration handler, String name) 67 throws ProcessingException { 68 this.handler = handler; 69 this.name = name; 70 if (name.indexOf('_') != -1 71 || name.indexOf(':') != -1 72 || name.indexOf('/') != -1) { 73 throw new ProcessingException("application name must not contain one of the characters ':','_' or '/'."); 74 } 75 this.configurations = new HashMap (3, 2); 76 } 77 78 81 public void configure(Configuration appconf) 82 throws ConfigurationException { 83 Configuration child = null; 84 85 this.loadOnDemand = appconf.getAttributeAsBoolean("loadondemand", false); 87 88 child = appconf.getChild("load", false); 90 if (child != null) { 91 this.loadResource = child.getAttribute("uri"); 92 this.loadResourceParameters = SourceParameters.create(child); 93 } 94 95 child = appconf.getChild("save", false); 97 if (child != null) { 98 this.saveResource = child.getAttribute("uri"); 99 this.saveResourceParameters = SourceParameters.create(child); 100 this.saveOnLogout = child.getAttributeAsBoolean("saveOnLogout", false); 101 } 102 103 Configuration[] configurations = appconf.getChildren("configuration"); 105 if (configurations != null) { 106 for(int i = 0; i < configurations.length; i++) { 107 child = configurations[i]; 108 String value = child.getAttribute("name"); 109 if (this.getConfiguration(value) != null) { 110 throw new ConfigurationException("Configuration names must be unique for application " + this.name + ": " + value); 111 } 112 this.configurations.put(value, child); 113 } 114 } 115 } 116 117 120 public String getName() { 121 return this.name; 122 } 123 124 127 public HandlerConfiguration getHandler() { 128 return this.handler; 129 } 130 131 134 public String getLoadResource() { 135 return this.loadResource; 136 } 137 138 141 public String getSaveResource() { 142 return this.saveResource; 143 } 144 145 148 public SourceParameters getLoadResourceParameters() { 149 return this.loadResourceParameters; 150 } 151 152 155 public SourceParameters getSaveResourceParameters() { 156 return this.saveResourceParameters; 157 } 158 159 160 public boolean saveOnLogout() { 161 return this.saveOnLogout; 162 } 163 164 public boolean getLoadOnDemand() { 165 return loadOnDemand; 166 } 167 168 171 public Configuration getConfiguration(String name) { 172 return (Configuration)this.configurations.get(name); 173 } 174 175 } 176 | Popular Tags |