Search in sources :

Example 81 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class COMUtil method toObject.

/**
 * translate a Variant Object to Object, when it is a Dispatch translate it to COMWrapper
 * @param parent
 * @param variant
 * @param key
 * @return Object from Variant
 * @throws ExpressionException
 */
public static Object toObject(COMObject parent, Variant variant, String key) throws ExpressionException {
    short type = variant.getvt();
    if (type == Variant.VariantEmpty)
        return null;
    else if (type == Variant.VariantNull)
        return null;
    else if (type == Variant.VariantShort)
        return Short.valueOf(variant.getShort());
    else if (type == Variant.VariantInt)
        return Integer.valueOf(variant.getInt());
    else if (type == Variant.VariantFloat)
        return new Float(variant.getFloat());
    else if (type == Variant.VariantDouble)
        return new Double(variant.getDouble());
    else if (type == Variant.VariantCurrency) {
        long l;
        try {
            l = variant.getCurrency().longValue();
        }// this reflection allows support for old and new jacob version
         catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            try {
                Method toCurrency = variant.getClass().getMethod("toCurrency", new Class[0]);
                Object curreny = toCurrency.invoke(variant, new Object[0]);
                Method longValue = curreny.getClass().getMethod("longValue", new Class[0]);
                l = Caster.toLongValue(longValue.invoke(curreny, new Object[0]), 0);
            } catch (Throwable t2) {
                ExceptionUtil.rethrowIfNecessary(t2);
                l = 0;
            }
        }
        return Long.valueOf(l);
    } else if (type == Variant.VariantObject)
        return variant.toEnumVariant();
    else if (type == Variant.VariantDate)
        return new DateTimeImpl((long) variant.getDate(), true);
    else if (type == Variant.VariantString)
        return variant.getString();
    else if (type == Variant.VariantBoolean)
        return variant.getBoolean() ? Boolean.TRUE : Boolean.FALSE;
    else if (type == Variant.VariantByte)
        return new Byte(variant.getByte());
    else if (type == Variant.VariantVariant) {
        throw new ExpressionException("type variant is not supported");
    // return toObject(variant.getV.get());
    } else if (type == Variant.VariantArray) {
        Variant[] varr = variant.getVariantArrayRef();
        Object[] oarr = new Object[varr.length];
        for (int i = 0; i < varr.length; i++) {
            oarr[i] = toObject(parent, varr[i], Caster.toString(i));
        }
        return new ArrayImpl(oarr);
    } else if (type == Variant.VariantDispatch) {
        return new COMObject(variant, variant.toDispatch(), parent.getName() + "." + key);
    }
    throw new ExpressionException("COM Type [" + toStringType(type) + "] not supported");
}
Also used : ArrayImpl(lucee.runtime.type.ArrayImpl) Method(java.lang.reflect.Method) ExpressionException(lucee.runtime.exp.ExpressionException) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl)

Example 82 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class Filter method invoke.

private static Collection invoke(PageContext pc, Array arr, UDF udf, ExecutorService es, List<Future<Data<Pair<Object, Object>>>> futures) throws CasterException, PageException {
    Array rtn = new ArrayImpl();
    boolean async = es != null;
    Iterator it = (arr instanceof ArrayPro ? ((ArrayPro) arr).entryArrayIterator() : arr.entryIterator());
    Entry e;
    Object res;
    while (it.hasNext()) {
        e = (Entry) it.next();
        res = _inv(pc, udf, new Object[] { e.getValue(), Caster.toDoubleValue(e.getKey()), arr }, e.getKey(), e.getValue(), es, futures);
        if (!async && Caster.toBooleanValue(res)) {
            rtn.append(e.getValue());
        }
    }
    return rtn;
}
Also used : Array(lucee.runtime.type.Array) Entry(java.util.Map.Entry) ArrayImpl(lucee.runtime.type.ArrayImpl) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) ArrayPro(lucee.runtime.type.ArrayPro)

Example 83 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class Map method invoke.

private static Array invoke(PageContext pc, Enumeration e, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures) throws PageException {
    Array rtn = new ArrayImpl();
    Object v;
    boolean async = es != null;
    Object res;
    int count = 0;
    ArgumentIntKey k;
    while (e.hasMoreElements()) {
        v = e.nextElement();
        k = ArgumentIntKey.init(++count);
        res = _inv(pc, udf, new Object[] { v }, k, es, futures);
        if (!async)
            rtn.set(k, res);
    }
    return rtn;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey)

Example 84 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class Map method invoke.

private static Collection invoke(PageContext pc, StringListData sld, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures) throws CasterException, PageException {
    Array arr = ListUtil.listToArray(sld.list, sld.delimiter, sld.includeEmptyFieldsx, sld.multiCharacterDelimiter);
    Array rtn = new ArrayImpl();
    Iterator it = (arr instanceof ArrayPro ? ((ArrayPro) arr).entryArrayIterator() : arr.entryIterator());
    Entry e;
    boolean async = es != null;
    Object res;
    while (it.hasNext()) {
        e = (Entry) it.next();
        res = _inv(pc, udf, new Object[] { e.getValue(), Caster.toDoubleValue(e.getKey()), sld.list, sld.delimiter }, e.getKey(), es, futures);
        if (!async)
            rtn.set(Caster.toString(e.getKey()), res);
    }
    return rtn;
}
Also used : Array(lucee.runtime.type.Array) Entry(java.util.Map.Entry) ArrayImpl(lucee.runtime.type.ArrayImpl) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) ArrayPro(lucee.runtime.type.ArrayPro)

Example 85 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class Map method invoke.

private static Collection invoke(PageContext pc, List list, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures) throws CasterException, PageException {
    Array rtn = new ArrayImpl();
    ListIterator it = list.listIterator();
    boolean async = es != null;
    Object res, v;
    int index;
    ArgumentIntKey k;
    while (it.hasNext()) {
        index = it.nextIndex();
        k = ArgumentIntKey.init(index);
        v = it.next();
        res = _inv(pc, udf, new Object[] { v, Caster.toDoubleValue(k.getString()), list }, k, es, futures);
        if (!async)
            rtn.set(k, res);
    }
    return rtn;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey) ListIterator(java.util.ListIterator)

Aggregations

ArrayImpl (lucee.runtime.type.ArrayImpl)100 Array (lucee.runtime.type.Array)79 Struct (lucee.runtime.type.Struct)33 StructImpl (lucee.runtime.type.StructImpl)24 PageException (lucee.runtime.exp.PageException)14 Entry (java.util.Map.Entry)13 Key (lucee.runtime.type.Collection.Key)12 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 ArrayList (java.util.ArrayList)6 ListIterator (java.util.ListIterator)6 FunctionException (lucee.runtime.exp.FunctionException)6 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)6 ApplicationException (lucee.runtime.exp.ApplicationException)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 Query (lucee.runtime.type.Query)5 QueryImpl (lucee.runtime.type.QueryImpl)5 ListAsArray (lucee.runtime.type.wrap.ListAsArray)5 NodeList (org.w3c.dom.NodeList)5