KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > javaguard > TreeItem


1 /**
2  * JavaGuard -- an obfuscation package for Java classfiles.
3  *
4  * Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
5  * Copyright (c) 2002 Thorsten Heit (theit@gmx.de)
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 theit@gmx.de.
22  *
23  *
24  * $Id: TreeItem.java,v 1.6 2002/05/24 08:55:31 glurk Exp $
25  */

26 package net.sf.javaguard;
27
28
29 import net.sf.javaguard.classfile.ClassFile;
30
31
32 /** Item that forms a tree structure and can represent a package level, a class,
33  * or a method or field.
34  *
35  * @author <a HREF="mailto:markw@retrologic.com">Mark Welsh</a>
36  * @author <a HREF="mailto:theit@gmx.de">Thorsten Heit</a>
37  */

38 public class TreeItem {
39   /** Holds whether the method or field element is synthetic. */
40   private boolean isSynthetic;
41   /** Access level (interpret using java.lang.reflect.Modifier). */
42   private int access;
43   /** The owner of the current element. */
44   private ClassTree classTree = null;
45   /** The parent of the current tree element. */
46   private TreeItem parent = null;
47   
48   /** Holds a separator string preceeding this level's name. */
49   private String JavaDoc separator = ClassFile.SEP_REGULAR;
50   /** Original name of this item. */
51   private String JavaDoc inName = null;
52   /** Output name of this item. */
53   private String JavaDoc outName = null;
54   /** Holds whether the name has been fixed in some way. */
55   private boolean isFixed = false;
56   /** Holds whether this entry is constrained by a .script entry. */
57   private boolean isFromScript = false;
58   /** Holds whether this entry is constrained by a .script_map entry. */
59   private boolean isFromScriptMap = false;
60   
61   /** Holds whether the element should be ignored when generating obfuscated
62    * names. */

63   private boolean ignoreElement;
64   
65   /** Holds whether the element must be obfuscated. */
66   private boolean forceObfuscate;
67   
68   /** Holds whether the element is matched by a script entry. */
69   private boolean scriptEntryMatch;
70   
71   
72   
73   
74   /** Default constructor that creates a new tree item.
75    * @param parent the parent of the tree item; may be null
76    * @param name the name of the tree item
77    */

78   public TreeItem(TreeItem parent, String JavaDoc name) {
79     setParent(parent);
80     this.inName = name;
81     if (null != getParent()) {
82       classTree = getParent().getClassTree();
83     }
84     setIgnoreElement(false);
85     setForceObfuscate(false);
86     setScriptEntryMatch(false);
87   }
88   
89   
90   
91   
92   /** Sets the access modifiers.
93    * @param access the access modifiers
94    * @see #getModifiers
95    */

96   protected void setModifiers(int access) {
97     this.access = access;
98   }
99   
100   
101   /** Return the current access modifiers.
102    * @return access modifiers
103    * @see #setModifiers
104    */

105   public int getModifiers() {
106     return access;
107   }
108   
109   
110   
111   
112   /** Return the original name of the entry.
113    * @return original name of the entry without the package prefix
114    */

115   public String JavaDoc getInName() {
116     return inName;
117   }
118   
119   
120   /** Construct and return the full original name of the entry.
121    * @return full original name in the form <code>package.subpackage.class</code>
122    */

123   public String JavaDoc getFullInName() {
124     if (null == getParent()) {
125       return "";
126     } else if (null == getParent().getParent()) {
127       return getInName();
128     } else {
129       return getParent().getFullInName() + getSeparator() + getInName();
130     }
131   }
132   
133   
134   /** Construct and return the full obfuscated name of the entry.
135    * @return full obfuscated name of the entry
136    */

137   public String JavaDoc getFullOutName() {
138     if (null == getParent()) {
139       return "";
140     } else if (getParent().getParent() == null) {
141       return getOutName();
142     } else {
143       return getParent().getFullOutName() + getSeparator() + getOutName();
144     }
145   }
146   
147   
148   
149   
150   /** Set the output name of the entry.
151    * @param outName output name of the entry
152    */

153   public void setOutName(String JavaDoc outName) {
154     this.outName = outName;
155     isFixed = true;
156   }
157   
158   /** Return the output name of the entry, obfuscated or original.
159    * @return output name of the entry without package prefix
160    */

161   public String JavaDoc getOutName() {
162     if (null != outName) {
163       return outName;
164     }
165     return getInName();
166   }
167   
168   
169   /** Return the obfuscated name of the entry.
170    * @return obfuscated name of the entry; may be null if not yet set
171    */

172   public String JavaDoc getObfName() {
173     return outName;
174   }
175   
176   
177   
178   
179   /** Signals that this constraint comes from an entry in the script file.
180    */

181   public void setFromScript() {
182     isFromScript = true;
183   }
184   
185   
186   /** Returns whether the element is constrained by an entry in the script file.
187    * @return true if the element is constrained by an entry in the script file;
188    * false else
189    */

190   public boolean isFromScript() {
191     return isFromScript;
192   }
193   
194   
195   
196   
197   /** Signals that this constraint comes from a mapping directive in the script
198    * file.
199    */

200   public void setFromScriptMap() {
201     isFromScriptMap = true;
202   }
203   
204   
205   /** Returns whether the element is constrained by a mapping directive in the
206    * script file.
207    * @return true if the element is constrained by a mapping directive in the
208    * script file; false else
209    */

210   public boolean isFromScriptMap() {
211     return isFromScriptMap;
212   }
213   
214   
215   
216   
217   /** Returns whether the entry has been fixed already in some way.
218    * @return true if the entry has been fixed; false else
219    */

220   public boolean isFixed() {
221     return isFixed;
222   }
223   
224   
225   
226   
227   /** Sets whether the element is synthetic.
228    * @param synthetic true if the element is synthetic; false else
229    * @see #isSynthetic
230    */

231   protected void setSynthetic(boolean synthetic) {
232     this.isSynthetic = synthetic;
233   }
234   
235   
236   /** Returns whether the element is synthetic.
237    * @return true if the element is synthetic; false else
238    * @see #setSynthetic
239    */

240   public boolean isSynthetic() {
241     return isSynthetic;
242   }
243   
244   
245   
246   
247   /** Set the parent element of the current one in the tree. Used when
248    * stitching in a Cl to replace a PlaceholderCl.
249    * @param parent the parent tree element
250    */

251   public void setParent(TreeItem parent) {
252     this.parent = parent;
253   }
254   
255   
256   /** Return the parent element in the tree.
257    * @return parent tree element
258    */

259   public TreeItem getParent() {
260     return parent;
261   }
262   
263   
264   
265   
266   /** Sets whether the current element should be ignored when generating the
267    * obfuscated name list or not.
268    * @param ignore true if the current element should be ignored; false else
269    * @see #canIgnoreElement
270    */

271   public void setIgnoreElement(boolean ignore) {
272     this.ignoreElement = ignore;
273   }
274   
275   /** Returns whether the current element should be ignored when generating
276    * obfuscated names.
277    * @return true if the current element should be ignored; false else
278    * @see #setIgnoreElement
279    */

280   public boolean canIgnoreElement() {
281     return ignoreElement;
282   }
283   
284   
285   
286   
287   /** Sets whether the current element must be obfuscated or not.
288    * @param force true if the current element must be obfuscated; false else
289    * @see #canForceObfuscate
290    */

291   public void setForceObfuscate(boolean force) {
292     this.forceObfuscate = force;
293   }
294   
295   /** Returns whether the current element must be obfuscated.
296    * @return true if the current element must be obfuscated; false else
297    * @see #setForceObfuscate
298    */

299   public boolean canForceObfuscate() {
300     return forceObfuscate;
301   }
302   
303   
304   
305   
306   /** Defines the class tree the tree item belongs to.
307    * @param ct the class tree
308    * @see #getClassTree
309    * @see ClassTree
310    */

311   protected void setClassTree(ClassTree ct) {
312     this.classTree = ct;
313   }
314   
315   
316   /** Returns the class tree the tree item belongs to.
317    * @return class tree
318    * @see #setClassTree
319    * @see ClassTree
320    */

321   protected ClassTree getClassTree() {
322     if (null == classTree) {
323       if (null != getParent()) {
324         setClassTree(getParent().getClassTree());
325       }
326     }
327     return classTree;
328   }
329   
330   
331   
332   
333   /** Sets the separator string to distinguish sub-levels.
334    * @param separator the separator string
335    * @see #getSeparator
336    */

337   protected void setSeparator(String JavaDoc separator) {
338     this.separator = separator;
339   }
340   
341   
342   /** Returns the separator string that allows to distinguish sub-levels.
343    * @return separator string
344    * @see #setSeparator
345    */

346   public String JavaDoc getSeparator() {
347     return separator;
348   }
349   
350   
351   
352   
353   /** Sets whether the tree item is matched by a script entry.
354    * @param match true if the item is matched by a script entry; false else
355    * @see #isScriptEntryMatch
356    */

357   public void setScriptEntryMatch(boolean match) {
358     this.scriptEntryMatch = match;
359   }
360   
361   
362   /** Returns whether the tree item is matched by a script entry.
363    * @return true if there's an entry that matches the tree item; false else
364    */

365   public boolean isScriptEntryMatch() {
366     return scriptEntryMatch;
367   }
368 }
369
Popular Tags