KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > webapps > authentication > configuration > ApplicationConfiguration


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.webapps.authentication.configuration;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
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 /**
27  * This object stores information about an application configuration
28  * inside a handler configuration.
29  *
30  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
31  * @version CVS $Id: ApplicationConfiguration.java 30932 2004-07-29 17:35:38Z vgritsenko $
32 */

33 public final class ApplicationConfiguration
34 implements java.io.Serializable JavaDoc {
35
36     /** The unique name of the handler */
37     private String JavaDoc name;
38
39     /** The load resource (optional) */
40     private String JavaDoc loadResource;
41
42     /** The save resource (optional) */
43     private String JavaDoc saveResource;
44
45     /** The load resource parameters (optional) */
46     private SourceParameters loadResourceParameters;
47
48     /** The save resource parameters (optional) */
49     private SourceParameters saveResourceParameters;
50
51     /** Is the application loaded on demand */
52     private boolean loadOnDemand = false;
53
54     /** The corresponding handler */
55     private HandlerConfiguration handler;
56
57     /** The configuration fragments */
58     private Map JavaDoc configurations;
59
60     /** Save the context on logout */
61     private boolean saveOnLogout = false;
62
63     /**
64      * Construct a new application handler
65      */

66     public ApplicationConfiguration(HandlerConfiguration handler, String JavaDoc 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 JavaDoc(3, 2);
76     }
77
78     /**
79      * Configure an application
80      */

81     public void configure(Configuration appconf)
82     throws ConfigurationException {
83         Configuration child = null;
84
85         // test for loadondemand attribute
86
this.loadOnDemand = appconf.getAttributeAsBoolean("loadondemand", false);
87
88         // get load resource (optinal)
89
child = appconf.getChild("load", false);
90         if (child != null) {
91             this.loadResource = child.getAttribute("uri");
92             this.loadResourceParameters = SourceParameters.create(child);
93         }
94
95         // get save resource (optional)
96
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         // get configurations (optional)
104
Configuration[] configurations = appconf.getChildren("configuration");
105         if (configurations != null) {
106             for(int i = 0; i < configurations.length; i++) {
107                 child = configurations[i];
108                 String JavaDoc 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     /**
118      * Get the application name.
119      */

120     public String JavaDoc getName() {
121         return this.name;
122     }
123
124     /**
125      * Get the handler
126      */

127     public HandlerConfiguration getHandler() {
128         return this.handler;
129     }
130
131     /**
132      * Get the load resource
133      */

134     public String JavaDoc getLoadResource() {
135         return this.loadResource;
136     }
137
138     /**
139      * Get the save resource
140      */

141     public String JavaDoc getSaveResource() {
142         return this.saveResource;
143     }
144
145     /**
146      * Get the load resource parameters
147      */

148     public SourceParameters getLoadResourceParameters() {
149         return this.loadResourceParameters;
150     }
151
152     /**
153      * Get the save resource parameters
154      */

155     public SourceParameters getSaveResourceParameters() {
156         return this.saveResourceParameters;
157     }
158
159     /** Should we save on logout? */
160     public boolean saveOnLogout() {
161         return this.saveOnLogout;
162     }
163
164     public boolean getLoadOnDemand() {
165         return loadOnDemand;
166     }
167
168     /**
169      * Get the configuration
170      */

171     public Configuration getConfiguration(String JavaDoc name) {
172         return (Configuration)this.configurations.get(name);
173     }
174
175 }
176
Popular Tags