import java.util.Iterator;
/**
- * abstract presentation of class file archive's location.
+ * This interface is for the class manages the location of an archive,
+ * and the set of a class file included in the archive.
*
* @author Haruaki TAMADA
* @version $Revision$
*/
public interface ClassFileArchive extends Iterable<ClassFileEntry>{
+ /**
+ * returns the location of this archive.
+ */
public URL getLocation();
+ /**
+ * returns the InputStream object from given entry.
+ */
public InputStream getInputStream(ClassFileEntry entry) throws IOException;
+ /**
+ * returns an entries of this archive.
+ */
public Iterator<ClassFileEntry> iterator();
+ /**
+ * returns this archive has given class entry or not.
+ */
public boolean hasEntry(String className);
+ /**
+ * returns an entry of given class name.
+ */
public ClassFileEntry getEntry(String className) throws ClassNotFoundException;
+ /**
+ * returns the name of this archive.
+ */
public String getName();
}
import jp.sourceforge.stigmata.digger.util.WarClassLoader;
/**
+ * Context object of Classpath.
+ *
* @author Haruaki TAMADA
* @version $Revision$
*/
/**
* returns a size of classpath list, which this context and parent context have.
*/
- public int getClasspathSize(){
+ public synchronized int getClasspathSize(){
int count = classpath.size();
if(parent != null){
count += parent.getClasspathSize();
* If you want to clear this context and parent context, use {@link #clearAll <code>clearAll</code>} method.
* @see clearAll
*/
- public void clear(){
+ public synchronized void clear(){
classpath.clear();
}
/**
* clears all of classpathes of this context and parent context.
*/
- public void clearAll(){
+ public synchronized void clearAll(){
clear();
if(parent != null){
parent.clearAll();
}
}
- public Iterator<URL> iterator(){
+ /**
+ * returns an iterator of classpath list.
+ */
+ public synchronized Iterator<URL> iterator(){
if(parent == null){
return classpath.iterator();
}
}
}
+
+ /**
+ * construct and returns a ClassLoader object which loads from classpath list.
+ */
public synchronized ClassLoader createClassLoader(){
if(loader == null){
List<URL> list = new ArrayList<URL>();
list.add(url);
}
- loader = new WarClassLoader(list.toArray(new URL[list.size()]), getClass().getClassLoader());
+ ClassLoader parentClassLoader = null;
+ if(parent != null){
+ parentClassLoader = parent.createClassLoader();
+ }
+ loader = new WarClassLoader(list.toArray(new URL[list.size()]), parentClassLoader);
}
return loader;
}
- public ClassFileEntry find(String className) throws ClassNotFoundException{
+ /**
+ * returns a {@link ClassFileEntry <code>ClassFileEntry</code>} object
+ * which is named given className.
+ *
+ * @return ClassFileEntry object, if not found given class, then returns null.
+ */
+ public synchronized ClassFileEntry findEntry(String className){
ClassLoader loader = createClassLoader();
URL resource = loader.getResource(className.replace('.', '/') + ".class");
return null;
}
- public Class<?> findClass(String className) throws ClassNotFoundException{
+ /**
+ * returns this context has given class entry or not.
+ */
+ public synchronized boolean hasEntry(String className){
+ ClassLoader loader = createClassLoader();
+ return loader.getResource(className.replace('.', '/') + ".class") != null;
+ }
+
+ /**
+ * finds and returns a {@link Class <code>Class</code>} object
+ * which is named given className.
+ */
+ public synchronized Class<?> findClass(String className) throws ClassNotFoundException{
try{
ClassLoader loader = createClassLoader();