Search in sources :

Example 1 with ASMPropertyImpl

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

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

ArrayList (java.util.ArrayList)2 ASMProperty (lucee.transformer.bytecode.util.ASMProperty)2 ASMPropertyImpl (lucee.transformer.bytecode.util.ASMPropertyImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 Vector (java.util.Vector)1 Resource (lucee.commons.io.res.Resource)1 PageContextImpl (lucee.runtime.PageContextImpl)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 LitString (lucee.transformer.expression.literal.LitString)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