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");
}
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;
}
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;
}
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;
}
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;
}
Aggregations