View Javadoc

1   /*
2    * Copyright (C) 2004 TiongHiang Lee
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not,  write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * Email: thlee@onemindsoft.org
19   */
20  
21  package org.onemind.commons.invoke;
22  
23  import org.onemind.commons.java.lang.reflect.ReflectUtils;
24  /***
25   * An abstract implementation of InvocableFunction
26   * @author TiongHiang Lee (thlee@onemindsoft.org)
27   * @version $Id: AbstractInvocableFunction.java,v 1.6 2005/01/24 05:51:54 thlee Exp $ $Name:  $
28   */
29  public abstract class AbstractInvocableFunction implements InvocableFunction
30  {
31  
32      /*** the name **/
33      private String _name;
34  
35      /*** the method **/
36      private Class[] _argTypes;
37      
38      /***
39       * Constructor
40       * @param name the name
41       */
42      public AbstractInvocableFunction(String name)
43      {
44          this(name, null);
45      }
46  
47      /***
48       * Constructor
49       * @param name the name
50       * @param argTypes the argument types
51       */
52      public AbstractInvocableFunction(String name, Class[] argTypes)
53      {
54          _name = name;
55          _argTypes = argTypes;
56      }
57  
58      /***
59       * {@inheritDoc}
60       */
61      public boolean canInvokeOn(Class[] argTypes)
62      {
63          return ReflectUtils.isCompatible(_argTypes, argTypes);
64      }
65  
66      /***
67       * Return the argTypes
68       * @return the argTypes.
69       */
70      public final Class[] getArgTypes()
71      {
72          return _argTypes;
73      }
74  
75      /***
76       * Return the name
77       * @return the name.
78       */
79      public final String getName()
80      {
81          return _name;
82      }
83      
84      /*** 
85       * {@inheritDoc}
86       */
87      public String toString()
88      {
89          return ReflectUtils.toMethodString(_name, _argTypes);
90      }
91  }