All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.python.core.BytecodeLoader2 Maven / Gradle / Ivy

Go to download

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

There is a newer version: 2.7.4
Show newest version
// Copyright (c) Corporation for National Research Initiatives

package org.python.core;

import java.security.SecureClassLoader;
import java.util.Vector;

/**
 * A java2 classloader for loading compiled python modules.
 */
class BytecodeLoader2 extends SecureClassLoader implements Loader {
    private Vector parents;

    public BytecodeLoader2() {
        this.parents = BytecodeLoader.init();
    }

    public void addParent(ClassLoader referent) {
        if (!this.parents.contains(referent)) {
            this.parents.add(0, referent);
        }
    }

    // override from abstract base class
    protected Class loadClass(String name, boolean resolve)
            throws ClassNotFoundException {
        Class c = findLoadedClass(name);
        if (c != null) {
            return c;
        }
        return BytecodeLoader.findParentClass(this.parents, name);
    }

    public Class loadClassFromBytes(String name, byte[] data) {
        Class c = defineClass(name, data, 0, data.length, this.getClass()
                .getProtectionDomain());
        resolveClass(c);
        BytecodeLoader.compileClass(c);
        return c;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy