KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > model > EntryPoint


1 /*
2  * $Id: EntryPoint.java 4259 2006-12-14 03:12:07Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.model;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15
16 import java.lang.reflect.InvocationTargetException JavaDoc;
17 import java.lang.reflect.Method JavaDoc;
18
19 /**
20  * <code>EntryPoint</code> is a method on a Mule-managed component that is invoked
21  * when an event for the component is received.
22  */

23 public class EntryPoint
24 {
25     /**
26      * logger used by this class
27      */

28     protected static final Log logger = LogFactory.getLog(EntryPoint.class);
29
30     /**
31      * the method on the object to invoke
32      */

33     private Method JavaDoc method;
34
35     /**
36      * Creates a new EntryPoint with the given method
37      *
38      * @param method the method to invoke on the component
39      */

40     public EntryPoint(Method JavaDoc method)
41     {
42         this.method = method;
43     }
44
45     /**
46      * Will invoke the entry point method on the given component
47      *
48      * @param component the component to invoke
49      * @param arg the argument to pass to the method invocation
50      * @return An object (if any) returned by the invocation
51      * @throws InvocationTargetException
52      * @throws IllegalAccessException
53      */

54     public Object JavaDoc invoke(Object JavaDoc component, Object JavaDoc arg)
55         throws InvocationTargetException JavaDoc, IllegalAccessException JavaDoc
56     {
57         String JavaDoc methodCall = null;
58         if (logger.isDebugEnabled())
59         {
60             methodCall = component.getClass().getName() + "." + method.getName() + "("
61                          + arg.getClass().getName() + ")";
62             logger.debug("Invoking " + methodCall);
63         }
64
65         Object JavaDoc result = method.invoke(component, new Object JavaDoc[]{arg});
66         if (logger.isDebugEnabled())
67         {
68             logger.debug("Result of call " + methodCall + " is " + result);
69         }
70         return result;
71     }
72
73     /**
74      * Determines if the <code>EntryPoint</code> is avoid method or not
75      *
76      * @return true if the method is void
77      */

78     public boolean isVoid()
79     {
80         return method.getReturnType().getName().equals("void");
81     }
82
83     /**
84      * Gets the method name
85      *
86      * @return the method name
87      */

88     public String JavaDoc getName()
89     {
90         if (method == null)
91         {
92             return null;
93         }
94         return method.getName();
95     }
96
97     /**
98      * Gets the argument type for the method
99      *
100      * @return the argument type. It should never be null
101      */

102     public Class JavaDoc getParameterType()
103     {
104         return method.getParameterTypes()[0];
105     }
106
107     /**
108      * Gets the method return type of the method
109      *
110      * @return the return type or null if the method is void
111      */

112     public Class JavaDoc getReturnType()
113     {
114         if (isVoid())
115         {
116             return null;
117         }
118         else
119         {
120             return method.getReturnType();
121         }
122     }
123
124     protected void setMethod(Method JavaDoc method)
125     {
126         this.method = method;
127     }
128
129     protected Method JavaDoc getMethod()
130     {
131         return method;
132     }
133 }
134
Popular Tags