KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > yworks > yguard > obf > YGuardRule


1 /**
2  * YGuard -- an obfuscation library for Java(TM) classfiles.
3  *
4  * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
5  * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library 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 library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * The author may be contacted at yguard@yworks.com
22  *
23  * Java and all Java-based marks are trademarks or registered
24  * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
25  */

26 package com.yworks.yguard.obf;
27
28 import java.io.*;
29 import java.util.*;
30 import java.lang.reflect.Modifier JavaDoc;
31
32 /**
33  * Representation of RGS script files entry.
34  *
35  * @author Mark Welsh
36  */

37 public class YGuardRule
38 {
39     public static final int PUBLIC = Modifier.PUBLIC;
40     public static final int PROTECTED = Modifier.PROTECTED;
41     public static final int FRIENDLY = 4096;
42     public static final int PRIVATE = Modifier.PRIVATE;
43         
44     public static final int LEVEL_NONE = 0;
45     public static final int LEVEL_PUBLIC = PUBLIC;
46     public static final int LEVEL_PROTECTED = PROTECTED | LEVEL_PUBLIC;
47     public static final int LEVEL_FRIENDLY = FRIENDLY | LEVEL_PROTECTED;
48     public static final int LEVEL_PRIVATE = PRIVATE | LEVEL_FRIENDLY;
49
50     // Constants -------------------------------------------------------------
51
public static final int TYPE_ATTR = 0;
52     public static final int TYPE_CLASS = 1;
53     public static final int TYPE_FIELD = 2;
54     public static final int TYPE_METHOD = 3;
55     public static final int TYPE_PACKAGE_MAP = 4;
56     public static final int TYPE_CLASS_MAP = 5;
57     public static final int TYPE_FIELD_MAP = 6;
58     public static final int TYPE_METHOD_MAP = 7;
59     public static final int TYPE_SOURCE_ATTRIBUTE_MAP = 8;
60     public static final int TYPE_LINE_NUMBER_MAPPER = 9;
61     public static final int TYPE_ATTR2 = 10;
62     public static final int TYPE_PACKAGE = 11;
63
64     // Fields ----------------------------------------------------------------
65
public int type;
66     public String JavaDoc name;
67     public String JavaDoc descriptor;
68     public String JavaDoc obfName;
69     public LineNumberTableMapper lineNumberTableMapper;
70     public int retainFields = LEVEL_NONE;
71     public int retainMethods = LEVEL_NONE;
72     public int retainClasses = LEVEL_PRIVATE;
73
74     // Instance Methods-------------------------------------------------------
75
public YGuardRule(int type, String JavaDoc name)
76     {
77       this.type = type;
78       this.name = name;
79       this.descriptor = null;
80       this.obfName = null;
81       this.lineNumberTableMapper = null;
82     }
83     public YGuardRule(int type, String JavaDoc name, String JavaDoc descriptor)
84     {
85         this.obfName = null;
86         this.type = type;
87         this.name = name;
88         this.descriptor = descriptor;
89         this.lineNumberTableMapper = null;
90     }
91
92     public YGuardRule(String JavaDoc className, LineNumberTableMapper lineNumberTableMapper) {
93       this.descriptor = null;
94       this.obfName = null;
95       this.name = className;
96       this.type = TYPE_LINE_NUMBER_MAPPER;
97       this.lineNumberTableMapper = lineNumberTableMapper;
98     }
99
100     public void logProperties(PrintWriter pw){
101       if (type == TYPE_LINE_NUMBER_MAPPER){
102         lineNumberTableMapper.logProperties(pw);
103       }
104     }
105
106     public String JavaDoc toString()
107     {
108         return typeToString(type)+" "+ name + " "
109         + descriptor+" fields: "+methodToString(retainFields)
110         +" methods: "+methodToString(retainMethods)
111         +" classes: "+methodToString(retainClasses);
112     }
113
114     public static String JavaDoc typeToString(int type){
115       switch (type){
116         default: return "Unknown type "+type;
117         case TYPE_ATTR:
118           return "ATTRIBUTE";
119         case TYPE_ATTR2:
120           return "ATTRIBUTE PER CLASS";
121         case TYPE_CLASS:
122           return "CLASS";
123         case TYPE_CLASS_MAP:
124           return "CLASS_MAP";
125         case TYPE_FIELD:
126           return "FIELD";
127         case TYPE_FIELD_MAP:
128           return "FIELD_MAP";
129         case TYPE_METHOD:
130           return "METHOD";
131         case TYPE_METHOD_MAP:
132           return "METHOD_MAP";
133         case TYPE_PACKAGE_MAP:
134           return "PACKAGE_MAP";
135         case TYPE_SOURCE_ATTRIBUTE_MAP:
136           return "SOURCE_ATTRIBUTE_MAP";
137         case TYPE_LINE_NUMBER_MAPPER:
138           return "LINE_NUMBER_MAPPER";
139         case TYPE_PACKAGE:
140           return "PACKAGE";
141       }
142     }
143     
144     public static String JavaDoc methodToString(int modifier){
145       switch (modifier){
146         default: return "Unknown modifier "+modifier;
147         case LEVEL_NONE:
148           return "LEVEL_NONE";
149         case LEVEL_FRIENDLY:
150           return "LEVEL_FRIENDLY";
151         case LEVEL_PRIVATE:
152           return "LEVEL_PRIVATE";
153         case LEVEL_PROTECTED:
154           return "LEVEL_PROTECTED";
155         case LEVEL_PUBLIC:
156           return "LEVEL_PUBLIC";
157       }
158     }
159 }
160
Popular Tags