KickJava   Java API By Example, From Geeks To Geeks.

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


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: Pk.java,v 1.4 2002/04/22 16:43:22 glurk Exp $
25  */

26 package net.sf.javaguard;
27
28 import java.util.*;
29
30 /** Tree item representing a package.
31  *
32  * @author <a HREF="mailto:markw@retrologic.com">Mark Welsh</a>
33  * @author <a HREF="mailto:theit@gmx.de">Thorsten Heit</a>
34  */

35 public class Pk extends PkCl {
36   /** Holds a list of sub-package levels. */
37   private Map pks = new TreeMap();
38   
39   
40   /** Create the root entry for a tree.
41    * @param classTree the root class tree to use
42    */

43   public static Pk createRoot(ClassTree classTree) {
44     return new Pk(classTree);
45   }
46   
47   
48   
49   
50   /** Constructor for default package level.
51    * @param classTree the class tree to which the package belongs to
52    */

53   public Pk(ClassTree classTree) {
54     this(null, "");
55     setClassTree(classTree);
56   }
57   
58   
59   /** Constructor for regular package levels.
60    */

61   public Pk(TreeItem parent, String JavaDoc name) {
62     super(parent, name);
63     if (null == parent && !name.equals("")) {
64       throw new InternalError JavaDoc("Internal error: only the default package has no parent");
65     }
66     else if (null != parent && name.equals("")) {
67       throw new InternalError JavaDoc("Internal error: the default package cannot have a parent");
68     }
69   }
70   
71   
72   /** Get a package level by name.
73    * @param name the package name
74    * @return package level
75    */

76   public Pk getPackage(String JavaDoc name) {
77     return (Pk) pks.get(name);
78   }
79   
80   
81   /** Get an Enumeration of packages.
82    * @return enumeration of packages
83    */

84   public Iterator getPackageIterator() {
85     return pks.values().iterator();
86   }
87   
88   
89   /** Return number of packages.
90    * @return the number of packages
91    */

92   public int getPackageCount() {
93     return pks.size();
94   }
95   
96   
97   /** Add a sub-package level.
98    * @param name the name of a package
99    * @return the package level
100    */

101   public Pk addPackage(String JavaDoc name) {
102     Pk pk = getPackage(name);
103     if (pk == null) {
104       pk = new Pk(this, name);
105       pks.put(name, pk);
106     }
107     return pk;
108   }
109   
110   
111   /** Add a class.
112    * @param name the class name
113    * @param superName the name of the super class
114    * @param interfaceNames a list of interfaces the class implements
115    * @see PkCl#addClass(String, boolean, String, String[])
116    * @return the new created class object
117    */

118   public Cl addClass(String JavaDoc name, String JavaDoc superName, String JavaDoc[] interfaceNames) {
119     return addClass(name, false, superName, interfaceNames);
120   }
121   
122   
123   /** Add a placeholder class.
124    * @param name the placeholder class name
125    * @return the new created class object
126    */

127   public Cl addPlaceholderClass(String JavaDoc name) {
128     return addPlaceholderClass(name, false);
129   }
130   
131   
132   /** Generate unique obfuscated names for this namespace.
133    */

134   public void generateNames() {
135     super.generateNames();
136     generateNames(pks);
137   }
138 }
139
Popular Tags