001: /*
002: * Copyright 2005 jWic group (http://www.jwic.de)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: * de.jwic.base.ApplicationSetupBean
017: * Created on 14.04.2005
018: * $Id: ApplicationSetupBean.java,v 1.2 2006/08/14 09:34:58 lordsam Exp $
019: */
020: package de.jwic.base;
021:
022: import java.lang.reflect.Constructor;
023: import java.util.Properties;
024:
025: /**
026: * Bean-style application setup.
027: * @author Florian Lippisch
028: * @version $Revision: 1.2 $
029: */
030: public class ApplicationSetupBean implements IApplicationSetup {
031:
032: private static final long serialVersionUID = 1L;
033:
034: private String name = null;
035: private String classname = null;
036: private String rootControlName = "root";
037: private String rootControlClassName = null;
038: private boolean serializable = true;
039: private boolean singleSession = false;
040: private boolean requireAuthentication = false;
041: private boolean useAjaxRendering = true;
042: private Properties properties = new Properties();
043:
044: /* (non-Javadoc)
045: * @see de.jwic.base.IApplicationSetup#getName()
046: */
047: public String getName() {
048: return name;
049: }
050:
051: /* (non-Javadoc)
052: * @see de.jwic.base.IApplicationSetup#getRootControlName()
053: */
054: public String getRootControlName() {
055: return rootControlName;
056: }
057:
058: /* (non-Javadoc)
059: * @see de.jwic.base.IApplicationSetup#createRootControl()
060: */
061: public IApplication createApplication() {
062:
063: try {
064: if (classname != null) {
065: return (IApplication) Class.forName(classname)
066: .newInstance();
067: }
068: // create a dummy application that creates the root class. This is
069: // for compatibility with jWic v2.x.
070: IApplication app = new Application() {
071: private static final long serialVersionUID = 1L;
072:
073: public Control createRootControl(
074: IControlContainer container) {
075: try {
076: Class clazz = Class
077: .forName(rootControlClassName);
078: Control control;
079: Constructor cstr = clazz
080: .getConstructor(new Class[] {
081: IControlContainer.class,
082: String.class });
083: control = (Control) cstr
084: .newInstance(new Object[] { container,
085: rootControlName });
086: return control;
087: } catch (Exception e) {
088: throw new ControlNotAvailableException(
089: "Can not create instance of '"
090: + rootControlClassName
091: + "'. Cause: " + e, e);
092: }
093: }
094: };
095: return app;
096: } catch (Exception e) {
097: throw new JWicException("Can not create application '"
098: + classname + "':" + e, e);
099: }
100: }
101:
102: /* (non-Javadoc)
103: * @see de.jwic.base.IApplicationSetup#isSerializable()
104: */
105: public boolean isSerializable() {
106: return serializable;
107: }
108:
109: /* (non-Javadoc)
110: * @see de.jwic.base.IApplicationSetup#isSingleSession()
111: */
112: public boolean isSingleSession() {
113: return singleSession;
114: }
115:
116: /* (non-Javadoc)
117: * @see de.jwic.base.IApplicationSetup#isRequireAuthentication()
118: */
119: public boolean isRequireAuthentication() {
120: return requireAuthentication;
121: }
122:
123: /* (non-Javadoc)
124: * @see de.jwic.base.IApplicationSetup#getProperty(java.lang.String)
125: */
126: public String getProperty(String key) {
127: if (properties == null) {
128: return null;
129: }
130: return properties.getProperty(key);
131: }
132:
133: /**
134: * @return Returns the properties.
135: */
136: public Properties getProperties() {
137: return properties;
138: }
139:
140: /**
141: * @param properties The properties to set.
142: */
143: public void setProperties(Properties properties) {
144: this .properties = properties;
145: }
146:
147: public void setProperty(String key, String value) {
148: if (properties == null) {
149: properties = new Properties();
150: }
151: properties.setProperty(key, value);
152: }
153:
154: /**
155: * @return Returns the rootControlClassName.
156: */
157: public String getRootControlClassName() {
158: return rootControlClassName;
159: }
160:
161: /**
162: * @param rootControlClassName The rootControlClassName to set.
163: */
164: public void setRootControlClassName(String rootControlClassName) {
165: this .rootControlClassName = rootControlClassName;
166: }
167:
168: /**
169: * @param name The name to set.
170: */
171: public void setName(String name) {
172: this .name = name;
173: }
174:
175: /**
176: * @param requireAuthentication The requireAuthentication to set.
177: */
178: public void setRequireAuthentication(boolean requireAuthentication) {
179: this .requireAuthentication = requireAuthentication;
180: }
181:
182: /**
183: * @param rootControlName The rootControlName to set.
184: */
185: public void setRootControlName(String rootControlName) {
186: this .rootControlName = rootControlName;
187: }
188:
189: /**
190: * @param serializable The serializable to set.
191: */
192: public void setSerializable(boolean serializable) {
193: this .serializable = serializable;
194: }
195:
196: /**
197: * @param singleSession The singleSession to set.
198: */
199: public void setSingleSession(boolean singleSession) {
200: this .singleSession = singleSession;
201: }
202:
203: /* (non-Javadoc)
204: * @see de.jwic.base.IApplicationSetup#isUseAjaxRendering()
205: */
206: public boolean isUseAjaxRendering() {
207: return useAjaxRendering;
208: }
209:
210: /**
211: * @param useAjaxRendering The useAjaxRendering to set.
212: */
213: public void setUseAjaxRendering(boolean useAjaxRendering) {
214: this .useAjaxRendering = useAjaxRendering;
215: }
216:
217: /**
218: * Get the classname of the IApplication implementation.
219: * @return Returns the classname.
220: */
221: public String getClassname() {
222: return classname;
223: }
224:
225: /**
226: * Set the classname of the IApplication implementation.
227: * @param classname The classname to set.
228: */
229: public void setClassname(String classname) {
230: this.classname = classname;
231: }
232: }
|