private List<URL> classpath = new ArrayList<URL>();\r
private ClassLoader loader = null;\r
\r
+ /**\r
+ * private constructor.\r
+ * The root context is only one.\r
+ */\r
private ClasspathContext(){\r
}\r
\r
+ /**\r
+ * constructor with parent classpath context.\r
+ */\r
public ClasspathContext(ClasspathContext parent){\r
this.parent = parent;\r
}\r
\r
+ /**\r
+ * returns parent classpath context.\r
+ */\r
public ClasspathContext getParent(){\r
return parent;\r
}\r
\r
+ /**\r
+ * returns default classpath context.\r
+ */\r
public static final ClasspathContext getDefaultContext(){\r
return DEFAULT_CONTEXT;\r
}\r
\r
+ /**\r
+ * adds given url to this context. If this context already has given url or\r
+ * parent context has given url, this method do nothing.\r
+ */\r
public synchronized void addClasspath(URL url){\r
- classpath.add(url);\r
- loader = null;\r
+ if(!contains(url)){\r
+ classpath.add(url);\r
+ loader = null;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * returns that this context or parent context have given url.\r
+ */\r
+ public synchronized boolean contains(URL url){\r
+ return (parent != null && parent.contains(url)) || classpath.contains(url); \r
}\r
\r
+ /**\r
+ * returns a size of classpath list, which this context and parent context have.\r
+ */\r
public int getClasspathSize(){\r
int count = classpath.size();\r
if(parent != null){\r
return count;\r
}\r
\r
+ /**\r
+ * returns an array of all of classpathes include parent context.\r
+ */\r
public synchronized URL[] getClasspathList(){\r
List<URL> list = new ArrayList<URL>();\r
- for(Iterator<URL> i = classpath(); i.hasNext(); ){\r
- list.add(i.next());\r
+ for(URL url: this){\r
+ list.add(url);\r
}\r
return list.toArray(new URL[list.size()]);\r
}\r
\r
+ /**\r
+ * clears all of classpathes of this context. not clear parent context.\r
+ * If you want to clear this context and parent context, use {@link #clearAll <code>clearAll</code>} method.\r
+ * @see clearAll\r
+ */\r
public void clear(){\r
classpath.clear();\r
}\r
\r
- public Iterator<URL> iterator(){\r
- return classpath.iterator();\r
+ /**\r
+ * clears all of classpathes of this context and parent context.\r
+ */\r
+ public void clearAll(){\r
+ clear();\r
+ if(parent != null){\r
+ parent.clearAll();\r
+ }\r
}\r
\r
- public Iterator<URL> classpath(){\r
+ public Iterator<URL> iterator(){\r
if(parent == null){\r
- return iterator();\r
+ return classpath.iterator();\r
}\r
else{\r
- final Iterator<URL> parentIterator = parent.classpath();\r
- final Iterator<URL> thisIterator = iterator();\r
+ final Iterator<URL> parentIterator = parent.iterator();\r
+ final Iterator<URL> thisIterator = classpath.iterator();\r
return new Iterator<URL>(){\r
public boolean hasNext(){\r
boolean next = parentIterator.hasNext();\r
public synchronized ClassLoader createClassLoader(){\r
if(loader == null){\r
List<URL> list = new ArrayList<URL>();\r
- for(Iterator<URL> i = classpath(); i.hasNext(); ){\r
- list.add(i.next());\r
+ for(URL url: this){\r
+ list.add(url);\r
}\r
\r
loader = new WarClassLoader(list.toArray(new URL[list.size()]), getClass().getClassLoader());\r
import java.io.IOException;\r
import java.net.MalformedURLException;\r
import java.net.URL;\r
-import java.util.Iterator;\r
\r
import javax.swing.Box;\r
import javax.swing.JButton;\r
bootClasspath.removeAllElements();\r
try{\r
ClasspathContext context = stigmata.getEnvironment().getClasspathContext();\r
- for(Iterator<URL> i = context.classpath(); i.hasNext(); ){\r
- classpath.addValue(i.next().toString());\r
+ for(URL url: context){\r
+ classpath.addValue(url.toString());\r
}\r
\r
addClasspath(bootClasspath, System.getProperty("java.class.path"));\r