Package railo.commons.lang

Examples of railo.commons.lang.PhysicalClassLoader


      String classNameOriginal=component.getPageSource().getFullClassName();
      String className=getClassname(component).concat("_wrap");
      String real=className.replace('.','/');
      String realOriginal=classNameOriginal.replace('.','/');
      Mapping mapping = component.getPageSource().getMapping();
    PhysicalClassLoader cl=null;
    try {
      cl = (PhysicalClassLoader) ((PageContextImpl)pc).getRPCClassLoader(false);
    } catch (IOException e) {
      throw Caster.toPageException(e);
    }
    Resource classFile = cl.getDirectory().getRealResource(real.concat(".class"));
    Resource classFileOriginal = mapping.getClassRootDirectory().getRealResource(realOriginal.concat(".class"));
   
  // LOAD CLASS
      //print.out(className);
    // check last Mod
    if(classFile.lastModified()>=classFileOriginal.lastModified()) {
      try {
        Class clazz=cl.loadClass(className);
        if(clazz!=null && !hasChangesOfChildren(classFile.lastModified(),clazz))return registerTypeMapping(clazz);
      }
      catch(Throwable t){}
    }
    if(!create) return null;
    isNew.setValue(true);
      //print.out("new");
    // CREATE CLASS 
    ClassWriter cw = ASMUtil.getClassWriter();
        //ClassWriter cw = new ClassWriter(true);
      cw.visit(Opcodes.V1_2, Opcodes.ACC_PUBLIC, real, null, "java/lang/Object", null);

      //GeneratorAdapter ga = new GeneratorAdapter(Opcodes.ACC_PUBLIC,Page.STATIC_CONSTRUCTOR,null,null,cw);
    BytecodeContext statConstr = null;//new BytecodeContext(null,null,null,cw,real,ga,Page.STATIC_CONSTRUCTOR);

      ///ga = new GeneratorAdapter(Opcodes.ACC_PUBLIC,Page.CONSTRUCTOR,null,null,cw);
    BytecodeContext constr = null;//new BytecodeContext(null,null,null,cw,real,ga,Page.CONSTRUCTOR);
   
     
     // field component
      //FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, "c", "Lrailo/runtime/ComponentImpl;", null, null);
      //fv.visitEnd();
     
      java.util.List<LitString> _keys=new ArrayList<LitString>();
   
        // remote methods
        Collection.Key[] keys = component.keys(Component.ACCESS_REMOTE);
        int max;
        for(int i=0;i<keys.length;i++){
          max=-1;
          while((max=createMethod(statConstr,constr,_keys,cw,real,component.get(keys[i]),max, writeLog,supressWSbeforeArg))!=-1){
            break;// for overload remove this
          }
        }
       
        // Constructor
        GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC,CONSTRUCTOR_OBJECT,null,null,cw);
    adapter.loadThis();
        adapter.invokeConstructor(Types.OBJECT, CONSTRUCTOR_OBJECT);
        railo.transformer.bytecode.Page.registerFields(new BytecodeContext(null,statConstr,constr,getPage(statConstr,constr),_keys,cw,real,adapter,CONSTRUCTOR_OBJECT,writeLog,supressWSbeforeArg), _keys);
        adapter.returnValue();
        adapter.endMethod();
       
       
        cw.visitEnd();
        byte[] barr = cw.toByteArray();
     
        try {
          ResourceUtil.touch(classFile);
          IOUtil.copy(new ByteArrayInputStream(barr), classFile,true);
         
          cl = (PhysicalClassLoader) ((PageContextImpl)pc).getRPCClassLoader(true);
         
          return registerTypeMapping(cl.loadClass(className, barr));
        }
        catch(Throwable t) {
          throw Caster.toPageException(t);
        }
    }
