001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.runtime.impl;
032:
033: import java.util.*;
034: import java.util.concurrent.ConcurrentMap;
035: import net.sf.retrotranslator.runtime.asm.Type;
036:
037: /**
038: * @author Taras Puchko
039: */
040: public class SignatureList {
041:
042: private static final Map<String, String> map = getMap();
043:
044: private SignatureList() {
045: }
046:
047: public static String getSignature(String className) {
048: return map.get(className);
049: }
050:
051: private static String getAccessToken() {
052: Type randomAccessType = Type
053: .getType("Ljava/util/RandomAccess;");
054: for (Class anInterface : ArrayList.class.getInterfaces()) {
055: if (anInterface.getName().equals(
056: randomAccessType.getClassName())) {
057: return randomAccessType.getDescriptor();
058: }
059: }
060: return "";
061: }
062:
063: private static Map<String, String> getMap() {
064: String originalName = "java/util/concurrent/ConcurrentMap";
065: Map<String, String> map = new Hashtable<String, String>();
066: String actualName = ConcurrentMap.class.getName().replace('.',
067: '/');
068: if (!actualName.endsWith(originalName)) {
069: return map;
070: }
071: String accessToken = getAccessToken();
072: String prefix = actualName.substring(0, actualName.length()
073: - originalName.length());
074: map.put("java/util/Collection",
075: "<E:Ljava/lang/Object;>Ljava/lang/Object;");
076: map
077: .put("java/util/Set",
078: "<E:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Collection<TE;>;");
079: map
080: .put("java/util/List",
081: "<E:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Collection<TE;>;");
082: map
083: .put(prefix + "java/util/Queue",
084: "<E:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Collection<TE;>;");
085: map
086: .put("java/util/Map",
087: "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/lang/Object;");
088: map
089: .put("java/util/SortedSet",
090: "<E:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Set<TE;>;");
091: map
092: .put(
093: "java/util/SortedMap",
094: "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Map<TK;TV;>;");
095: map.put(prefix + "java/util/concurrent/BlockingQueue",
096: "<E:Ljava/lang/Object;>Ljava/lang/Object;L" + prefix
097: + "java/util/Queue<TE;>;");
098: map
099: .put(
100: prefix + "java/util/concurrent/ConcurrentMap",
101: "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Map<TK;TV;>;");
102: map
103: .put(
104: "java/util/HashSet",
105: "<E:Ljava/lang/Object;>Ljava/util/AbstractSet<TE;>;"
106: + "Ljava/util/Set<TE;>;Ljava/lang/Cloneable;Ljava/io/Serializable;");
107: map
108: .put(
109: "java/util/TreeSet",
110: "<E:Ljava/lang/Object;>Ljava/util/AbstractSet<TE;>;Ljava/util/SortedSet<TE;>;"
111: + "Ljava/lang/Cloneable;Ljava/io/Serializable;");
112: map
113: .put(
114: "java/util/LinkedHashSet",
115: "<E:Ljava/lang/Object;>Ljava/util/HashSet<TE;>;Ljava/util/Set<TE;>;"
116: + "Ljava/lang/Cloneable;Ljava/io/Serializable;");
117: map
118: .put(
119: "java/util/ArrayList",
120: "<E:Ljava/lang/Object;>Ljava/util/AbstractList<TE;>;Ljava/util/List<TE;>;"
121: + accessToken
122: + "Ljava/lang/Cloneable;Ljava/io/Serializable;");
123: map
124: .put(
125: "java/util/LinkedList",
126: "<E:Ljava/lang/Object;>Ljava/util/AbstractSequentialList<TE;>;"
127: + "Ljava/util/List<TE;>;Ljava/lang/Cloneable;Ljava/io/Serializable;");
128: map
129: .put(
130: prefix + "java/util/PriorityQueue",
131: "<E:Ljava/lang/Object;>L"
132: + prefix
133: + "java/util/AbstractQueue<TE;>;Ljava/io/Serializable;");
134: map
135: .put(
136: "java/util/HashMap",
137: "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/util/AbstractMap<TK;TV;>;"
138: + "Ljava/util/Map<TK;TV;>;Ljava/lang/Cloneable;Ljava/io/Serializable;");
139: map
140: .put(
141: "java/util/TreeMap",
142: "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/util/AbstractMap<TK;TV;>;"
143: + "Ljava/util/SortedMap<TK;TV;>;Ljava/lang/Cloneable;Ljava/io/Serializable;");
144: map
145: .put("java/util/LinkedHashMap",
146: "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/util/HashMap<TK;TV;>;");
147: map
148: .put(
149: "java/util/Vector",
150: "<E:Ljava/lang/Object;>Ljava/util/AbstractList<TE;>;Ljava/util/List<TE;>;"
151: + accessToken
152: + "Ljava/lang/Cloneable;Ljava/io/Serializable;");
153: map
154: .put(
155: "java/util/Hashtable",
156: "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/util/Dictionary<TK;TV;>;"
157: + "Ljava/util/Map<TK;TV;>;Ljava/lang/Cloneable;Ljava/io/Serializable;");
158: map
159: .put(
160: "java/util/WeakHashMap",
161: "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/util/AbstractMap<TK;TV;>;Ljava/util/Map<TK;TV;>;");
162: map
163: .put(
164: "java/util/IdentityHashMap",
165: "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/util/AbstractMap<TK;TV;>;"
166: + "Ljava/util/Map<TK;TV;>;Ljava/io/Serializable;Ljava/lang/Cloneable;");
167: map
168: .put(
169: prefix
170: + "java/util/concurrent/CopyOnWriteArrayList",
171: "<E:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/List<TE;>;"
172: + accessToken
173: + "Ljava/lang/Cloneable;Ljava/io/Serializable;");
174: map
175: .put(prefix
176: + "java/util/concurrent/CopyOnWriteArraySet",
177: "<E:Ljava/lang/Object;>Ljava/util/AbstractSet<TE;>;Ljava/io/Serializable;");
178: map
179: .put(
180: prefix
181: + "java/util/concurrent/ConcurrentLinkedQueue",
182: "<E:Ljava/lang/Object;>L"
183: + prefix
184: + "java/util/AbstractQueue<TE;>;L"
185: + prefix
186: + "java/util/Queue<TE;>;Ljava/io/Serializable;");
187: map
188: .put(
189: prefix
190: + "java/util/concurrent/LinkedBlockingQueue",
191: "<E:Ljava/lang/Object;>L"
192: + prefix
193: + "java/util/AbstractQueue<TE;>;L"
194: + prefix
195: + "java/util/concurrent/BlockingQueue<TE;>;Ljava/io/Serializable;");
196: map
197: .put(
198: prefix
199: + "java/util/concurrent/ArrayBlockingQueue",
200: "<E:Ljava/lang/Object;>L"
201: + prefix
202: + "java/util/AbstractQueue<TE;>;L"
203: + prefix
204: + "java/util/concurrent/BlockingQueue<TE;>;Ljava/io/Serializable;");
205: map
206: .put(
207: prefix
208: + "java/util/concurrent/PriorityBlockingQueue",
209: "<E:Ljava/lang/Object;>L"
210: + prefix
211: + "java/util/AbstractQueue<TE;>;L"
212: + prefix
213: + "java/util/concurrent/BlockingQueue<TE;>;Ljava/io/Serializable;");
214: map.put(prefix + "java/util/concurrent/DelayQueue", "<E::L"
215: + prefix + "java/util/concurrent/Delayed;>L" + prefix
216: + "java/util/AbstractQueue<TE;>;L" + prefix
217: + "java/util/concurrent/BlockingQueue<TE;>;");
218: map
219: .put(
220: prefix
221: + "java/util/concurrent/SynchronousQueue",
222: "<E:Ljava/lang/Object;>L"
223: + prefix
224: + "java/util/AbstractQueue<TE;>;L"
225: + prefix
226: + "java/util/concurrent/BlockingQueue<TE;>;Ljava/io/Serializable;");
227: map
228: .put(
229: prefix
230: + "java/util/concurrent/ConcurrentHashMap",
231: "<K:Ljava/lang/Object;V:Ljava/lang/Object;>L"
232: + prefix
233: + "java/util/AbstractMap<TK;TV;>;L"
234: + prefix
235: + "java/util/concurrent/ConcurrentMap<TK;TV;>;Ljava/io/Serializable;");
236: map
237: .put("java/util/AbstractCollection",
238: "<E:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Collection<TE;>;");
239: map
240: .put("java/util/AbstractSet",
241: "<E:Ljava/lang/Object;>Ljava/util/AbstractCollection<TE;>;Ljava/util/Set<TE;>;");
242: map
243: .put(
244: "java/util/AbstractList",
245: "<E:Ljava/lang/Object;>Ljava/util/AbstractCollection<TE;>;Ljava/util/List<TE;>;");
246: map.put("java/util/AbstractSequentialList",
247: "<E:Ljava/lang/Object;>Ljava/util/AbstractList<TE;>;");
248: map.put(prefix + "java/util/AbstractQueue",
249: "<E:Ljava/lang/Object;>L" + prefix
250: + "java/util/AbstractCollection<TE;>;L"
251: + prefix + "java/util/Queue<TE;>;");
252: map
253: .put(
254: "java/util/AbstractMap",
255: "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Map<TK;TV;>;");
256: map.put("java/util/Enumeration",
257: "<E:Ljava/lang/Object;>Ljava/lang/Object;");
258: map.put("java/util/Iterator",
259: "<E:Ljava/lang/Object;>Ljava/lang/Object;");
260: map
261: .put("java/util/ListIterator",
262: "<E:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Iterator<TE;>;");
263: map.put("java/lang/Comparable",
264: "<T:Ljava/lang/Object;>Ljava/lang/Object;");
265: map.put("java/util/Comparator",
266: "<T:Ljava/lang/Object;>Ljava/lang/Object;");
267: return map;
268: }
269:
270: }
|