KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > util > NoSuchMethodException


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.util;
23
24 import java.lang.reflect.Method JavaDoc;
25
26 /**
27  * A better NoSuchMethodException which can take a Method object
28  * and formats the detail message based on in.
29  *
30  * @version <tt>$Revision: 1958 $</tt>
31  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
32  */

33 public class NoSuchMethodException
34    extends java.lang.NoSuchMethodException JavaDoc
35 {
36    /**
37     * Construct a <tt>NoSuchMethodException</tt> with the specified detail
38     * message.
39     *
40     * @param msg Detail message.
41     */

42    public NoSuchMethodException(String JavaDoc msg) {
43       super(msg);
44    }
45
46    /**
47     * Construct a <tt>NoSuchMethodException</tt> using the given method
48     * object to construct the detail message.
49     *
50     * @param method Method to determine detail message from.
51     */

52    public NoSuchMethodException(Method JavaDoc method) {
53       super(format(method));
54    }
55
56    /**
57     * Construct a <tt>NoSuchMethodException</tt> using the given method
58     * object to construct the detail message.
59     *
60     * @param msg Detail message prefix.
61     * @param method Method to determine detail message suffix from.
62     */

63    public NoSuchMethodException(String JavaDoc msg, Method JavaDoc method) {
64       super(msg + format(method));
65    }
66    
67    /**
68     * Construct a <tt>NoSuchMethodException</tt> with no detail.
69     */

70    public NoSuchMethodException() {
71       super();
72    }
73
74    /**
75     * Return a string representation of the given method object.
76     */

77    public static String JavaDoc format(Method JavaDoc method)
78    {
79       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
80       buffer.append(method.getName()).append("(");
81       Class JavaDoc[] paramTypes = method.getParameterTypes();
82       for (int count = 0; count < paramTypes.length; count++) {
83          if (count > 0) {
84             buffer.append(",");
85          }
86          buffer.
87             append(paramTypes[count].getName().substring(paramTypes[count].getName().lastIndexOf(".")+1));
88       }
89       buffer.append(")");
90
91       return buffer.toString();
92    }
93 }
94
Popular Tags