001: /**
002: * JavaGuard -- an obfuscation package for Java classfiles.
003: *
004: * Copyright (c) 2002 Thorsten Heit (theit@gmx.de)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * The author may be contacted at theit@gmx.de.
021: *
022: *
023: * $Id: ScriptEntry.java,v 1.1.1.1 2002/04/03 13:49:45 glurk Exp $
024: */package net.sf.javaguard;
025:
026: /** Representation of a script file entry.
027: *
028: * @author <a href="mailto:theit@gmx.de">Thorsten Heit</a>
029: */
030: public class ScriptEntry {
031: /** The <code>int</code> value representing the <code>public</code> modifier. */
032: public static final int PUBLIC = 1;
033: /** The <code>int</code> value representing the <code>public</code> modifier. */
034: public static final int PROTECTED = 2;
035: /** The <code>int</code> value representing the <code>public</code> modifier. */
036: public static final int PRIVATE = 4;
037: /** The <code>int</code> value representing the <code>public</code> modifier. */
038: public static final int FIELD = 8;
039: /** The <code>int</code> value representing the <code>public</code> modifier. */
040: public static final int METHOD = 16;
041:
042: /** Holds the type of the entry.
043: * @see ScriptConstants
044: */
045: private int type;
046:
047: /** Holds the name.
048: * @see #info
049: */
050: private String name;
051:
052: /** Holds a Java descriptor for the class/field/method name. */
053: private String descriptor;
054:
055: /** Holds the mapped output name of a class, field or method entry.
056: * @see #name
057: */
058: private String mappedName;
059:
060: /** Holds additional attributes if the entry is a class entry.
061: */
062: private int attrs;
063:
064: /** Holds an additional info string if the entry is an attribute entry.
065: */
066: private String info;
067:
068: /** Creates a new entry that only consists of a type and a name.
069: * @param type the entry type
070: * @param name the name of the entry; may not be null
071: */
072: public ScriptEntry(int type, String name) {
073: this (type, name, null);
074: }
075:
076: /** Creates a new entry that has a type, a name and an additional descriptor.
077: * @param type the entry type
078: * @param name the name of the entry; may not be null
079: * @param descriptor a descriptor for the entry name
080: */
081: public ScriptEntry(int type, String name, String descriptor) {
082: this (type, name, descriptor, null);
083: }
084:
085: /** Creates a new entry that has a type, a name, an additional descriptor and
086: * an additional info string.
087: * @param type the entry type
088: * @param name the name of the entry; may not be null
089: * @param descriptor a descriptor for the entry name
090: * @param mappedName the mapped name
091: */
092: public ScriptEntry(int type, String name, String descriptor,
093: String mappedName) {
094: this (type, name, descriptor, mappedName, 0);
095: }
096:
097: /** Creates a new entry that has a type, a name, an additional descriptor, an
098: * optional mapped name and additional attributes.
099: * @param type the entry type
100: * @param name the name of the entry; may not be null
101: * @param descriptor a descriptor for the entry name
102: * @param mappedName the mapped name
103: * @param attrs additional attributes of the entry
104: */
105: public ScriptEntry(int type, String name, String descriptor,
106: String mappedName, int attrs) {
107: this (type, name, descriptor, mappedName, attrs, null);
108: }
109:
110: /** Creates a new entry that has a type, a name, an additional descriptor, an
111: * optional mapped name and additional attributes.
112: * @param type the entry type
113: * @param name the name of the entry; may not be null
114: * @param descriptor a descriptor for the entry name
115: * @param mappedName the mapped name
116: * @param attrs additional attributes of the entry
117: * @param info an additiona info string for the entry
118: */
119: public ScriptEntry(int type, String name, String descriptor,
120: String mappedName, int attrs, String info) {
121: setType(type);
122: setName(name);
123: setDescriptor(descriptor);
124: setMappedName(mappedName);
125: setAttrs(attrs);
126: setInfo(info);
127: }
128:
129: /** Sets the type of the entry.
130: * @param aType the type of the entry
131: * @see #getType
132: */
133: public void setType(int aType) {
134: this .type = aType;
135: }
136:
137: /** Returns the type of the current entry.
138: * @return type of the entry
139: * @see #setType
140: */
141: public int getType() {
142: return type;
143: }
144:
145: /** Sets the name property of the entry.
146: * @param name New value of property name.
147: * @see #getName
148: */
149: public void setName(String aName) {
150: this .name = aName;
151: }
152:
153: /** Returns the name property of the entry.
154: * @return Value of property name.
155: * @see #setName
156: */
157: public String getName() {
158: return name;
159: }
160:
161: /** Sets the descriptor property of the entry.
162: * @param descriptor New value of property descriptor.
163: * @see #getDescriptor
164: */
165: public void setDescriptor(String descriptor) {
166: this .descriptor = descriptor;
167: }
168:
169: /** Returns the descriptor property of the entry.
170: * @return Value of property descriptor.
171: * @see #setDescriptor
172: */
173: public String getDescriptor() {
174: return descriptor;
175: }
176:
177: /** Sets the mapped name for the current entry.
178: * @param name a string that contains the mapped name
179: * @see #getMappedName
180: */
181: public void setMappedName(String name) {
182: this .mappedName = name;
183: }
184:
185: /** Returns the mapped name of the current entry.
186: * @return the mapped name
187: * @see #setMappedName
188: */
189: public String getMappedName() {
190: return mappedName;
191: }
192:
193: /** Setter for property attrs.
194: * @param attrs New value of property attrs.
195: */
196: public void setAttrs(int attrs) {
197: this .attrs = attrs;
198: }
199:
200: /** Getter for property attrs.
201: * @return Value of property attrs.
202: */
203: public int getAttrs() {
204: return attrs;
205: }
206:
207: /** Sets whether the entry wants its public elements to be retained.
208: * @param canRetain true if the public elements are retained; false else
209: * @see #canRetainPublic
210: */
211: public void setRetainPublic(boolean canRetain) {
212: if (canRetain) {
213: setAttrs(getAttrs() | PUBLIC);
214: } else {
215: setAttrs(getAttrs() & ~PUBLIC);
216: }
217: }
218:
219: /** Returns whether the entry wants its public elements to be retained.
220: * @return true if the public elements are retained; false else
221: * @see #setRetainPublic
222: */
223: public boolean canRetainPublic() {
224: return true == ((getAttrs() & PUBLIC) != 0);
225: }
226:
227: /** Sets whether the entry wants its protected elements to be retained.
228: * @param canRetain true if the protected elements are retained; false else
229: * @see #canRetainProtected
230: */
231: public void setRetainProtected(boolean canRetain) {
232: if (canRetain) {
233: setAttrs(getAttrs() | PROTECTED);
234: } else {
235: setAttrs(getAttrs() & ~PROTECTED);
236: }
237: }
238:
239: /** Returns whether the entry wants its protected elements to be retained.
240: * @return true if the protected elements are retained; false else
241: * @see #setRetainProtected
242: */
243: public boolean canRetainProtected() {
244: return true == ((getAttrs() & PROTECTED) != 0);
245: }
246:
247: /** Sets whether the entry wants its fields to be retained.
248: * @param canRetain true if the fields are retained; false else
249: * @see #canRetainFields
250: */
251: public void setRetainFields(boolean canRetain) {
252: if (canRetain) {
253: setAttrs(getAttrs() | FIELD);
254: } else {
255: setAttrs(getAttrs() & ~FIELD);
256: }
257: }
258:
259: /** Returns whether the entry wants its fields to be retained.
260: * @return true if the fields are retained; false else
261: * @see #setRetainFields
262: */
263: public boolean canRetainFields() {
264: return true == ((getAttrs() & FIELD) != 0);
265: }
266:
267: /** Sets whether the entry wants its methods to be retained.
268: * @param canRetain true if the methods are retained; false else
269: * @see #canRetainMethods
270: */
271: public void setRetainMethods(boolean canRetain) {
272: if (canRetain) {
273: setAttrs(getAttrs() | METHOD);
274: } else {
275: setAttrs(getAttrs() & ~METHOD);
276: }
277: }
278:
279: /** Returns whether the entry wants its methods to be retained.
280: * @return true if the methods are retained; false else
281: * @see #setRetainMethods
282: */
283: public boolean canRetainMethods() {
284: return true == ((getAttrs() & METHOD) != 0);
285: }
286:
287: /** Sets an additional info string for the entry.
288: * @param info additional info string; may be null
289: * @see #getInfo
290: */
291: public void setInfo(String info) {
292: this .info = info;
293: }
294:
295: /** Returns the additional info string assigned to the entry.
296: * @return additional info string
297: * @see #setInfo
298: */
299: public String getInfo() {
300: return info;
301: }
302: }
|