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.test.TestLauncher
017: * Created on 18.04.2005
018: * $Id: TestLauncher.java,v 1.2 2006/08/14 09:34:58 lordsam Exp $
019: */
020: package de.jwic.test;
021:
022: import java.lang.reflect.Constructor;
023:
024: import de.jwic.base.Control;
025: import de.jwic.base.ControlContainer;
026: import de.jwic.base.IApplication;
027: import de.jwic.base.IControlContainer;
028: import de.jwic.base.JWicException;
029: import de.jwic.base.Page;
030: import de.jwic.controls.LabelControl;
031:
032: /**
033: * Launches a jwic application from the URL. The TestLauncher is just a plain
034: * container that adds one child control specified in the starting URL. This is
035: * helpfull if you want to quickly test a control without creating an
036: * ApplicationSetup for it.
037: *
038: * @author Florian Lippisch
039: * @version $Revision: 1.2 $
040: */
041: public class TestLauncher extends Page {
042:
043: private static final long serialVersionUID = 1L;
044:
045: /**
046: * @param container
047: */
048: public TestLauncher(IControlContainer container) {
049: super (container);
050: init();
051: }
052:
053: /**
054: * @param container
055: * @param name
056: */
057: public TestLauncher(IControlContainer container, String name) {
058: super (container, name);
059: init();
060: }
061:
062: /* (non-Javadoc)
063: * @see de.jwic.base.ControlContainer#actionPerformed(java.lang.String, java.lang.String)
064: */
065: public void actionPerformed(String actionId, String parameter) {
066:
067: if (actionId.equals("exit")) {
068: getSessionContext().exit();
069: }
070:
071: }
072:
073: /* (non-Javadoc)
074: * @see de.jwic.base.Page#init()
075: */
076: private void init() {
077:
078: String classname = getSessionContext()
079: .getInitParameter("class");
080: if (classname == null) {
081: throw new JWicException("parameter class missing.");
082: }
083:
084: try {
085: Class clazz = Class.forName(classname);
086: if (IApplication.class.isAssignableFrom(clazz)) {
087: // create application
088: ControlContainer container = new ControlContainer(this ,
089: "app");
090: IApplication app = (IApplication) clazz.newInstance();
091: app.initialize(getSessionContext());
092: app.createRootControl(container);
093:
094: } else if (Control.class.isAssignableFrom(clazz)) {
095: Constructor cstr = clazz.getConstructor(new Class[] {
096: IControlContainer.class, String.class });
097: cstr.newInstance(new Object[] { this , "app" });
098:
099: } else {
100: throw new IllegalArgumentException(
101: "Specified class is not an application nor a control.");
102: }
103: } catch (Exception e) {
104: removeControl("app");
105: LabelControl lbl = new LabelControl(this , "app");
106: lbl.setText("Error loading control '" + classname + "':"
107: + e);
108: }
109:
110: }
111:
112: }
|