KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > panorama > startup > impl > ExecuteStatic


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// 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 com.panorama.startup.impl;
16
17 import java.lang.reflect.Method;
18
19 import com.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 {
30     private String _methodName = "init";
31     private Class _targetClass;
32
33     public void execute() throws Exception
34     {
35         Method m = _targetClass.getMethod(_methodName, null);
36
37         m.invoke(null, null);
38     }
39
40     /**
41      * Sets the name of the method to invoke; if not set, the default is <code>init</code>.
42      * The target class must have a public static method with that name taking no
43      * parameters.
44      */

45     public void setMethodName(String string)
46     {
47         _methodName = string;
48     }
49
50     /**
51      * Sets the class to invoke the method on.
52      */

53     public void setTargetClass(Class targetClass)
54     {
55         _targetClass = targetClass;
56     }
57
58 }
59
Popular Tags