KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Globals


1
2 /*
3  * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4  * California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has
5  * intellectual property rights relating to technology embodied in the product
6  * that is described in this document. In particular, and without limitation,
7  * these intellectual property rights may include one or more of the U.S.
8  * patents listed at http://www.sun.com/patents and one or more additional
9  * patents or pending patent applications in the U.S. and in other countries.
10  * U.S. Government Rights - Commercial software. Government users are subject
11  * to the Sun Microsystems, Inc. standard license agreement and applicable
12  * provisions of the FAR and its supplements. Use is subject to license terms.
13  * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
14  * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This
15  * product is covered and controlled by U.S. Export Control laws and may be
16  * subject to the export or import laws in other countries. Nuclear, missile,
17  * chemical biological weapons or nuclear maritime end uses or end users,
18  * whether direct or indirect, are strictly prohibited. Export or reexport
19  * to countries subject to U.S. embargo or to entities identified on U.S.
20  * export exclusion lists, including, but not limited to, the denied persons
21  * and specially designated nationals lists is strictly prohibited.
22  */

23
24
25 import java.io.*;
26 import java.util.*;
27
28 public class Globals {
29
30   // The mappings from old id's to new id's.
31
static Hashtable mappings = new Hashtable();
32
33   // A table of targets of all known mappings.
34
static Hashtable mapTargets = new Hashtable();
35
36   // These id's may not be changed.
37
static Hashtable noChangeIds = new Hashtable();
38
39   // These id's should be used for mappings.
40
static Hashtable useIds = new Hashtable();
41
42   // The location of the input and output directories.
43
static File inpDir, outDir;
44
45   // Set to true by Java parser if class has a main program.
46
static boolean mainExists;
47
48   // Returns the map of old to obfuscated id. If map does not
49
// exist, it is created.
50
static String JavaDoc map(String JavaDoc str) {
51     Object JavaDoc obj = mappings.get(str);
52     if (obj != null) {
53       return (String JavaDoc)obj;
54     }
55     if (useIds.isEmpty()) {
56       String JavaDoc newId = "O0" + counter++;
57       mappings.put(str, newId);
58       return newId;
59     } else {
60       obj = useIds.keys().nextElement();
61       useIds.remove(obj);
62       String JavaDoc newId = (String JavaDoc)obj;
63       mappings.put(str, newId);
64       return newId;
65     }
66   }
67
68   // A counter used to generate new identifiers
69
static int counter = 0;
70
71 }
72
Popular Tags