01: // Copyright 2004, 2005 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.examples.panorama.startup.impl;
16:
17: import java.lang.reflect.Method;
18:
19: import org.apache.examples.panorama.startup.Executable;
20:
21: /**
22: * Used to access the legacy startup code that is in the form
23: * of a public static method (usually <code>init()</code>) on some
24: * class.
25: *
26: * @author Howard Lewis Ship
27: */
28: public class ExecuteStatic implements Executable {
29: private String _methodName = "init";
30: private Class _targetClass;
31:
32: public void execute() throws Exception {
33: Method m = _targetClass.getMethod(_methodName, null);
34:
35: m.invoke(null, null);
36: }
37:
38: /**
39: * Sets the name of the method to invoke; if not set, the default is <code>init</code>.
40: * The target class must have a public static method with that name taking no
41: * parameters.
42: */
43: public void setMethodName(String string) {
44: _methodName = string;
45: }
46:
47: /**
48: * Sets the class to invoke the method on.
49: */
50: public void setTargetClass(Class targetClass) {
51: _targetClass = targetClass;
52: }
53:
54: }
|