Source Code Cross Referenced for ClassMap.java in  » Byte-Code » Javassist » javassist » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Byte Code » Javassist » javassist 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Javassist, a Java-bytecode translator toolkit.
003:         * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
004:         *
005:         * The contents of this file are subject to the Mozilla Public License Version
006:         * 1.1 (the "License"); you may not use this file except in compliance with
007:         * the License.  Alternatively, the contents of this file may be used under
008:         * the terms of the GNU Lesser General Public License Version 2.1 or later.
009:         *
010:         * Software distributed under the License is distributed on an "AS IS" basis,
011:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
012:         * for the specific language governing rights and limitations under the
013:         * License.
014:         */
015:
016:        package javassist;
017:
018:        import javassist.bytecode.Descriptor;
019:
020:        /**
021:         * A hash table associating class names with different names.
022:         *
023:         * <p>This hashtable is used for replacing class names in a class
024:         * definition or a method body.  Define a subclass of this class
025:         * if a more complex mapping algorithm is needed.  For example,
026:         *
027:         * <ul><pre>class MyClassMap extends ClassMap {
028:         *   public Object get(Object jvmClassName) {
029:         *     String name = toJavaName((String)jvmClassName);
030:         *     if (name.startsWith("java."))
031:         *         return toJvmName("java2." + name.substring(5));
032:         *     else
033:         *         return super.get(jvmClassName);
034:         *   }
035:         * }</pre></ul>
036:         *
037:         * <p>This subclass maps <code>java.lang.String</code> to
038:         * <code>java2.lang.String</code>.  Note that <code>get()</code>
039:         * receives and returns the internal representation of a class name.
040:         * For example, the internal representation of <code>java.lang.String</code>
041:         * is <code>java/lang/String</code>.
042:         *
043:         * @see #get(Object)
044:         * @see CtClass#replaceClassName(ClassMap)
045:         * @see CtNewMethod#copy(CtMethod,String,CtClass,ClassMap)
046:         */
047:        public class ClassMap extends java.util.HashMap {
048:            private ClassMap parent;
049:
050:            /**
051:             * Constructs a hash table.
052:             */
053:            public ClassMap() {
054:                parent = null;
055:            }
056:
057:            ClassMap(ClassMap map) {
058:                parent = map;
059:            }
060:
061:            /**
062:             * Maps a class name to another name in this hashtable.
063:             * The names are obtained with calling <code>Class.getName()</code>.
064:             * This method translates the given class names into the
065:             * internal form used in the JVM before putting it in
066:             * the hashtable.
067:             *
068:             * @param oldname   the original class name
069:             * @param newname   the substituted class name.
070:             */
071:            public void put(CtClass oldname, CtClass newname) {
072:                put(oldname.getName(), newname.getName());
073:            }
074:
075:            /**
076:             * Maps a class name to another name in this hashtable.
077:             * If the hashtable contains another mapping from the same
078:             * class name, the old mapping is replaced. 
079:             * This method translates the given class names into the
080:             * internal form used in the JVM before putting it in
081:             * the hashtable.
082:             *
083:             * <p>If <code>oldname</code> is equivalent to
084:             * <code>newname</code>, then this method does not
085:             * perform anything; it does not record the mapping from
086:             * <code>oldname</code> to <code>newname</code>.  See
087:             * <code>fix</code> method.
088:             *
089:             * @param oldname   the original class name
090:             * @param newname   the substituted class name.
091:             * @see #fix(String)
092:             */
093:            public void put(String oldname, String newname) {
094:                if (oldname == newname)
095:                    return;
096:
097:                String oldname2 = toJvmName(oldname);
098:                String s = (String) get(oldname2);
099:                if (s == null || !s.equals(oldname2))
100:                    super .put(oldname2, toJvmName(newname));
101:            }
102:
103:            protected final void put0(Object oldname, Object newname) {
104:                super .put(oldname, newname);
105:            }
106:
107:            /**
108:             * Returns the class name to wihch the given <code>jvmClassName</code>
109:             * is mapped.  A subclass of this class should override this method.
110:             *
111:             * <p>This method receives and returns the internal representation of
112:             * class name used in the JVM.
113:             *
114:             * @see #toJvmName(String)
115:             * @see #toJavaName(String)
116:             */
117:            public Object get(Object jvmClassName) {
118:                Object found = super .get(jvmClassName);
119:                if (found == null && parent != null)
120:                    return parent.get(jvmClassName);
121:                else
122:                    return found;
123:            }
124:
125:            /**
126:             * Prevents a mapping from the specified class name to another name.
127:             */
128:            public void fix(CtClass clazz) {
129:                fix(clazz.getName());
130:            }
131:
132:            /**
133:             * Prevents a mapping from the specified class name to another name.
134:             */
135:            public void fix(String name) {
136:                String name2 = toJvmName(name);
137:                super .put(name2, name2);
138:            }
139:
140:            /**
141:             * Converts a class name into the internal representation used in
142:             * the JVM.
143:             */
144:            public static String toJvmName(String classname) {
145:                return Descriptor.toJvmName(classname);
146:            }
147:
148:            /**
149:             * Converts a class name from the internal representation used in
150:             * the JVM to the normal one used in Java.
151:             */
152:            public static String toJavaName(String classname) {
153:                return Descriptor.toJavaName(classname);
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.