OPENJPA-401 making temporary classloader optional for MappingTool ant task

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@618745 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2008-02-05 18:58:09 +00:00
parent 24d2a42c22
commit b92f6420af
1 changed files with 28 additions and 7 deletions

View File

@ -49,6 +49,7 @@ import org.apache.openjpa.util.MultiLoaderClassResolver;
* <li><code>file</code></li> * <li><code>file</code></li>
* <li><code>schemaFile</code></li> * <li><code>schemaFile</code></li>
* <li><code>sqlFile</code></li> * <li><code>sqlFile</code></li>
* <li><code>tmpClassLoader</code></li>
* </ul> Of these arguments, only <code>action</code> is required. * </ul> Of these arguments, only <code>action</code> is required.
*/ */
public class MappingToolTask public class MappingToolTask
@ -61,6 +62,7 @@ public class MappingToolTask
protected String file = null; protected String file = null;
protected String schemaFile = null; protected String schemaFile = null;
protected String sqlFile = null; protected String sqlFile = null;
protected boolean tmpClassLoader = true;
/** /**
* Set the enumerated MappingTool action type. * Set the enumerated MappingTool action type.
@ -176,21 +178,27 @@ public class MappingToolTask
if (MappingTool.ACTION_IMPORT.equals(flags.action)) if (MappingTool.ACTION_IMPORT.equals(flags.action))
assertFiles(files); assertFiles(files);
ClassLoader loader = ClassLoader toolLoader = (ClassLoader) AccessController
(ClassLoader) AccessController.doPrivileged(J2DoPrivHelper .doPrivileged(J2DoPrivHelper
.getClassLoaderAction(MappingTool.class));
ClassLoader loader = toolLoader;
MultiLoaderClassResolver resolver = new MultiLoaderClassResolver();
if (tmpClassLoader) {
loader = (ClassLoader) AccessController.doPrivileged(J2DoPrivHelper
.newTemporaryClassLoaderAction(getClassLoader())); .newTemporaryClassLoaderAction(getClassLoader()));
resolver.addClassLoader(loader);
}
resolver.addClassLoader(toolLoader);
if (flags.meta && MappingTool.ACTION_ADD.equals(flags.action)) if (flags.meta && MappingTool.ACTION_ADD.equals(flags.action))
flags.metaDataFile = Files.getFile(file, loader); flags.metaDataFile = Files.getFile(file, loader);
else else
flags.mappingWriter = Files.getWriter(file, loader); flags.mappingWriter = Files.getWriter(file, loader);
flags.schemaWriter = Files.getWriter(schemaFile, loader); flags.schemaWriter = Files.getWriter(schemaFile, loader);
flags.sqlWriter = Files.getWriter(sqlFile, loader); flags.sqlWriter = Files.getWriter(sqlFile, loader);
MultiLoaderClassResolver resolver = new MultiLoaderClassResolver();
resolver.addClassLoader(loader);
resolver.addClassLoader((ClassLoader) AccessController.doPrivileged(
J2DoPrivHelper.getClassLoaderAction(MappingTool.class)));
JDBCConfiguration conf = (JDBCConfiguration) getConfiguration(); JDBCConfiguration conf = (JDBCConfiguration) getConfiguration();
conf.setClassResolver(resolver); conf.setClassResolver(resolver);
@ -218,5 +226,18 @@ public class MappingToolTask
return actions; return actions;
} }
} }
/**
* <P>
* Set whether a temporary ClassLoader should be used by the MappingTool.
* The default value is true
* </P>
*
* @param tmpClassLoader
* Whether the temporary ClassLoader should be used.
*/
public void setTmpClassLoader(boolean tmpClassLoader) {
this.tmpClassLoader = tmpClassLoader;
}
} }