use of lucee.runtime.type.Collection in project Lucee by lucee.
the class Filter method _call.
public static Collection _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, short type) throws PageException {
ExecutorService execute = null;
List<Future<Data<Pair<Object, Object>>>> futures = null;
if (parallel) {
execute = Executors.newFixedThreadPool(maxThreads);
futures = new ArrayList<Future<Data<Pair<Object, Object>>>>();
}
Collection coll;
// Array
if (type == TYPE_ARRAY) {
coll = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (type == TYPE_QUERY) {
coll = invoke(pc, (Query) obj, udf, execute, futures);
} else // Struct
if (type == TYPE_STRUCT) {
coll = invoke(pc, (Struct) obj, udf, execute, futures);
} else // Array
if (obj instanceof Array) {
coll = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (obj instanceof Query) {
coll = invoke(pc, (Query) obj, udf, execute, futures);
} else // Struct
if (obj instanceof Struct) {
coll = invoke(pc, (Struct) obj, udf, execute, futures);
} else // other Iteratorable
if (obj instanceof Iteratorable) {
coll = invoke(pc, (Iteratorable) obj, udf, execute, futures);
} else // Map
if (obj instanceof java.util.Map) {
coll = invoke(pc, (java.util.Map) obj, udf, execute, futures);
} else // List
if (obj instanceof List) {
coll = invoke(pc, (List) obj, udf, execute, futures);
} else // Iterator
if (obj instanceof Iterator) {
coll = invoke(pc, (Iterator) obj, udf, execute, futures);
} else // Enumeration
if (obj instanceof Enumeration) {
coll = invoke(pc, (Enumeration) obj, udf, execute, futures);
} else // String List
if (obj instanceof StringListData) {
coll = invoke(pc, (StringListData) obj, udf, execute, futures);
} else
throw new FunctionException(pc, "Filter", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
if (parallel)
afterCall(pc, coll, futures, execute);
return coll;
}
use of lucee.runtime.type.Collection in project Lucee by lucee.
the class VariableInterpreter method getVariableReference.
/**
* return a variable reference by string syntax ("scopename.key.key" -> "url.name")
* a variable reference, references to variable, to modifed it, with global effect.
* @param pc
* @param var variable name to get
* @return variable as Reference
* @throws PageException
*/
public static VariableReference getVariableReference(PageContext pc, String var) throws PageException {
StringList list = parse(pc, new ParserString(var), false);
if (list == null)
throw new InterpreterException("invalid variable declaration [" + var + "]");
if (list.size() == 1) {
return new VariableReference(pc.undefinedScope(), list.next());
}
int scope = scopeString2Int(pc.ignoreScopes(), list.next());
Object coll;
if (scope == Scope.SCOPE_UNDEFINED) {
coll = pc.touch(pc.undefinedScope(), KeyImpl.init(list.current()));
} else {
coll = VariableInterpreter.scope(pc, scope, list.hasNext());
// coll=pc.scope(scope);
}
while (list.hasNextNext()) {
coll = pc.touch(coll, KeyImpl.init(list.next()));
}
if (!(coll instanceof Collection))
throw new InterpreterException("invalid variable [" + var + "]");
return new VariableReference((Collection) coll, list.next());
}
use of lucee.runtime.type.Collection in project Lucee by lucee.
the class VariableInterpreter method getVariableReference.
public static VariableReference getVariableReference(PageContext pc, Collection.Key[] keys, boolean keepScope) throws PageException {
if (keys.length == 1) {
if (keepScope) {
Collection coll = ((UndefinedImpl) pc.undefinedScope()).getScopeFor(keys[0], null);
if (coll != null)
return new VariableReference(coll, keys[0]);
}
return new VariableReference(pc.undefinedScope(), keys[0]);
}
int scope = scopeKey2Int(keys[0]);
Object coll;
if (scope == Scope.SCOPE_UNDEFINED) {
coll = pc.touch(pc.undefinedScope(), keys[0]);
} else {
coll = VariableInterpreter.scope(pc, scope, keys.length > 1);
}
for (int i = 1; i < (keys.length - 1); i++) {
coll = pc.touch(coll, keys[i]);
}
if (!(coll instanceof Collection))
throw new InterpreterException("invalid variable [" + ListUtil.arrayToList(keys, ".") + "]");
return new VariableReference((Collection) coll, keys[keys.length - 1]);
}
use of lucee.runtime.type.Collection in project Lucee by lucee.
the class ModernAppListenerException method getCatchBlock.
@Override
public CatchBlock getCatchBlock(Config config) {
CatchBlock cb = rootCause.getCatchBlock(config);
Collection cause = (Collection) Duplicator.duplicate(cb, false);
// rtn.setEL("message", getMessage());
if (!cb.containsKey(KeyConstants._detail))
cb.setEL(KeyConstants._detail, "Exception throwed while invoking function [" + eventName + "] in application event handler ");
cb.setEL(ROOT_CAUSE, cause);
cb.setEL(CAUSE, cause);
// cb.setEL("stacktrace", getStackTraceAsString());
// rtn.setEL("tagcontext", new ArrayImpl());
// rtn.setEL("type", getTypeAsString());
cb.setEL(KeyConstants._name, eventName);
return cb;
}
use of lucee.runtime.type.Collection in project Lucee by lucee.
the class StructFindValue method getValues.
/**
* @param coll
* @param value
* @param all
* @param buffer
* @return
* @throws PageException
*/
private static boolean getValues(PageContext pc, Array array, Collection coll, String value, boolean all, String path) throws PageException {
// Key[] keys = coll.keys();
boolean abort = false;
Key key;
Iterator<Entry<Key, Object>> it = coll.entryIterator();
Entry<Key, Object> e;
loop: while (it.hasNext()) {
e = it.next();
if (abort)
break loop;
key = e.getKey();
Object o = e.getValue();
// Collection (this function search first for sub)
if (o instanceof Collection) {
abort = getValues(pc, array, ((Collection) o), value, all, StructFindKey.createKey(coll, path, key));
}
// matching value
if (!abort && !StructFindKey.isArray(coll)) {
String target = Caster.toString(o, null);
if ((target != null && target.equalsIgnoreCase(value))) /*|| (o instanceof Array && checkSub(array,((Array)o),value,all,path,abort))*/
{
Struct sct = new StructImpl();
sct.setEL(KeyConstants._key, key.getString());
sct.setEL(KeyConstants._path, StructFindKey.createKey(coll, path, key));
sct.setEL(KeyConstants._owner, coll);
array.append(sct);
if (!all)
abort = true;
}
}
}
return abort;
}
Aggregations