001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package de.schlund.pfixxml.config.impl;
020:
021: import java.util.Collections;
022: import java.util.Enumeration;
023: import java.util.LinkedHashMap;
024: import java.util.Map;
025: import java.util.Properties;
026:
027: import de.schlund.pfixcore.auth.AuthConstraint;
028: import de.schlund.pfixcore.generator.IWrapper;
029: import de.schlund.pfixcore.workflow.ContextResource;
030: import de.schlund.pfixcore.workflow.State;
031: import de.schlund.pfixcore.workflow.app.ResdocFinalizer;
032: import de.schlund.pfixxml.config.PageRequestConfig;
033:
034: /**
035: * Stores configuration for a PageRequest
036: *
037: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
038: */
039: public class PageRequestConfigImpl implements SSLOption, Cloneable,
040: PageRequestConfig {
041:
042: private String pageName = null;
043: private String copyFromPage = null;
044: // private boolean storeXML = true;
045: private boolean ssl = false;
046: private Class<? extends State> stateClass = null;
047: private Class<? extends State> defaultStaticStateClass = null;
048: private Class<? extends State> defaultIWrapperStateClass = null;
049: private Class<? extends ResdocFinalizer> finalizer = null;
050: private String authPrefix = null;
051: private Class<? extends IWrapper> authClass = null;
052: private LinkedHashMap<String, Class<? extends IWrapper>> auxwrappers = new LinkedHashMap<String, Class<? extends IWrapper>>();
053: private LinkedHashMap<String, IWrapperConfigImpl> iwrappers = new LinkedHashMap<String, IWrapperConfigImpl>();
054: private LinkedHashMap<String, Class<? extends ContextResource>> resources = new LinkedHashMap<String, Class<? extends ContextResource>>();
055: private Properties props = new Properties();
056: private Policy policy = Policy.ANY;
057: private boolean requiresToken = false;
058: private AuthConstraint authConstraint;
059: private String defaultFlow = null;
060:
061: public void setPageName(String page) {
062: this .pageName = page;
063: }
064:
065: /* (non-Javadoc)
066: * @see de.schlund.pfixxml.config.PageRequestConfig#getPageName()
067: */
068: public String getPageName() {
069: return this .pageName;
070: }
071:
072: // public void setStoreXML(boolean store) {
073: // this.storeXML = store;
074: // }
075:
076: /* (non-Javadoc)
077: * @see de.schlund.pfixxml.config.PageRequestConfig#isStoreXML()
078: */
079: // public boolean isStoreXML() {
080: // return this.storeXML;
081: // }
082: public void setSSL(boolean forceSSL) {
083: this .ssl = forceSSL;
084: }
085:
086: /* (non-Javadoc)
087: * @see de.schlund.pfixxml.config.PageRequestConfig#isSSL()
088: */
089: public boolean isSSL() {
090: return this .ssl;
091: }
092:
093: public void setState(Class<? extends State> clazz) {
094: this .stateClass = clazz;
095: }
096:
097: /* (non-Javadoc)
098: * @see de.schlund.pfixxml.config.PageRequestConfig#getState()
099: */
100: public Class<? extends State> getState() {
101: if (this .stateClass != null) {
102: return this .stateClass;
103: } else {
104: if (this .iwrappers.size() > 0) {
105: return this .defaultIWrapperStateClass;
106: } else {
107: return this .defaultStaticStateClass;
108: }
109: }
110: }
111:
112: public void setCopyFromPage(String page) {
113: this .copyFromPage = page;
114: }
115:
116: public String getCopyFromPage() {
117: return this .copyFromPage;
118: }
119:
120: public boolean isCopy() {
121: return (this .copyFromPage != null);
122: }
123:
124: public void setDefaultStaticState(Class<? extends State> clazz) {
125: this .defaultStaticStateClass = clazz;
126: }
127:
128: public void setDefaultIHandlerState(Class<? extends State> clazz) {
129: this .defaultIWrapperStateClass = clazz;
130: }
131:
132: public void setIWrapperPolicy(Policy policy) {
133: this .policy = policy;
134: }
135:
136: /* (non-Javadoc)
137: * @see de.schlund.pfixxml.config.PageRequestConfig#getIWrapperPolicy()
138: */
139: public Policy getIWrapperPolicy() {
140: return this .policy;
141: }
142:
143: public void setFinalizer(Class<? extends ResdocFinalizer> clazz) {
144: this .finalizer = clazz;
145: }
146:
147: /* (non-Javadoc)
148: * @see de.schlund.pfixxml.config.PageRequestConfig#getFinalizer()
149: */
150: public Class<? extends ResdocFinalizer> getFinalizer() {
151: return this .finalizer;
152: }
153:
154: public void addIWrapper(IWrapperConfigImpl config) {
155: this .iwrappers.put(config.getPrefix(), config);
156: }
157:
158: public Map<String, IWrapperConfigImpl> getIWrappers() {
159: return Collections.unmodifiableMap(this .iwrappers);
160: }
161:
162: public void addAuxWrapper(String prefix,
163: Class<? extends IWrapper> clazz) {
164: this .auxwrappers.put(prefix, clazz);
165: }
166:
167: /* (non-Javadoc)
168: * @see de.schlund.pfixxml.config.PageRequestConfig#getAuxWrappers()
169: */
170: public Map<String, Class<? extends IWrapper>> getAuxWrappers() {
171: return this .auxwrappers;
172: }
173:
174: public void addContextResource(String prefix,
175: Class<? extends ContextResource> clazz) {
176: this .resources.put(prefix, clazz);
177: }
178:
179: /* (non-Javadoc)
180: * @see de.schlund.pfixxml.config.PageRequestConfig#getContextResources()
181: */
182: public Map<String, Class<? extends ContextResource>> getContextResources() {
183: return this .resources;
184: }
185:
186: public void setProperties(Properties props) {
187: this .props = new Properties();
188: Enumeration<?> e = props.propertyNames();
189: while (e.hasMoreElements()) {
190: String propname = (String) e.nextElement();
191: this .props.setProperty(propname, props
192: .getProperty(propname));
193: }
194: }
195:
196: /* (non-Javadoc)
197: * @see de.schlund.pfixxml.config.PageRequestConfig#getProperties()
198: */
199: public Properties getProperties() {
200: return this .props;
201: }
202:
203: public void addAuthWrapper(String prefix,
204: Class<? extends IWrapper> clazz) {
205: this .authPrefix = prefix;
206: this .authClass = clazz;
207: if (this .stateClass == null) {
208: // Create class object at runtime due to build dependency problems
209: try {
210: this
211: .setState(Class
212: .forName(
213: "de.schlund.pfixcore.workflow.app.DefaultAuthIWrapperState")
214: .asSubclass(State.class));
215: } catch (ClassNotFoundException e) {
216: throw new RuntimeException(
217: "Class de.schlund.pfixcore.workflow.app.DefaultAuthIWrapperState could not be loaded!",
218: e);
219: }
220: }
221: }
222:
223: /* (non-Javadoc)
224: * @see de.schlund.pfixxml.config.PageRequestConfig#getAuthWrapperPrefix()
225: */
226: public String getAuthWrapperPrefix() {
227: return this .authPrefix;
228: }
229:
230: /* (non-Javadoc)
231: * @see de.schlund.pfixxml.config.PageRequestConfig#getAuthWrapperClass()
232: */
233: public Class<? extends IWrapper> getAuthWrapperClass() {
234: return this .authClass;
235: }
236:
237: public boolean requiresToken() {
238: return requiresToken;
239: }
240:
241: public void setRequiresToken(boolean requiresToken) {
242: this .requiresToken = requiresToken;
243: }
244:
245: public AuthConstraint getAuthConstraint() {
246: return authConstraint;
247: }
248:
249: public void setAuthConstraint(AuthConstraint authConstraint) {
250: this .authConstraint = authConstraint;
251: }
252:
253: public String getDefaultFlow() {
254: return defaultFlow;
255: }
256:
257: public void setDefaultFlow(String defaultFlow) {
258: this .defaultFlow = defaultFlow;
259: }
260:
261: /* (non-Javadoc)
262: * @see java.lang.Object#clone()
263: */
264: protected Object clone() throws CloneNotSupportedException {
265: return super.clone();
266: }
267: }
|