Search in sources :

Example 1 with ASMProperty

use of lucee.transformer.bytecode.util.ASMProperty in project Lucee by lucee.

the class Axis1Client method _mapComplex.

private Class _mapComplex(PageContext pc, SymbolTable symbolTable, Config secondChanceConfig, org.apache.axis.encoding.TypeMapping tm, TypeEntry type) throws PageException {
    // extension
    Class ex = null;
    if (type instanceof DefinedType) {
        DefinedType dt = (DefinedType) type;
        TypeEntry exType = dt.getComplexTypeExtensionBase(symbolTable);
        if (exType != null)
            ex = map(pc, symbolTable, secondChanceConfig, tm, exType);
    }
    Vector children = type.getContainedElements();
    ArrayList<ASMPropertyImpl> properties = new ArrayList<ASMPropertyImpl>();
    if (children != null) {
        Iterator it = children.iterator();
        ElementDecl el;
        Class clazz;
        TypeEntry t;
        String name;
        while (it.hasNext()) {
            clazz = null;
            el = (ElementDecl) it.next();
            t = el.getType();
            Vector els = t.getContainedElements();
            // again handle children
            if (els != null) {
                clazz = mapComplex(pc, symbolTable, secondChanceConfig, tm, t);
            }
            name = lucee.runtime.type.util.ListUtil.last(el.getQName().getLocalPart(), '>');
            if (clazz == null)
                clazz = tm.getClassForQName(t.getQName());
            if (clazz == null)
                clazz = Object.class;
            properties.add(new ASMPropertyImpl(clazz, name));
        }
    }
    ASMProperty[] props = properties.toArray(new ASMProperty[properties.size()]);
    String clientClassName = getClientClassName(type, props);
    Class pojo;
    if (pc == null)
        pojo = ComponentUtil.getComponentPropertiesClass(secondChanceConfig, clientClassName, props, ex);
    else
        pojo = ComponentUtil.getClientComponentPropertiesClass(pc, clientClassName, props, ex);
    TypeMappingUtil.registerBeanTypeMapping(tm, pojo, type.getQName());
    return pojo;
}
Also used : ArrayList(java.util.ArrayList) DefinedType(org.apache.axis.wsdl.symbolTable.DefinedType) ElementDecl(org.apache.axis.wsdl.symbolTable.ElementDecl) TypeEntry(org.apache.axis.wsdl.symbolTable.TypeEntry) ASMProperty(lucee.transformer.bytecode.util.ASMProperty) ASMPropertyImpl(lucee.transformer.bytecode.util.ASMPropertyImpl) KeyIterator(lucee.runtime.type.it.KeyIterator) KeyAsStringIterator(lucee.runtime.type.it.KeyAsStringIterator) ObjectsIterator(lucee.runtime.type.it.ObjectsIterator) Iterator(java.util.Iterator) ObjectsEntryIterator(lucee.runtime.type.it.ObjectsEntryIterator) Vector(java.util.Vector)

Example 2 with ASMProperty

use of lucee.transformer.bytecode.util.ASMProperty 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)

Example 3 with ASMProperty

use of lucee.transformer.bytecode.util.ASMProperty in project Lucee by lucee.

the class ComponentUtil method _getStructPropertiesClass.

private static Class _getStructPropertiesClass(PageContext pc, Struct sct, PhysicalClassLoader cl) throws PageException, IOException, ClassNotFoundException {
    // create hash based on the keys of the struct
    String hash = StructUtil.keyHash(sct);
    char c = hash.charAt(0);
    if (c >= '0' && c <= '9')
        hash = "a" + hash;
    // create class name (struct class name + hash)
    String className = sct.getClass().getName() + "." + hash;
    // create physcal location for the file
    String real = className.replace('.', '/');
    Resource classFile = cl.getDirectory().getRealResource(real.concat(".class"));
    // load existing class
    if (classFile.exists()) {
        try {
            Class clazz = cl.loadClass(className);
            if (clazz != null)
                return clazz;
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
    }
    // Properties
    List<ASMProperty> props = new ArrayList<ASMProperty>();
    Iterator<Entry<Key, Object>> it = sct.entryIterator();
    Entry<Key, Object> e;
    while (it.hasNext()) {
        e = it.next();
        props.add(new ASMPropertyImpl(ASMUtil.toType(e.getValue() == null ? Object.class : Object.class, /*e.getValue().getClass()*/
        true), e.getKey().getString()));
    }
    // create file
    byte[] barr = ASMUtil.createPojo(real, props.toArray(new ASMProperty[props.size()]), Object.class, new Class[] { Pojo.class }, null);
    // create class file from bytecode
    ResourceUtil.touch(classFile);
    IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
    cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(true);
    return cl.loadClass(className);
}
Also used : Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) LitString(lucee.transformer.expression.literal.LitString) PageContextImpl(lucee.runtime.PageContextImpl) ASMProperty(lucee.transformer.bytecode.util.ASMProperty) Entry(java.util.Map.Entry) ByteArrayInputStream(java.io.ByteArrayInputStream) ASMPropertyImpl(lucee.transformer.bytecode.util.ASMPropertyImpl) Key(lucee.runtime.type.Collection.Key)

Aggregations

ASMProperty (lucee.transformer.bytecode.util.ASMProperty)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 Resource (lucee.commons.io.res.Resource)2 PageContextImpl (lucee.runtime.PageContextImpl)2 ASMPropertyImpl (lucee.transformer.bytecode.util.ASMPropertyImpl)2 LitString (lucee.transformer.expression.literal.LitString)2 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 Vector (java.util.Vector)1 PhysicalClassLoader (lucee.commons.lang.PhysicalClassLoader)1 Mapping (lucee.runtime.Mapping)1 Key (lucee.runtime.type.Collection.Key)1 KeyAsStringIterator (lucee.runtime.type.it.KeyAsStringIterator)1 KeyIterator (lucee.runtime.type.it.KeyIterator)1 ObjectsEntryIterator (lucee.runtime.type.it.ObjectsEntryIterator)1 ObjectsIterator (lucee.runtime.type.it.ObjectsIterator)1 DefinedType (org.apache.axis.wsdl.symbolTable.DefinedType)1 ElementDecl (org.apache.axis.wsdl.symbolTable.ElementDecl)1 TypeEntry (org.apache.axis.wsdl.symbolTable.TypeEntry)1