1 /***
2 * ClassInfo.java
3 *
4 * Project: Dependency Tool
5 *
6 * WHEN WHO WHAT
7 * 06.06.2003 pko initial public release
8 * 03.04.2002 ctr modification
9 * 22.01.2002 ctr modification
10 * 11.12.2001 ctr creation
11 *
12 * Copyright 2003 ELCA Informatique SA
13 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland
14 * www.elca.ch
15 *
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public License
18 * as published by the Free Software Foundation; either version 2.1 of
19 * the License, or (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 * USA
30 */
31
32 package ch.elca.dependency.core.classinfo;
33
34 import java.util.ArrayList;
35 import java.util.HashSet;
36
37 import ch.elca.dependency.exception.ClassInfoException;
38
39 /***
40 * This class acts particuarly as struct. It holds the dependencies of the
41 * specified class, the class name and its package name.
42 * This class is, if it is constructed once, always valid. Invalid values are
43 * not allowed in the constructor where that's the only way to initialize this
44 * object.
45 *
46 * @see Reader
47 * @see Analyzer
48 *
49 * @author Christoph Trutmann
50 * @version 1.0-beta
51 */
52 public class ClassInfo implements Cloneable, Comparable {
53
54 /***
55 * Fully qualified name of the class where this informations belong to.
56 */
57 private final String m_fullClassName;
58
59 /***
60 * Super class of this class.
61 */
62 private String m_superClass;
63
64 /***
65 * All the classes (in the full qualified name) needed by this class.
66 */
67 private ArrayList m_neededClasses;
68
69 /***
70 * All the packages (in the full qualified name) needed by this class.
71 */
72 private ArrayList m_neededPackages;
73
74 /***
75 * Set containing all the implemented interfaces.<br>
76 * If no interface is implemented the set is empty but never null!
77 */
78 private HashSet m_interfaces;
79
80 /***
81 * Constructor - Allows only direct initialisation at the beginning.
82 *
83 * @param fullName Full qualified name of the class where this information
84 * belongs to.
85 * @param superClass Super class of this class.
86 * @param dependencies All the classes which are 'used' by the class where
87 * this information belongs to. Also these classes are
88 * stored with the full qualified name.
89 * @param packDepend All the packages which are 'used' by this class.
90 * @param interfaces Implemented interfaces by this class.
91 * @throws IllegalArgumentException If there are wrong arguments passed or
92 * if some arguments are missed.
93 */
94 public ClassInfo(String fullName, String superClass, ArrayList dependencies,
95 ArrayList packDepend, HashSet interfaces)
96 throws IllegalArgumentException {
97
98 // wrong constructor arguments
99 if ( fullName == null || fullName.equals("") ) {
100 throw new IllegalArgumentException(
101 "The name of the class is not specified.");
102 }
103 if ( superClass == null || superClass.equals("") ) {
104 throw new IllegalArgumentException(
105 "The name of the super class is not specified.");
106 }
107 if ( dependencies == null ) {
108 throw new IllegalArgumentException(
109 "There are no dependencies specified.");
110 }
111 if ( packDepend == null ) {
112 throw new IllegalArgumentException(
113 "There are no package dependencies specified.");
114 }
115 if ( interfaces == null ) {
116 throw new IllegalArgumentException(
117 "There is no set with interfaces specified.");
118 }
119
120 // initialize instance variables
121 m_fullClassName = fullName;
122 m_superClass = superClass;
123 m_neededClasses = dependencies;
124 m_neededPackages = packDepend;
125 m_interfaces = interfaces;
126 }
127
128 /***
129 * Gets the name of the class where the informations belong to.
130 *
131 * @return Name of the class.
132 * @throws ClassInfoException If the class informations are invalid.
133 */
134 public String getClassName() throws ClassInfoException {
135
136 // get the index of the last point
137 int indexOfPoint = m_fullClassName.lastIndexOf(".");
138
139 // extract package name
140 if ( indexOfPoint != -1 ) {
141 return m_fullClassName.substring( indexOfPoint,
142 m_fullClassName.length());
143 } else {
144 throw new ClassInfoException("The class \"" + m_fullClassName
145 + "\" has no package statement specified.");
146 }
147 }
148
149
150 /***
151 * Gets the mane of the package where the informations belong to.
152 *
153 * @return Name of the package.
154 * @throws ClassInfoException If the class informations are invalid.
155 */
156 public String getPackage() throws ClassInfoException {
157
158 // get the index of the last point
159 int indexOfPoint = m_fullClassName.lastIndexOf(".");
160
161 // extract package name
162 if ( indexOfPoint != -1 ) {
163 return m_fullClassName.substring(0, indexOfPoint);
164 } else {
165 return "default";
166 // throw new ClassInfoException("The class \"" + m_fullClassName +
167 // "\" has no package statement specified.");
168 }
169 }
170
171
172 /***
173 * Gets the full qualified name of this class.
174 *
175 * @return Full qualified name of this class.
176 */
177 public String getFullName(){
178 return m_fullClassName;
179 }
180
181
182 /***
183 * Gets the super class of this class.
184 *
185 * @return Super class in the full qualified name string.
186 */
187 public String getSuperClass(){
188 return m_superClass;
189 }
190
191
192 /***
193 * Gets the list with the packages needed by the class specified here. These
194 * packages are specified in the full qualified name.
195 *
196 * @return ArrayList with all the packages needed by the spec. class.
197 */
198 public ArrayList getNeededPackages() {
199 return m_neededPackages;
200 }
201
202
203 /***
204 * Gets the list with the classes nedded by this class specified here. These
205 * classes are specified in the full qualified name.
206 *
207 * @return ArrayList with all the classes needed by the spec. class.
208 */
209 public ArrayList getNeededClasses() {
210 return m_neededClasses;
211 }
212
213
214 /***
215 * Gets a <code>HashSet</code> with all the implemented interfaces of the
216 * current class.
217 *
218 * @return HashSet with all the implemented interfaces.
219 */
220 public HashSet getImplInterfaces(){
221 return m_interfaces;
222 }
223
224
225 /***
226 * Creates and returns a copy of this object.
227 *
228 * @return A clone of this instance.
229 * @throws CloneNotSupportedException If the object's class does not support
230 * the Cloneable interface. Subclasses
231 * that override the clone method can
232 * also throw this exception to indicate
233 * that an instance cannot be cloned.
234
235 */
236 public Object clone() throws CloneNotSupportedException {
237 return super.clone();
238 }
239
240
241 /***
242 * Compares the names of two <code>ClassInfo</code> objects.
243 *
244 * @param o The object to be compared.
245 * @return A negative integer, zero, or a positive integer as this object
246 * is less than, equal to, or greater than the specified object.
247 */
248 public int compareTo(Object o){
249 String thisName = this.getFullName();
250 String compareName = ((ClassInfo)o).getFullName();
251
252 // compare th two strings
253 return thisName.compareTo(compareName);
254 }
255 }
This page was automatically generated by Maven