View Full Code Here


   
    private static Object _getClientComponentPropertiesObject(PageContext pc, Config secondChanceConfig, String className, ASMProperty[] properties) throws PageException, IOException, ClassNotFoundException {
      String real=className.replace('.','/');
     
    PhysicalClassLoader cl;
      if(pc==null)cl = (PhysicalClassLoader)secondChanceConfig.getRPCClassLoader(false);
      else cl = (PhysicalClassLoader)((PageContextImpl)pc).getRPCClassLoader(false);
   
    Resource rootDir = cl.getDirectory();
    Resource classFile = rootDir.getRealResource(real.concat(".class"));
   
    if(classFile.exists()) {
      try {
        Class clazz = cl.loadClass(className);
        Field field = clazz.getField("_md5_");
        if(ASMUtil.createMD5(properties).equals(field.get(null))){
        //if(equalInterface(properties,clazz)) {
          return ClassUtil.loadInstance(clazz);
        }
      }
      catch(Exception e) {
       
      }
    }
    // create file
    byte[] barr = ASMUtil.createPojo(real, properties,Object.class,new Class[]{Pojo.class},null);
      boolean exist=classFile.exists();
    ResourceUtil.touch(classFile);
      IOUtil.copy(new ByteArrayInputStream(barr), classFile,true);
     
      if(pc==null)cl = (PhysicalClassLoader)secondChanceConfig.getRPCClassLoader(exist);
      else cl = (PhysicalClassLoader)((PageContextImpl)pc).getRPCClassLoader(exist);
     
    return ClassUtil.loadInstance(cl.loadClass(className));

  }
View Full Code Here

    private static Class _getServerComponentPropertiesClass(PageContext pc,Component component) throws PageException, IOException, ClassNotFoundException {
      String className=getClassname(component);//StringUtil.replaceLast(classNameOriginal,"$cfc","");
      String real=className.replace('.','/');

      Mapping mapping = component.getPageSource().getMapping();
    PhysicalClassLoader cl = (PhysicalClassLoader)((PageContextImpl)pc).getRPCClassLoader(false);
   
    Resource classFile = cl.getDirectory().getRealResource(real.concat(".class"));
   
      String classNameOriginal=component.getPageSource().getFullClassName();
      String realOriginal=classNameOriginal.replace('.','/');
    Resource classFileOriginal = mapping.getClassRootDirectory().getRealResource(realOriginal.concat(".class"));

    // load existing class
    if(classFile.lastModified()>=classFileOriginal.lastModified()) {
      try {
        Class clazz=cl.loadClass(className);
        if(clazz!=null && !hasChangesOfChildren(classFile.lastModified(), clazz))return clazz;//ClassUtil.loadInstance(clazz);
      }
      catch(Throwable t){}
    }

    // create file
    byte[] barr = ASMUtil.createPojo(real, ASMUtil.toASMProperties(
        ComponentUtil.getProperties(component, false, true, false, false)),Object.class,new Class[]{Pojo.class},component.getPageSource().getDisplayPath());
      ResourceUtil.touch(classFile);
      IOUtil.copy(new ByteArrayInputStream(barr), classFile,true);
      cl = (PhysicalClassLoader)((PageContextImpl)pc).getRPCClassLoader(true);
    return cl.loadClass(className); //ClassUtil.loadInstance(cl.loadClass(className));
    }
