Java 类org.mozilla.javascript.GeneratedClassLoader 实例源码

项目:https-github.com-hyb1996-NoRootScriptDroid    文件:Main.java   
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
        throws FileNotFoundException {
    if (data == null) {
        throw new FileNotFoundException(path);
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
    } catch (IllegalAccessException iaex) {
        Context.reportError(iaex.toString());
        throw new RuntimeException(iaex);
    } catch (InstantiationException inex) {
        Context.reportError(inex.toString());
        throw new RuntimeException(inex);
    }
}
项目:Auto.js    文件:Main.java   
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
        throws FileNotFoundException {
    if (data == null) {
        throw new FileNotFoundException(path);
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
    } catch (IllegalAccessException iaex) {
        Context.reportError(iaex.toString());
        throw new RuntimeException(iaex);
    } catch (InstantiationException inex) {
        Context.reportError(inex.toString());
        throw new RuntimeException(inex);
    }
}
项目:Push2Display    文件:BatikSecurityController.java   
/**
 * Default constructor
 */
public GeneratedClassLoader createClassLoader
    (final ClassLoader parentLoader, Object securityDomain) {

    if (securityDomain instanceof RhinoClassLoader) {
        return (RhinoClassLoader)securityDomain;
    }

    // FIXX: This should be supported by intersecting perms.
    // Calling var script = Script(source); script(); is not supported
    throw new SecurityException("Script() objects are not supported");
}
项目:code404    文件:Main.java   
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
        throws FileNotFoundException
{
    if (data == null) {
        throw new FileNotFoundException(path);
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
    } catch (IllegalAccessException iaex) {
        Context.reportError(iaex.toString());
        throw new RuntimeException(iaex);
    } catch (InstantiationException inex) {
        Context.reportError(inex.toString());
        throw new RuntimeException(inex);
    }
}
项目:Push2Display    文件:BatikSecurityController.java   
/**
 * Default constructor
 */
public GeneratedClassLoader createClassLoader
    (final ClassLoader parentLoader, Object securityDomain) {

    if (securityDomain instanceof RhinoClassLoader) {
        return (RhinoClassLoader)securityDomain;
    }

    // FIXX: This should be supported by intersecting perms.
    // Calling var script = Script(source); script(); is not supported
    throw new SecurityException("Script() objects are not supported");
}
项目:feathers-sdk    文件:BatikSecurityController.java   
/**
 * Default constructor
 */
public GeneratedClassLoader createClassLoader
    (final ClassLoader parentLoader, Object securityDomain) {

    if (securityDomain instanceof RhinoClassLoader) {
        return (RhinoClassLoader)securityDomain;
    }

    // FIXX: This should be supported by intersecting perms.
    // Calling var script = Script(source); script(); is not supported
    throw new SecurityException("Script() objects are not supported");
}
项目:S3F    文件:Main.java   
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
        throws FileNotFoundException
{
    if (data == null) {
        throw new FileNotFoundException(path);
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
    } catch (IllegalAccessException iaex) {
        Context.reportError(iaex.toString());
        throw new RuntimeException(iaex);
    } catch (InstantiationException inex) {
        Context.reportError(inex.toString());
        throw new RuntimeException(inex);
    }
}
项目:rhino-jscover    文件:Main.java   
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
        throws FileNotFoundException
{
    if (data == null) {
        throw new FileNotFoundException(path);
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
    } catch (IllegalAccessException iaex) {
        Context.reportError(iaex.toString());
        throw new RuntimeException(iaex);
    } catch (InstantiationException inex) {
        Context.reportError(inex.toString());
        throw new RuntimeException(inex);
    }
}
项目:astor    文件:Main.java   
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
        throws FileNotFoundException
{
    if (data == null) {
        throw new FileNotFoundException(path);
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
    } catch (IllegalAccessException iaex) {
        Context.reportError(iaex.toString());
        throw new RuntimeException(iaex);
    } catch (InstantiationException inex) {
        Context.reportError(inex.toString());
        throw new RuntimeException(inex);
    }
}
项目:Rhino-Prov-Mod    文件:Main.java   
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
        throws FileNotFoundException
{
    if (data == null) {
        throw new FileNotFoundException(path);
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
    } catch (IllegalAccessException iaex) {
        Context.reportError(iaex.toString());
        throw new RuntimeException(iaex);
    } catch (InstantiationException inex) {
        Context.reportError(inex.toString());
        throw new RuntimeException(inex);
    }
}
项目:closure-compiler-old    文件:Main.java   
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
        throws FileNotFoundException
{
    if (data == null) {
        throw new FileNotFoundException(path);
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
    } catch (IllegalAccessException iaex) {
        Context.reportError(iaex.toString());
        throw new RuntimeException(iaex);
    } catch (InstantiationException inex) {
        Context.reportError(inex.toString());
        throw new RuntimeException(inex);
    }
}
项目:closure-compiler-copy    文件:Main.java   
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
        throws FileNotFoundException
{
    if (data == null) {
        throw new FileNotFoundException(path);
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
    } catch (IllegalAccessException iaex) {
        Context.reportError(iaex.toString());
        throw new RuntimeException(iaex);
    } catch (InstantiationException inex) {
        Context.reportError(inex.toString());
        throw new RuntimeException(inex);
    }
}
项目:https-github.com-hyb1996-NoRootScriptDroid    文件:NoSecurityController.java   
@Override
public GeneratedClassLoader createClassLoader(ClassLoader classLoader, Object o) {
    return Context.getCurrentContext().createClassLoader(classLoader);
}
项目:Auto.js    文件:NoSecurityController.java   
@Override
public GeneratedClassLoader createClassLoader(ClassLoader classLoader, Object o) {
    return Context.getCurrentContext().createClassLoader(classLoader);
}
项目:whackpad    文件:Main.java   
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
{
    if (data == null) {
        exitCode = EXITCODE_FILE_NOT_FOUND;
        return null;
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
     } catch (RhinoException rex) {
        ToolErrorReporter.reportException(
            cx.getErrorReporter(), rex);
        exitCode = EXITCODE_RUNTIME_ERROR;
    } catch (IllegalAccessException iaex) {
        exitCode = EXITCODE_RUNTIME_ERROR;
        Context.reportError(iaex.toString());
    } catch (InstantiationException inex) {
        exitCode = EXITCODE_RUNTIME_ERROR;
        Context.reportError(inex.toString());
    }
    return null;
}
项目:rhino-android    文件:NoSecurityController.java   
@Override
public GeneratedClassLoader createClassLoader(ClassLoader classLoader, Object o) {
    return Context.getCurrentContext().createClassLoader(classLoader);
}
项目:rhino-android    文件:JavaAcessibilityTest.java   
@Override
protected GeneratedClassLoader createClassLoader(ClassLoader parent) {
  return (GeneratedClassLoader) new AndroidContextFactory(new File(System.getProperty("java.io.tmpdir", "."), "classes")).getApplicationClassLoader();
}
项目:LoboEvolution    文件:SecurityControllerImpl.java   
@Override
public GeneratedClassLoader createClassLoader(ClassLoader parent, Object staticDomain) {
    return new LocalSecureClassLoader(parent, codesource);
}