Search in sources :

Example 1 with PhysicalClassLoader

use of lucee.commons.lang.PhysicalClassLoader in project Lucee by lucee.

the class AxisCaster method _toPojo.

private static Pojo _toPojo(PageContext pc, Pojo pojo, TypeMapping tm, TypeEntry typeEntry, QName type, Struct sct, Set<Object> done) throws PageException {
    // print.ds();System.exit(0);
    if (pojo == null) {
        try {
            PhysicalClassLoader cl = (PhysicalClassLoader) pc.getConfig().getRPCClassLoader(false);
            pojo = (Pojo) ClassUtil.loadInstance(ComponentUtil.getStructPropertiesClass(pc, sct, cl));
        } catch (ClassException e) {
            throw Caster.toPageException(e);
        } catch (IOException e) {
            throw Caster.toPageException(e);
        }
    }
    // initialize
    List<Property> props = new ArrayList<Property>();
    Iterator<Entry<Key, Object>> it = sct.entryIterator();
    Entry<Key, Object> e;
    PropertyImpl p;
    while (it.hasNext()) {
        e = it.next();
        p = new PropertyImpl();
        p.setAccess(Component.ACCESS_PUBLIC);
        p.setName(e.getKey().getString());
        p.setType(e.getValue() == null ? "any" : Caster.toTypeName(e.getValue()));
        props.add(p);
    }
    _initPojo(pc, typeEntry, type, pojo, props.toArray(new Property[props.size()]), sct, null, tm, done);
    return pojo;
}
Also used : Entry(java.util.Map.Entry) TypeEntry(org.apache.axis.wsdl.symbolTable.TypeEntry) PhysicalClassLoader(lucee.commons.lang.PhysicalClassLoader) ArrayList(java.util.ArrayList) ClassException(lucee.commons.lang.ClassException) PropertyImpl(lucee.runtime.component.PropertyImpl) IOException(java.io.IOException) Property(lucee.runtime.component.Property) Key(lucee.runtime.type.Collection.Key)

Example 2 with PhysicalClassLoader

use of lucee.commons.lang.PhysicalClassLoader in project Lucee by lucee.

the class PageContextImpl method getRPCClassLoader.

public ClassLoader getRPCClassLoader(boolean reload, ClassLoader[] parents) throws IOException {
    JavaSettingsImpl js = (JavaSettingsImpl) applicationContext.getJavaSettings();
    ClassLoader cl = config.getRPCClassLoader(reload, parents);
    if (js != null) {
        return ((PhysicalClassLoader) cl).getCustomClassLoader(js.getResourcesTranslated(), reload);
    }
    return cl;
}
Also used : PhysicalClassLoader(lucee.commons.lang.PhysicalClassLoader) JavaSettingsImpl(lucee.runtime.listener.JavaSettingsImpl) ResourceClassLoader(lucee.commons.io.res.util.ResourceClassLoader) PhysicalClassLoader(lucee.commons.lang.PhysicalClassLoader)

Example 3 with PhysicalClassLoader

use of lucee.commons.lang.PhysicalClassLoader in project Lucee by lucee.

the class ConfigImpl method getRPCClassLoader.

@Override
public ClassLoader getRPCClassLoader(boolean reload) throws IOException {
    if (rpcClassLoader != null && !reload)
        return rpcClassLoader;
    Resource dir = getClassDirectory().getRealResource("RPC");
    if (!dir.exists())
        dir.createDirectory(true);
    rpcClassLoader = new PhysicalClassLoader(this, dir, null, false);
    return rpcClassLoader;
}
Also used : PhysicalClassLoader(lucee.commons.lang.PhysicalClassLoader) Resource(lucee.commons.io.res.Resource) CompressResource(lucee.commons.io.res.type.compress.CompressResource)

Example 4 with PhysicalClassLoader

use of lucee.commons.lang.PhysicalClassLoader in project Lucee by lucee.

the class ComponentUtil method _getComponentPropertiesClass.

private static Class _getComponentPropertiesClass(PageContext pc, Config secondChanceConfig, String className, ASMProperty[] properties, Class extendsClass) 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 clazz;
            }
        } catch (Exception e) {
        }
    }
    // create file
    if (extendsClass == null)
        extendsClass = Object.class;
    byte[] barr = ASMUtil.createPojo(real, properties, extendsClass, 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 cl.loadClass(className);
}
Also used : Field(java.lang.reflect.Field) PhysicalClassLoader(lucee.commons.lang.PhysicalClassLoader) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(lucee.commons.io.res.Resource) LitString(lucee.transformer.expression.literal.LitString) PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 5 with PhysicalClassLoader

use of lucee.commons.lang.PhysicalClassLoader in project Lucee by lucee.

the class ComponentUtil method _getComponentPropertiesClass.

private static Class _getComponentPropertiesClass(PageContext pc, Component component) throws PageException, IOException, ClassNotFoundException {
    ASMProperty[] props = ASMUtil.toASMProperties(component.getProperties(false, true, false, false));
    String className = getClassname(component, props);
    String real = className.replace('.', '/');
    Mapping mapping = component.getPageSource().getMapping();
    PhysicalClassLoader cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(false);
    Resource classFile = cl.getDirectory().getRealResource(real.concat(".class"));
    // get component class information
    String classNameOriginal = component.getPageSource().getClassName();
    String realOriginal = classNameOriginal.replace('.', '/');
    Resource classFileOriginal = mapping.getClassRootDirectory().getRealResource(realOriginal.concat(".class"));
    // load existing class when pojo is still newer than component class file
    if (classFile.lastModified() >= classFileOriginal.lastModified()) {
        try {
            Class clazz = cl.loadClass(className);
            // ClassUtil.loadInstance(clazz);
            if (clazz != null && !hasChangesOfChildren(classFile.lastModified(), clazz))
                return clazz;
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
    }
    // extends
    String strExt = component.getExtends();
    Class<?> ext = Object.class;
    if (!StringUtil.isEmpty(strExt, true)) {
        ext = Caster.cfTypeToClass(strExt);
    }
    // 
    // create file
    byte[] barr = ASMUtil.createPojo(real, props, ext, new Class[] { Pojo.class }, component.getPageSource().getDisplayPath());
    ResourceUtil.touch(classFile);
    IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
    cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(true);
    // ClassUtil.loadInstance(cl.loadClass(className));
    return cl.loadClass(className);
}
Also used : Resource(lucee.commons.io.res.Resource) Mapping(lucee.runtime.Mapping) LitString(lucee.transformer.expression.literal.LitString) PageContextImpl(lucee.runtime.PageContextImpl) ASMProperty(lucee.transformer.bytecode.util.ASMProperty) PhysicalClassLoader(lucee.commons.lang.PhysicalClassLoader) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

PhysicalClassLoader (lucee.commons.lang.PhysicalClassLoader)9 Resource (lucee.commons.io.res.Resource)6 IOException (java.io.IOException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 PageContextImpl (lucee.runtime.PageContextImpl)3 LitString (lucee.transformer.expression.literal.LitString)3 ArrayList (java.util.ArrayList)2 CompressResource (lucee.commons.io.res.type.compress.CompressResource)2 Mapping (lucee.runtime.Mapping)2 Key (lucee.runtime.type.Collection.Key)2 ClassWriter (org.objectweb.asm.ClassWriter)2 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)2 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 Caller (lucee.commons.io.SystemUtil.Caller)1 ResourceClassLoader (lucee.commons.io.res.util.ResourceClassLoader)1