Search in sources :

Example 16 with Collection

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;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) StringListData(lucee.runtime.type.util.StringListData) Iteratorable(lucee.runtime.type.Iteratorable) ExecutorService(java.util.concurrent.ExecutorService) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) Collection(lucee.runtime.type.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Pair(lucee.commons.lang.Pair)

Example 17 with Collection

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());
}
Also used : VariableReference(lucee.runtime.type.ref.VariableReference) StringList(lucee.commons.lang.StringList) ParserString(lucee.commons.lang.ParserString) Collection(lucee.runtime.type.Collection)

Example 18 with Collection

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]);
}
Also used : UndefinedImpl(lucee.runtime.type.scope.UndefinedImpl) VariableReference(lucee.runtime.type.ref.VariableReference) Collection(lucee.runtime.type.Collection)

Example 19 with Collection

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;
}
Also used : CatchBlock(lucee.runtime.exp.CatchBlock) Collection(lucee.runtime.type.Collection)

Example 20 with Collection

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;
}
Also used : Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) Collection(lucee.runtime.type.Collection) Key(lucee.runtime.type.Collection.Key) Struct(lucee.runtime.type.Struct)

Aggregations

Collection (lucee.runtime.type.Collection)22 List (java.util.List)12 Iterator (java.util.Iterator)8 ExpressionException (lucee.runtime.exp.ExpressionException)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 Key (lucee.runtime.type.Collection.Key)6 Struct (lucee.runtime.type.Struct)6 Node (org.w3c.dom.Node)6 Entry (java.util.Map.Entry)4 XMLException (lucee.runtime.exp.XMLException)4 Array (lucee.runtime.type.Array)4 NodeList (org.w3c.dom.NodeList)4 Enumeration (java.util.Enumeration)3 FunctionException (lucee.runtime.exp.FunctionException)3 Iteratorable (lucee.runtime.type.Iteratorable)3 Query (lucee.runtime.type.Query)3 StructImpl (lucee.runtime.type.StructImpl)3 ListIterator (java.util.ListIterator)2 ExecutorService (java.util.concurrent.ExecutorService)2