From 65c27bc2ad15618f70ec02d8fc93f53ff55a510e Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Thu, 7 Feb 2002 10:36:21 +0000 Subject: [PATCH] Add in a TypeFactory that will reload a specified set of URLs everytime create() is called which allows statics to be used in tasks if they absolutely have to be git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271201 13f79535-47bb-0310-9956-ffa450edef68 --- .../interfaces/type/ReloadingTypeFactory.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/type/ReloadingTypeFactory.java diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/type/ReloadingTypeFactory.java b/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/type/ReloadingTypeFactory.java new file mode 100644 index 000000000..bb0541e2a --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/type/ReloadingTypeFactory.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.myrmidon.interfaces.type; + +import java.net.URL; +import java.net.URLClassLoader; + +/** + * This is a TypeFactory that will recreate the ClassLoader each time the + * create() method is called. This is to provide support for types that + * use static variables to cache information. While this is a extremely bad + * practice, sometimes this is unavoidable - especially when using third party + * libraries. + * + * @author Peter Donald + * @version CVS $Revision$ $Date$ + */ +public class ReloadingTypeFactory + extends DefaultTypeFactory +{ + /** + * The URLs that are used to construct the ClassLoader. + */ + private URL[] m_urls; + + ///The parent classLoader (if any) + private ClassLoader m_parent; + + /** + * Construct a factory that recreats a ClassLoader from specified + * URLs and with specified parent ClassLoader. The specified urls must + * not be null. + */ + public ReloadingTypeFactory( final URL[] urls, + final ClassLoader parent ) + { + if( null == urls ) + { + throw new NullPointerException( "urls" ); + } + m_urls = urls; + m_parent = parent; + } + + protected ClassLoader getClassLoader() + { + System.out.println( "ReloadingTypeFactory.getClassLoader" ); + return new URLClassLoader( m_urls, m_parent ); + } +}