KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > enhancer > lib > MethodRenamer


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: MethodRenamer.java 405 2006-04-24 16:42:17Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.enhancer.lib;
27
28 /**
29  * Change the name of a method.
30  * @author Florent Benoit
31  */

32 public final class MethodRenamer {
33
34     /**
35      * Prefix for renamed method.
36      */

37     public static final String JavaDoc PREFIX = "original$EasyBeans$";
38
39     /**
40      * Utility class, no constructor.
41      */

42     private MethodRenamer() {
43
44     }
45
46     /**
47      * Encodes a name by prefixing it with the prefix.
48      * @param name method name to rename/encode
49      * @return the encoded name
50      */

51     public static String JavaDoc encode(final String JavaDoc name) {
52         if (name == null) {
53             throw new IllegalArgumentException JavaDoc("Cannot encode a null name");
54         }
55         return PREFIX + name;
56     }
57
58     /**
59      * Decodes a method by removing the prefix.
60      * @param name encoded method name to decode.
61      * @return the decoded name.
62      */

63     public static String JavaDoc decode(final String JavaDoc name) {
64         if (name == null || !name.startsWith(PREFIX)) {
65             throw new IllegalArgumentException JavaDoc("Given name '" + name + " don't start with prefix " + PREFIX);
66         }
67         return name.substring(PREFIX.length());
68     }
69
70 }
71
Popular Tags