File Source: ExportedService.java
/*
P/P * Method: com.dmdirc.plugins.ExportedService__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22 package com.dmdirc.plugins;
23
24 import java.lang.reflect.Method;
25 import java.lang.reflect.InvocationTargetException;
26
27 /**
28 * Object to allow interaction with Exported methods
29 */
30 public class ExportedService {
31 /** Method we will be executing today! */
32 final Method myMethod;
33
34 /** Object we will be executing this method on. */
35 final Object myObject;
36
37 /**
38 * Create a new ExportedService object.
39 *
40 * @param myClass class method is in.
41 * @param methodName Name of method
42 */
43 public ExportedService(final Class myClass, final String methodName) {
/*
P/P * Method: void com.dmdirc.plugins.ExportedService(Class, String)
*
* Postconditions:
* init'ed(this.myMethod)
* this.myObject == null
*/
44 this(myClass, methodName, null);
45 }
46
47 /**
48 * Create a new ExportedService object.
49 *
50 * @param myClass class method is in.
51 * @param methodName Name of method
52 * @param object Object to execute this method on.
53 */
/*
P/P * Method: void com.dmdirc.plugins.ExportedService(Class, String, Object)
*
* Presumptions:
* arr$.length@59 <= 232-1
* arr$[i$]@59 != null
* java.lang.Class:getDeclaredMethods(...)@59 != null
* java.lang.reflect.Method:getName(...)@61 != null
*
* Postconditions:
* init'ed(this.myMethod)
* this.myObject == object
* init'ed(this.myObject)
*
* Test Vectors:
* myClass: Inverse{null}, Addr_Set{null}
* java.lang.String:equals(...)@61: {0}, {1}
*/
54 public ExportedService(final Class<?> myClass, final String methodName, final Object object) {
55 myObject = object;
56 if (myClass == null) {
57 myMethod = null;
58 } else {
59 final Method[] methods = myClass.getDeclaredMethods();
60 for (Method m : methods) {
61 if (m.getName().equals(methodName)) {
62 myMethod = m;
63 return;
64 }
65 }
66 myMethod = null;
67 }
68 }
69
70 /**
71 * Execute the method.
72 *
73 * @param args Arguments to pass to method
74 * @return result of executing the method
75 */
76 public Object execute(final Object... args) {
/*
P/P * Method: Object execute(Object[])
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.myMethod: Inverse{null}, Addr_Set{null}
*/
77 if (myMethod == null) { return null; }
78
79 try {
80 return myMethod.invoke(myObject, args);
81 } catch (IllegalAccessException iae) {
82 return null;
83 } catch (IllegalArgumentException iae) {
84 return null;
85 } catch (InvocationTargetException ite) {
86 return null;
87 }
88 }
89 }
SofCheck Inspector Build Version : 2.17854
| ExportedService.java |
2009-Jun-25 01:54:24 |
| ExportedService.class |
2009-Sep-02 17:04:13 |