Search in sources :

Example 1 with LoaderException

use of org.motechproject.mds.exception.loader.LoaderException in project motech by motech.

the class JavassistLoader method doWhenClassNotFound.

@Override
public void doWhenClassNotFound(String name) {
    CtClass ctClass = MotechClassPool.getDefault().getOrNull(name);
    if (null != ctClass) {
        try {
            ctClass.defrost();
            byte[] bytecode = ctClass.toBytecode();
            loadClass(new ClassData(name, bytecode));
        } catch (IOException | CannotCompileException ex) {
            throw new LoaderException("Unable to load class using Javassist: " + name, ex);
        }
    }
}
Also used : CtClass(javassist.CtClass) ClassData(org.motechproject.mds.domain.ClassData) LoaderException(org.motechproject.mds.exception.loader.LoaderException) IOException(java.io.IOException) CannotCompileException(javassist.CannotCompileException)

Example 2 with LoaderException

use of org.motechproject.mds.exception.loader.LoaderException in project motech by motech.

the class PristineBundleClassLoader method loadPristineClassBytecode.

private byte[] loadPristineClassBytecode(String name) {
    String classpath = JavassistUtil.toClassPath(name);
    URL classResource = bundle.getResource(classpath);
    if (classResource != null) {
        try (InputStream in = classResource.openStream()) {
            return IOUtils.toByteArray(in);
        } catch (IOException e) {
            throw new LoaderException("Unable to load bytes in pristine class", e);
        }
    }
    return null;
}
Also used : LoaderException(org.motechproject.mds.exception.loader.LoaderException) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

IOException (java.io.IOException)2 LoaderException (org.motechproject.mds.exception.loader.LoaderException)2 InputStream (java.io.InputStream)1 URL (java.net.URL)1 CannotCompileException (javassist.CannotCompileException)1 CtClass (javassist.CtClass)1 ClassData (org.motechproject.mds.domain.ClassData)1