|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ExecuteStatic.java | - | 100% | 100% | 100% |
|
||||||||||||||
| 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 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 | { | |
| 30 | private String _methodName = "init"; | |
| 31 | private Class _targetClass; | |
| 32 | ||
| 33 | 1 | public void execute() throws Exception |
| 34 | { | |
| 35 | 1 | Method m = _targetClass.getMethod(_methodName, null); |
| 36 | ||
| 37 | 1 | 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 | 1 | public void setMethodName(String string) |
| 46 | { | |
| 47 | 1 | _methodName = string; |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * Sets the class to invoke the method on. | |
| 52 | */ | |
| 53 | 1 | public void setTargetClass(Class targetClass) |
| 54 | { | |
| 55 | 1 | _targetClass = targetClass; |
| 56 | } | |
| 57 | ||
| 58 | } |
|
||||||||||