001: /**
002: * JavaGuard -- an obfuscation package for Java classfiles.
003: *
004: * Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
005: * Copyright (c) 2002 Thorsten Heit (theit@gmx.de)
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 theit@gmx.de.
022: *
023: *
024: * $Id: Pk.java,v 1.4 2002/04/22 16:43:22 glurk Exp $
025: */package net.sf.javaguard;
026:
027: import java.util.*;
028:
029: /** Tree item representing a package.
030: *
031: * @author <a href="mailto:markw@retrologic.com">Mark Welsh</a>
032: * @author <a href="mailto:theit@gmx.de">Thorsten Heit</a>
033: */
034: public class Pk extends PkCl {
035: /** Holds a list of sub-package levels. */
036: private Map pks = new TreeMap();
037:
038: /** Create the root entry for a tree.
039: * @param classTree the root class tree to use
040: */
041: public static Pk createRoot(ClassTree classTree) {
042: return new Pk(classTree);
043: }
044:
045: /** Constructor for default package level.
046: * @param classTree the class tree to which the package belongs to
047: */
048: public Pk(ClassTree classTree) {
049: this (null, "");
050: setClassTree(classTree);
051: }
052:
053: /** Constructor for regular package levels.
054: */
055: public Pk(TreeItem parent, String name) {
056: super (parent, name);
057: if (null == parent && !name.equals("")) {
058: throw new InternalError(
059: "Internal error: only the default package has no parent");
060: } else if (null != parent && name.equals("")) {
061: throw new InternalError(
062: "Internal error: the default package cannot have a parent");
063: }
064: }
065:
066: /** Get a package level by name.
067: * @param name the package name
068: * @return package level
069: */
070: public Pk getPackage(String name) {
071: return (Pk) pks.get(name);
072: }
073:
074: /** Get an Enumeration of packages.
075: * @return enumeration of packages
076: */
077: public Iterator getPackageIterator() {
078: return pks.values().iterator();
079: }
080:
081: /** Return number of packages.
082: * @return the number of packages
083: */
084: public int getPackageCount() {
085: return pks.size();
086: }
087:
088: /** Add a sub-package level.
089: * @param name the name of a package
090: * @return the package level
091: */
092: public Pk addPackage(String name) {
093: Pk pk = getPackage(name);
094: if (pk == null) {
095: pk = new Pk(this , name);
096: pks.put(name, pk);
097: }
098: return pk;
099: }
100:
101: /** Add a class.
102: * @param name the class name
103: * @param superName the name of the super class
104: * @param interfaceNames a list of interfaces the class implements
105: * @see PkCl#addClass(String, boolean, String, String[])
106: * @return the new created class object
107: */
108: public Cl addClass(String name, String super Name,
109: String[] interfaceNames) {
110: return addClass(name, false, super Name, interfaceNames);
111: }
112:
113: /** Add a placeholder class.
114: * @param name the placeholder class name
115: * @return the new created class object
116: */
117: public Cl addPlaceholderClass(String name) {
118: return addPlaceholderClass(name, false);
119: }
120:
121: /** Generate unique obfuscated names for this namespace.
122: */
123: public void generateNames() {
124: super.generateNames();
125: generateNames(pks);
126: }
127: }
|