KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > go > beandoc > teadoc > PackageDoc


1 /* ====================================================================
2  * BeanDoc - Copyright (c) 1997-2000 GO.com
3  * ====================================================================
4  * The Tea Software License, Version 1.0
5  *
6  * Copyright (c) 2000 GO.com. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by GO.com
23  * (http://opensource.go.com/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Tea", "TeaServlet", "Kettle", "Trove", BeanDoc and "GO.com"
28  * must not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact opensource@go.com.
31  *
32  * 5. Products derived from this software may not be called "Tea",
33  * "TeaServlet", "Kettle", "Trove" or BeanDoc, nor may "Tea", "TeaServlet",
34  * "Kettle", "Trove" or BeanDoc appear in their name, without prior written
35  * permission of GO.com.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL GO.COM OR ITS CONTRIBUTORS BE LIABLE
41  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
44  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
45  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
46  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
47  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  * ====================================================================
49  *
50  * For more information about Tea, please see http://opensource.go.com/.
51  */

52
53 package com.go.beandoc.teadoc;
54
55 import java.util.Arrays JavaDoc;
56 import java.util.ArrayList JavaDoc;
57
58 /******************************************************************************
59  *
60  * @author Brian S O'Neill
61  * @version
62  * <!--$$Revision:--> 3 <!-- $-->, <!--$$JustDate:--> 8/23/00 <!-- $-->
63  */

64 public class PackageDoc extends Doc {
65
66     private com.sun.javadoc.PackageDoc mDoc;
67     private PackageDoc[] mPackages;
68
69     public static PackageDoc[] convert(RootDoc root,
70                                        com.sun.javadoc.PackageDoc[] docs) {
71         int length = docs.length;
72         PackageDoc[] newDocs = new PackageDoc[length];
73         for (int i=0; i<length; i++) {
74             newDocs[i] = new PackageDoc(root, docs[i]);
75         }
76         return newDocs;
77     }
78
79     public PackageDoc(RootDoc root, com.sun.javadoc.PackageDoc doc) {
80         super(root, doc);
81         mDoc = doc;
82     }
83
84     public ClassDoc[] getAllClasses() {
85         return ClassDoc.convert(mRootDoc, mDoc.allClasses());
86     }
87
88     public ClassDoc[] getSortedAllClasses() {
89         ClassDoc[] docs = (ClassDoc[])getAllClasses().clone();
90         Arrays.sort(docs);
91         return docs;
92     }
93
94     public ClassDoc[] getOrdinaryClasses() {
95         return ClassDoc.convert(mRootDoc, mDoc.ordinaryClasses());
96     }
97
98     public ClassDoc[] getSortedOrdinaryClasses() {
99         ClassDoc[] docs = (ClassDoc[])getOrdinaryClasses().clone();
100         Arrays.sort(docs);
101         return docs;
102     }
103
104     public ClassDoc[] getExceptions() {
105         return ClassDoc.convert(mRootDoc, mDoc.exceptions());
106     }
107
108     public ClassDoc[] getSortedExceptions() {
109         ClassDoc[] docs = (ClassDoc[])getExceptions().clone();
110         Arrays.sort(docs);
111         return docs;
112     }
113
114     public ClassDoc[] getErrors() {
115         return ClassDoc.convert(mRootDoc, mDoc.errors());
116     }
117
118     public ClassDoc[] getSortedErrors() {
119         ClassDoc[] docs = (ClassDoc[])getErrors().clone();
120         Arrays.sort(docs);
121         return docs;
122     }
123
124     public ClassDoc[] getInterfaces() {
125         return ClassDoc.convert(mRootDoc, mDoc.interfaces());
126     }
127
128     public ClassDoc[] getSortedInterfaces() {
129         ClassDoc[] docs = (ClassDoc[])getInterfaces().clone();
130         Arrays.sort(docs);
131         return docs;
132     }
133
134     public PackageDoc[] getPackages() {
135         if (mPackages == null) {
136             ArrayList JavaDoc list = new ArrayList JavaDoc();
137             PackageDoc[] allPackages = mRootDoc.getPackages();
138             String JavaDoc thisName = getName();
139
140             for (int i=0; i<allPackages.length; i++) {
141                 PackageDoc doc = allPackages[i];
142                 String JavaDoc name = doc.getName();
143                 if (name.startsWith(thisName) && doc != this) {
144                     name = name.substring(thisName.length());
145                     if (name.lastIndexOf('.') <= 0) {
146                         list.add(doc);
147                     }
148                 }
149             }
150
151             mPackages =
152                 (PackageDoc[])list.toArray(new PackageDoc[list.size()]);
153         }
154
155         return mPackages;
156     }
157
158     public PackageDoc[] getSortedPackages() {
159         PackageDoc[] docs = (PackageDoc[])getPackages().clone();
160         Arrays.sort(docs);
161         return docs;
162     }
163
164     public int hashCode() {
165         if (mDoc != null) {
166             return getName().hashCode();
167         }
168         else {
169             return super.hashCode();
170         }
171     }
172
173     public boolean equals(Object JavaDoc other) {
174         if (this == other) {
175             return true;
176         }
177
178         if (other instanceof PackageDoc) {
179             PackageDoc doc = (PackageDoc)other;
180             return getName().equals(doc.getName());
181         }
182
183         return false;
184     }
185
186     public int compareTo(Object JavaDoc obj) {
187         if (obj instanceof PackageDoc) {
188             return getName().compareTo(((PackageDoc)obj).getName());
189         }
190         else {
191             return 0;
192         }
193     }
194 }
195
Popular Tags