KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > properties > MethodProperty


1 package net.sourceforge.pmd.properties;
2
3 import java.lang.reflect.Method JavaDoc;
4
5 /**
6  * @author Brian Remedios
7  */

8 public class MethodProperty extends AbstractPMDProperty {
9     
10     /**
11      * Constructor for MethodProperty.
12      * @param theName String
13      * @param theDescription String
14      * @param theDefault Object
15      * @param theUIOrder float
16      */

17     public MethodProperty(String JavaDoc theName, String JavaDoc theDescription, Object JavaDoc theDefault, float theUIOrder) {
18         super(theName, theDescription, theDefault, theUIOrder);
19     }
20
21     /**
22      * Method type.
23      * @return Class
24      * @see net.sourceforge.pmd.PropertyDescriptor#type()
25      */

26     public Class JavaDoc type() {
27         return Method JavaDoc.class;
28     }
29
30     /**
31      * Method valueFrom.
32      * @param propertyString String
33      * @return Object
34      * @throws IllegalArgumentException
35      * @see net.sourceforge.pmd.PropertyDescriptor#valueFrom(String)
36      */

37     public Object JavaDoc valueFrom(String JavaDoc propertyString) throws IllegalArgumentException JavaDoc {
38         
39         Class JavaDoc cls = classIn(propertyString);
40         String JavaDoc methodName = methodNameIn(propertyString);
41         Class JavaDoc[] parameterTypes = parameterTypesIn(propertyString);
42         
43         try {
44             return cls.getMethod(methodName, parameterTypes);
45         } catch (Exception JavaDoc e) {
46             throw new IllegalArgumentException JavaDoc("invalid method: " + propertyString);
47         }
48     }
49
50     private Class JavaDoc classIn(String JavaDoc propertyString) throws IllegalArgumentException JavaDoc {
51         
52         int dotPos = propertyString.lastIndexOf('.');
53         String JavaDoc className = propertyString.substring(0, dotPos);
54         
55         try {
56             return Class.forName(className);
57             } catch (Exception JavaDoc ex) {
58                 throw new IllegalArgumentException JavaDoc("class not found: " + className);
59             }
60     }
61     
62     private String JavaDoc methodNameIn(String JavaDoc propertyString) throws IllegalArgumentException JavaDoc {
63         
64         int dotPos = propertyString.lastIndexOf('.');
65         return propertyString.substring(dotPos);
66     }
67     
68     private Class JavaDoc[] parameterTypesIn(String JavaDoc propertyString) {
69         return null;
70     }
71 }
72
Popular Tags