Package org.allspice.util

Examples of org.allspice.util.ImmediateClassLoader


  }
  public static void main(String[] args) throws Exception {
    // Create the java class
    JavaClass jc = GenJavaClass.createJavaClass(makeAddClass()) ;
    // Use a utility loader so we can call our class without saving to disk
    ImmediateClassLoader loader = new ImmediateClassLoader() ;
    loader.defineClass(jc.getClassName(),jc.getBytes()) ;
    // Load the honest to goodness class
    Class<?> cl = loader.loadClass("TestClass") ;
    // Create an instance of the class.
    Object o = cl.newInstance() ;
    // Get the "add" method
    Method m = cl.getMethod("add",int.class,int.class) ;
    // Run it!
View Full Code Here


    }
  }
 
  public static ClassLoader createLoader(StdJavaExpressions converter,Collection<FileUnit> cdecls) throws CompilerException, GenerationError {
    ClassPool cp = createClassPool(cdecls) ;
    ImmediateClassLoader defcl = new ImmediateClassLoader() ;
    for(FileUnit cd: cdecls) {
      for(ClassDef cdef: createClassDef(converter,cp,cd)) {
        final JavaClass jc = GenJavaClass.createJavaClass(cdef) ;
        byte[] bytes = jc.getBytes() ;
        defcl.defineClass(jc.getClassName(), bytes) ;
      }
    }
    return defcl ;
  }
View Full Code Here

    }
    return cd ;
  }
  public Class<?> makeClass(ClassDef cd) throws Exception {
    final JavaClass jc = GenJavaClass.createJavaClass(cd) ;
    ImmediateClassLoader loader = new ImmediateClassLoader() ;
    loader.defineClass(jc.getClassName(),jc.getBytes()) ;
    return loader.loadClass(cd.name.toString())
  }
View Full Code Here

TOP

Related Classes of org.allspice.util.ImmediateClassLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.