Browse Source

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
master
Peter Donald 23 years ago
parent
commit
65c27bc2ad
1 changed files with 55 additions and 0 deletions
  1. +55
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/type/ReloadingTypeFactory.java

+ 55
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/type/ReloadingTypeFactory.java View File

@@ -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 <a href="mailto:peter@apache.org">Peter Donald</a>
* @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 );
}
}

Loading…
Cancel
Save