001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.webapps.authentication.configuration;
018:
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: import org.apache.avalon.framework.configuration.Configuration;
023: import org.apache.avalon.framework.configuration.ConfigurationException;
024: import org.apache.cocoon.ProcessingException;
025: import org.apache.excalibur.source.SourceParameters;
026:
027: /**
028: * This object stores information about an application configuration
029: * inside a handler configuration.
030: *
031: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
032: * @deprecated This block is deprecated and will be removed in future versions.
033: * @version CVS $Id: ApplicationConfiguration.java 433543 2006-08-22 06:22:54Z crossley $
034: */
035: public final class ApplicationConfiguration implements
036: java.io.Serializable {
037:
038: /** The unique name of the handler */
039: private String name;
040:
041: /** The load resource (optional) */
042: private String loadResource;
043:
044: /** The save resource (optional) */
045: private String saveResource;
046:
047: /** The load resource parameters (optional) */
048: private SourceParameters loadResourceParameters;
049:
050: /** The save resource parameters (optional) */
051: private SourceParameters saveResourceParameters;
052:
053: /** Is the application loaded on demand */
054: private boolean loadOnDemand = false;
055:
056: /** The corresponding handler */
057: private HandlerConfiguration handler;
058:
059: /** The configuration fragments */
060: private Map configurations;
061:
062: /** Save the context on logout */
063: private boolean saveOnLogout = false;
064:
065: /**
066: * Construct a new application handler
067: */
068: public ApplicationConfiguration(HandlerConfiguration handler,
069: String name) throws ProcessingException {
070: this .handler = handler;
071: this .name = name;
072: if (name.indexOf('_') != -1 || name.indexOf(':') != -1
073: || name.indexOf('/') != -1) {
074: throw new ProcessingException(
075: "application name must not contain one of the characters ':','_' or '/'.");
076: }
077: this .configurations = new HashMap(3, 2);
078: }
079:
080: /**
081: * Configure an application
082: */
083: public void configure(Configuration appconf)
084: throws ConfigurationException {
085: Configuration child = null;
086:
087: // test for loadondemand attribute
088: this .loadOnDemand = appconf.getAttributeAsBoolean(
089: "loadondemand", false);
090:
091: // get load resource (optinal)
092: child = appconf.getChild("load", false);
093: if (child != null) {
094: this .loadResource = child.getAttribute("uri");
095: this .loadResourceParameters = SourceParameters
096: .create(child);
097: }
098:
099: // get save resource (optional)
100: child = appconf.getChild("save", false);
101: if (child != null) {
102: this .saveResource = child.getAttribute("uri");
103: this .saveResourceParameters = SourceParameters
104: .create(child);
105: this .saveOnLogout = child.getAttributeAsBoolean(
106: "saveOnLogout", false);
107: }
108:
109: // get configurations (optional)
110: Configuration[] configurations = appconf
111: .getChildren("configuration");
112: if (configurations != null) {
113: for (int i = 0; i < configurations.length; i++) {
114: child = configurations[i];
115: String value = child.getAttribute("name");
116: if (this .getConfiguration(value) != null) {
117: throw new ConfigurationException(
118: "Configuration names must be unique for application "
119: + this .name + ": " + value);
120: }
121: this .configurations.put(value, child);
122: }
123: }
124: }
125:
126: /**
127: * Get the application name.
128: */
129: public String getName() {
130: return this .name;
131: }
132:
133: /**
134: * Get the handler
135: */
136: public HandlerConfiguration getHandler() {
137: return this .handler;
138: }
139:
140: /**
141: * Get the load resource
142: */
143: public String getLoadResource() {
144: return this .loadResource;
145: }
146:
147: /**
148: * Get the save resource
149: */
150: public String getSaveResource() {
151: return this .saveResource;
152: }
153:
154: /**
155: * Get the load resource parameters
156: */
157: public SourceParameters getLoadResourceParameters() {
158: return this .loadResourceParameters;
159: }
160:
161: /**
162: * Get the save resource parameters
163: */
164: public SourceParameters getSaveResourceParameters() {
165: return this .saveResourceParameters;
166: }
167:
168: /** Should we save on logout? */
169: public boolean saveOnLogout() {
170: return this .saveOnLogout;
171: }
172:
173: public boolean getLoadOnDemand() {
174: return loadOnDemand;
175: }
176:
177: /**
178: * Get the configuration
179: */
180: public Configuration getConfiguration(String name) {
181: return (Configuration) this.configurations.get(name);
182: }
183:
184: }
|