View Full Code Here

   
    String className=createClassName(extendz,interfaces);
      //Mapping mapping = cfc.getPageSource().getMapping();
   
      // get ClassLoader
      PhysicalClassLoader cl=null;
    try {
      cl = (PhysicalClassLoader) pci.getRPCClassLoader(false);// mapping.getConfig().getRPCClassLoader(false)
    } catch (IOException e) {
      throw Caster.toPageException(e);
    }
    Resource classFile = cl.getDirectory().getRealResource(className.concat(".class"));
   
    // check if already exists, if yes return
    if(classFile.exists()) {
      //Object obj=newInstance(cl,className,cfc);
      // if(obj!=null) return obj;
    }
   
    /*
    String classNameOriginal=component.getPageSource().getFullClassName();
      String realOriginal=classNameOriginal.replace('.','/');
    Resource classFileOriginal = mapping.getClassRootDirectory().getRealResource(realOriginal.concat(".class"));
    */ 
    ClassWriter cw = ASMUtil.getClassWriter();
     
    cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, className, null, typeExtends.getInternalName(), strInterfaces);
    //BytecodeContext statConstr = null;//new BytecodeContext(null,null,null,cw,real,ga,Page.STATIC_CONSTRUCTOR);
    //BytecodeContext constr = null;//new BytecodeContext(null,null,null,cw,real,ga,Page.CONSTRUCTOR);
   
   
    // field Component
    FieldVisitor _fv = cw.visitField(Opcodes.ACC_PRIVATE, "cfc", COMPONENT_NAME, null, null);
    _fv.visitEnd();
    _fv = cw.visitField(Opcodes.ACC_PRIVATE, "config", CONFIG_WEB_NAME, null, null);
    _fv.visitEnd();
   
     // Constructor
        GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC,CONSTRUCTOR,null,null,cw);
        Label begin = new Label();
        adapter.visitLabel(begin);
    adapter.loadThis();
        adapter.invokeConstructor(Types.OBJECT, SUPER_CONSTRUCTOR);
       
        //adapter.putField(JAVA_PROXY, arg1, arg2)

        adapter.visitVarInsn(Opcodes.ALOAD, 0);
        adapter.visitVarInsn(Opcodes.ALOAD, 1);
        adapter.visitFieldInsn(Opcodes.PUTFIELD, className, "config", CONFIG_WEB_NAME);

        adapter.visitVarInsn(Opcodes.ALOAD, 0);
        adapter.visitVarInsn(Opcodes.ALOAD, 2);
        adapter.visitFieldInsn(Opcodes.PUTFIELD, className, "cfc", COMPONENT_NAME);
   
        adapter.visitInsn(Opcodes.RETURN);
    Label end = new Label();
    adapter.visitLabel(end);
    adapter.visitLocalVariable("config",CONFIG_WEB_NAME, null, begin, end, 1);
    adapter.visitLocalVariable("cfc",COMPONENT_NAME, null, begin, end, 2);
   
        //adapter.returnValue();
        adapter.endMethod();
       
   
    // create methods
    Set<Class> cDone=new HashSet<Class>();
    Map<String,Class> mDone=new HashMap<String,Class>();
    for(int i=0;i<interfaces.length;i++){
      _createProxy(cw,cDone,mDone, cfc, interfaces[i],className);
    }
        cw.visitEnd();
       
       
        // create class file
        byte[] barr = cw.toByteArray();
     
        try {
          ResourceUtil.touch(classFile);
          IOUtil.copy(new ByteArrayInputStream(barr), classFile,true);
         
          cl = (PhysicalClassLoader) pci.getRPCClassLoader(true);
          Class<?> clazz = cl.loadClass(className, barr);
          return newInstance(clazz, pc.getConfig(),cfc);
        }
        catch(Throwable t) {
          throw Caster.toPageException(t);
        }
View Full Code Here

  public static void main(String[] args) throws Throwable {
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
    Resource root = frp.getResource("/Users/mic/Projects/Railo/webroot/WEB-INF/railo/cfclasses/wrappers/");
    root.mkdir();
    PhysicalClassLoader pcl = new PhysicalClassLoader(root);
    //PhysicalClassLoader pcl = (PhysicalClassLoader)ThreadLocalPageContext.getConfig().getRPCClassLoader(false);

    ASMProxyFactory.getClass(pcl, root, ArrayNew.class);
   
   
View Full Code Here

    if(rpcClassLoader!=null && !reload) return rpcClassLoader;
       
    Resource dir = getDeployDirectory().getRealResource("RPC");
    if(!dir.exists())dir.createDirectory(true);
    //rpcClassLoader = new PhysicalClassLoader(dir,getFactory().getServlet().getClass().getClassLoader());
    rpcClassLoader = new PhysicalClassLoader(dir,getClassLoader());
    return rpcClassLoader;
  }
View Full Code Here

TOP

Related Classes of railo.commons.lang.PhysicalClassLoader

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.