001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.examples.panorama.startup.impl;
016
017 import java.lang.reflect.Method;
018
019 import org.apache.examples.panorama.startup.Executable;
020
021 /**
022 * Used to access the legacy startup code that is in the form
023 * of a public static method (usually <code>init()</code>) on some
024 * class.
025 *
026 * @author Howard Lewis Ship
027 */
028 public class ExecuteStatic implements Executable
029 {
030 private String _methodName = "init";
031 private Class _targetClass;
032
033 public void execute() throws Exception
034 {
035 Method m = _targetClass.getMethod(_methodName, (Class []) null);
036
037 m.invoke(null, (Object []) null);
038 }
039
040 /**
041 * Sets the name of the method to invoke; if not set, the default is <code>init</code>.
042 * The target class must have a public static method with that name taking no
043 * parameters.
044 */
045 public void setMethodName(String string)
046 {
047 _methodName = string;
048 }
049
050 /**
051 * Sets the class to invoke the method on.
052 */
053 public void setTargetClass(Class targetClass)
054 {
055 _targetClass = targetClass;
056 }
057
058 }