001: /**
002: * YGuard -- an obfuscation library for Java(TM) classfiles.
003: *
004: * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
005: * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com)
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * The author may be contacted at yguard@yworks.com
022: *
023: * Java and all Java-based marks are trademarks or registered
024: * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
025: */package com.yworks.yguard.obf;
026:
027: import java.io.*;
028: import java.lang.reflect.*;
029: import java.util.*;
030: import com.yworks.yguard.obf.classfile.*;
031:
032: /**
033: * Tree item representing a package.
034: *
035: * @author Mark Welsh
036: */
037: public class Pk extends PkCl {
038: // Constants -------------------------------------------------------------
039:
040: // Fields ----------------------------------------------------------------
041: private Hashtable pks = new Hashtable(); // Owns a list of sub-package levels
042:
043: // Class Methods ---------------------------------------------------------
044: /** Create the root entry for a tree. */
045: public static Pk createRoot(ClassTree classTree) {
046: return new Pk(classTree);
047: }
048:
049: // Instance Methods ------------------------------------------------------
050: /** Constructor for default package level. */
051: public Pk(ClassTree classTree) {
052: this (null, "");
053: this .classTree = classTree;
054: }
055:
056: /** Constructor for regular package levels. */
057: public Pk(TreeItem parent, String name) {
058: super (parent, name);
059: if (parent == null && !name.equals("")) {
060: throw new IllegalArgumentException(
061: "Internal error: only the default package has no parent");
062: } else if (parent != null && name.equals("")) {
063: throw new IllegalArgumentException(
064: "Internal error: the default package cannot have a parent");
065: }
066: }
067:
068: /** Get a package level by name. */
069: public Pk getPackage(String name) {
070: return (Pk) pks.get(name);
071: }
072:
073: /** Get an Enumeration of packages. */
074: public Enumeration getPackageEnum() {
075: return pks.elements();
076: }
077:
078: /** Return number of packages. */
079: public int getPackageCount() {
080: return pks.size();
081: }
082:
083: /** Add a sub-package level. */
084: public Pk addPackage(String name) {
085: Pk pk = getPackage(name);
086: if (pk == null) {
087: pk = new Pk(this , name);
088: pks.put(name, pk);
089: }
090: return pk;
091: }
092:
093: /** Add a class. */
094: public Cl addClass(String name, String super Name,
095: String[] interfaceNames, int modifiers) {
096: return addClass(false, name, super Name, interfaceNames,
097: modifiers);
098: }
099:
100: /** Add a placeholder class. */
101: public Cl addPlaceholderClass(String name) {
102: return addPlaceholderClass(false, name);
103: }
104:
105: /** Generate unique obfuscated names for this namespace. */
106: public void generateNames() {
107: super.generateNames();
108: generateNames(pks);
109: }
110: }
|