feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
62
jdkSrc/jdk8/com/sun/codemodel/internal/fmt/JBinaryFile.java
Normal file
62
jdkSrc/jdk8/com/sun/codemodel/internal/fmt/JBinaryFile.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.fmt;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.sun.codemodel.internal.JResourceFile;
|
||||
|
||||
/**
|
||||
* Allows the application to use OutputStream to define data
|
||||
* that will be stored into a file.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class JBinaryFile extends JResourceFile {
|
||||
|
||||
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
public JBinaryFile( String name ) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* Data written to the returned output stream will be written
|
||||
* to the file.
|
||||
*/
|
||||
public OutputStream getDataStore() {
|
||||
return baos;
|
||||
}
|
||||
|
||||
public void build(OutputStream os) throws IOException {
|
||||
os.write( baos.toByteArray() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.fmt;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.sun.codemodel.internal.JResourceFile;
|
||||
|
||||
/**
|
||||
* A property file.
|
||||
*/
|
||||
public class JPropertyFile extends JResourceFile
|
||||
{
|
||||
public JPropertyFile( String name ) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
private final Properties data = new Properties();
|
||||
|
||||
/**
|
||||
* Adds key/value pair into the property file.
|
||||
* If you call this method twice with the same key,
|
||||
* the old one is overriden by the new one.
|
||||
*/
|
||||
public void add( String key, String value ) {
|
||||
data.put(key,value);
|
||||
}
|
||||
|
||||
// TODO: method to iterate values in data?
|
||||
// TODO: should we rather expose Properties object directly via
|
||||
// public Properties body() { return data; } ?
|
||||
|
||||
public void build( OutputStream out ) throws IOException {
|
||||
data.store(out,null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.fmt;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.sun.codemodel.internal.JResourceFile;
|
||||
|
||||
|
||||
/**
|
||||
* A simple class that takes an object and serializes it into a file
|
||||
* in the parent package with the given name.
|
||||
*/
|
||||
public class JSerializedObject extends JResourceFile {
|
||||
|
||||
private final Object obj;
|
||||
|
||||
/**
|
||||
* @exception IOException
|
||||
* If the serialization fails, this exception is thrown
|
||||
*/
|
||||
public JSerializedObject( String name, Object obj ) throws IOException {
|
||||
super(name);
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* called by JPackage to serialize the object
|
||||
*/
|
||||
protected void build( OutputStream os ) throws IOException {
|
||||
// serialize the obj into a ByteArrayOutputStream
|
||||
ObjectOutputStream oos = new ObjectOutputStream(os);
|
||||
oos.writeObject(obj);
|
||||
oos.close();
|
||||
}
|
||||
}
|
||||
80
jdkSrc/jdk8/com/sun/codemodel/internal/fmt/JStaticFile.java
Normal file
80
jdkSrc/jdk8/com/sun/codemodel/internal/fmt/JStaticFile.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.fmt;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.sun.codemodel.internal.JResourceFile;
|
||||
|
||||
/**
|
||||
* Allows an application to copy a resource file to the output.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class JStaticFile extends JResourceFile {
|
||||
|
||||
private final ClassLoader classLoader;
|
||||
private final String resourceName;
|
||||
private final boolean isResource;
|
||||
|
||||
public JStaticFile(String _resourceName) {
|
||||
this(_resourceName,!_resourceName.endsWith(".java"));
|
||||
}
|
||||
|
||||
public JStaticFile(String _resourceName,boolean isResource) {
|
||||
this( SecureLoader.getClassClassLoader(JStaticFile.class), _resourceName, isResource );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isResource
|
||||
* false if this is a Java source file. True if this is other resource files.
|
||||
*/
|
||||
public JStaticFile(ClassLoader _classLoader, String _resourceName, boolean isResource) {
|
||||
super(_resourceName.substring(_resourceName.lastIndexOf('/')+1));
|
||||
this.classLoader = _classLoader;
|
||||
this.resourceName = _resourceName;
|
||||
this.isResource = isResource;
|
||||
}
|
||||
|
||||
protected boolean isResource() {
|
||||
return isResource;
|
||||
}
|
||||
|
||||
protected void build(OutputStream os) throws IOException {
|
||||
DataInputStream dis = new DataInputStream(classLoader.getResourceAsStream(resourceName));
|
||||
|
||||
byte[] buf = new byte[256];
|
||||
int sz;
|
||||
while( (sz=dis.read(buf))>0 )
|
||||
os.write(buf,0,sz);
|
||||
|
||||
dis.close();
|
||||
}
|
||||
|
||||
}
|
||||
239
jdkSrc/jdk8/com/sun/codemodel/internal/fmt/JStaticJavaFile.java
Normal file
239
jdkSrc/jdk8/com/sun/codemodel/internal/fmt/JStaticJavaFile.java
Normal file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.fmt;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.codemodel.internal.JResourceFile;
|
||||
import com.sun.codemodel.internal.JTypeVar;
|
||||
|
||||
/**
|
||||
* Statically generated Java soruce file.
|
||||
*
|
||||
* <p>
|
||||
* This {@link JResourceFile} implementation will generate a Java source
|
||||
* file by copying the source code from a resource.
|
||||
* <p>
|
||||
* While copying a resource, we look for a package declaration and
|
||||
* replace it with the target package name. This allows the static Java
|
||||
* source code to have an arbitrary package declaration.
|
||||
* <p>
|
||||
* You can also use the getJClass method to obtain a {@link JClass}
|
||||
* object that represents the static file. This allows the client code
|
||||
* to refer to the class from other CodeModel generated code.
|
||||
* <p>
|
||||
* Note that because we don't parse the static Java source code,
|
||||
* the returned {@link JClass} object doesn't respond to methods like
|
||||
* "isInterface" or "_extends",
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class JStaticJavaFile extends JResourceFile {
|
||||
|
||||
private final JPackage pkg;
|
||||
private final String className;
|
||||
private final URL source;
|
||||
private final JStaticClass clazz;
|
||||
private final LineFilter filter;
|
||||
|
||||
public JStaticJavaFile(JPackage _pkg, String className, String _resourceName) {
|
||||
this( _pkg, className,
|
||||
SecureLoader.getClassClassLoader(JStaticJavaFile.class).getResource(_resourceName), null );
|
||||
}
|
||||
|
||||
public JStaticJavaFile(JPackage _pkg, String _className, URL _source, LineFilter _filter ) {
|
||||
super(_className+".java");
|
||||
if(_source==null) throw new NullPointerException();
|
||||
this.pkg = _pkg;
|
||||
this.clazz = new JStaticClass();
|
||||
this.className = _className;
|
||||
this.source = _source;
|
||||
this.filter = _filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a class object that represents a statically generated code.
|
||||
*/
|
||||
public final JClass getJClass() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
protected boolean isResource() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void build(OutputStream os) throws IOException {
|
||||
InputStream is = source.openStream();
|
||||
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(is));
|
||||
PrintWriter w = new PrintWriter(new BufferedWriter(new OutputStreamWriter(os)));
|
||||
LineFilter filter = createLineFilter();
|
||||
int lineNumber=1;
|
||||
|
||||
try {
|
||||
String line;
|
||||
while((line=r.readLine())!=null) {
|
||||
line = filter.process(line);
|
||||
if(line!=null)
|
||||
w.println(line);
|
||||
lineNumber++;
|
||||
}
|
||||
} catch( ParseException e ) {
|
||||
throw new IOException("unable to process "+source+" line:"+lineNumber+"\n"+e.getMessage());
|
||||
}
|
||||
|
||||
w.close();
|
||||
r.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link LineFilter}.
|
||||
* <p>
|
||||
* A derived class can override this method to process
|
||||
* the contents of the source file.
|
||||
*/
|
||||
private LineFilter createLineFilter() {
|
||||
// this filter replaces the package declaration.
|
||||
LineFilter f = new LineFilter() {
|
||||
public String process(String line) {
|
||||
if(!line.startsWith("package ")) return line;
|
||||
|
||||
// replace package decl
|
||||
if( pkg.isUnnamed() )
|
||||
return null;
|
||||
else
|
||||
return "package "+pkg.name()+";";
|
||||
}
|
||||
};
|
||||
if( filter!=null )
|
||||
return new ChainFilter(filter,f);
|
||||
else
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter that alters the Java source code.
|
||||
* <p>
|
||||
* By implementing this interface, derived classes
|
||||
* can modify the Java source file before it's written out.
|
||||
*/
|
||||
public interface LineFilter {
|
||||
/**
|
||||
* @param line
|
||||
* a non-null valid String that corresponds to one line.
|
||||
* No '\n' included.
|
||||
* @return
|
||||
* null to strip the line off. Otherwise the returned
|
||||
* String will be written out. Do not add '\n' at the end
|
||||
* of this string.
|
||||
*
|
||||
* @exception ParseException
|
||||
* when for some reason there's an error in the line.
|
||||
*/
|
||||
String process(String line) throws ParseException;
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link LineFilter} that combines two {@link LineFilter}s.
|
||||
*/
|
||||
public final static class ChainFilter implements LineFilter {
|
||||
private final LineFilter first,second;
|
||||
public ChainFilter( LineFilter first, LineFilter second ) {
|
||||
this.first=first;
|
||||
this.second=second;
|
||||
}
|
||||
public String process(String line) throws ParseException {
|
||||
line = first.process(line);
|
||||
if(line==null) return null;
|
||||
return second.process(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class JStaticClass extends JClass {
|
||||
|
||||
private final JTypeVar[] typeParams;
|
||||
|
||||
JStaticClass() {
|
||||
super(pkg.owner());
|
||||
// TODO: allow those to be specified
|
||||
typeParams = new JTypeVar[0];
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public String fullName() {
|
||||
if(pkg.isUnnamed())
|
||||
return className;
|
||||
else
|
||||
return pkg.name()+'.'+className;
|
||||
}
|
||||
|
||||
public JPackage _package() {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
public JClass _extends() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Iterator<JClass> _implements() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean isInterface() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean isAbstract() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public JTypeVar[] typeParams() {
|
||||
return typeParams;
|
||||
}
|
||||
|
||||
protected JClass substituteParams(JTypeVar[] variables, List<JClass> bindings) {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
59
jdkSrc/jdk8/com/sun/codemodel/internal/fmt/JTextFile.java
Normal file
59
jdkSrc/jdk8/com/sun/codemodel/internal/fmt/JTextFile.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.fmt;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import com.sun.codemodel.internal.JResourceFile;
|
||||
|
||||
|
||||
/**
|
||||
* Simple text file.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class JTextFile extends JResourceFile
|
||||
{
|
||||
public JTextFile( String name ) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
private String contents = null;
|
||||
|
||||
public void setContents( String _contents ) {
|
||||
this.contents = _contents;
|
||||
}
|
||||
|
||||
public void build( OutputStream out ) throws IOException {
|
||||
Writer w = new OutputStreamWriter(out);
|
||||
w.write(contents);
|
||||
w.close();
|
||||
}
|
||||
}
|
||||
91
jdkSrc/jdk8/com/sun/codemodel/internal/fmt/SecureLoader.java
Normal file
91
jdkSrc/jdk8/com/sun/codemodel/internal/fmt/SecureLoader.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.codemodel.internal.fmt;
|
||||
|
||||
import com.sun.codemodel.internal.*;
|
||||
|
||||
/**
|
||||
* Class defined for safe calls of getClassLoader methods of any kind (context/system/class
|
||||
* classloader. This MUST be package private and defined in every package which
|
||||
* uses such invocations.
|
||||
* @author snajper
|
||||
*/
|
||||
class SecureLoader {
|
||||
|
||||
static ClassLoader getContextClassLoader() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return Thread.currentThread().getContextClassLoader();
|
||||
} else {
|
||||
return (ClassLoader) java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction() {
|
||||
public java.lang.Object run() {
|
||||
return Thread.currentThread().getContextClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static ClassLoader getClassClassLoader(final Class c) {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return c.getClassLoader();
|
||||
} else {
|
||||
return (ClassLoader) java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction() {
|
||||
public java.lang.Object run() {
|
||||
return c.getClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static ClassLoader getSystemClassLoader() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return ClassLoader.getSystemClassLoader();
|
||||
} else {
|
||||
return (ClassLoader) java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction() {
|
||||
public java.lang.Object run() {
|
||||
return ClassLoader.getSystemClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void setContextClassLoader(final ClassLoader cl) {
|
||||
if (System.getSecurityManager() == null) {
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
} else {
|
||||
java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction() {
|
||||
public java.lang.Object run() {
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user