Search in sources :

Example 41 with UDF

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

the class CallStackGet method _getTagContext.

public static void _getTagContext(PageContext pc, Array tagContext, Throwable t, Collection.Key lineNumberName) {
    // Throwable root = t.getRootCause();
    Throwable cause = t.getCause();
    if (cause != null)
        _getTagContext(pc, tagContext, cause, lineNumberName);
    StackTraceElement[] traces = t.getStackTrace();
    UDF[] udfs = ((PageContextImpl) pc).getUDFs();
    int line = 0;
    String template;
    Struct item;
    StackTraceElement trace = null;
    String functionName, methodName;
    int index = udfs.length - 1;
    for (int i = 0; i < traces.length; i++) {
        trace = traces[i];
        template = trace.getFileName();
        if (trace.getLineNumber() <= 0 || template == null || ResourceUtil.getExtension(template, "").equals("java"))
            continue;
        methodName = trace.getMethodName();
        if (methodName != null && methodName.startsWith("udfCall") && index > -1)
            functionName = udfs[index--].getFunctionName();
        else
            functionName = "";
        item = new StructImpl();
        line = trace.getLineNumber();
        item.setEL(KeyConstants._function, functionName);
        /* template is now a absolute path
			try {
				template=ExpandPath.call(pc, template);
			}
			catch (PageException e) {}*/
        item.setEL(KeyConstants._template, abs((PageContextImpl) pc, template));
        item.setEL(lineNumberName, new Double(line));
        tagContext.appendEL(item);
    }
}
Also used : StructImpl(lucee.runtime.type.StructImpl) UDF(lucee.runtime.type.UDF) PageContextImpl(lucee.runtime.PageContextImpl) Struct(lucee.runtime.type.Struct)

Example 42 with UDF

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

the class _CreateComponent method call.

public static Object call(PageContext pc, Object[] objArr) throws PageException {
    String path = Caster.toString(objArr[objArr.length - 1]);
    // not store the index to make it faster
    Component c = CreateObject.doComponent(pc, path);
    // no init method
    if (!(c.get(KeyConstants._init, null) instanceof UDF)) {
        if (objArr.length > 1) {
            Object arg1 = objArr[0];
            if (arg1 instanceof FunctionValue) {
                Struct args = Caster.toFunctionValues(objArr, 0, objArr.length - 1);
                EntityNew.setPropeties(pc, c, args, true);
            } else if (Decision.isStruct(arg1)) {
                Struct args = Caster.toStruct(arg1);
                EntityNew.setPropeties(pc, c, args, true);
            }
        }
        return c;
    }
    Object rtn;
    // no arguments
    if (objArr.length == 1) {
        rtn = c.call(pc, KeyConstants._init, EMPTY);
    } else // named arguments
    if (objArr[0] instanceof FunctionValue) {
        Struct args = Caster.toFunctionValues(objArr, 0, objArr.length - 1);
        rtn = c.callWithNamedValues(pc, KeyConstants._init, args);
    } else // no name arguments
    {
        Object[] args = new Object[objArr.length - 1];
        for (int i = 0; i < objArr.length - 1; i++) {
            args[i] = objArr[i];
            if (args[i] instanceof FunctionValue)
                throw new ExpressionException("invalid argument defintion, when using named parameters to a function, every parameter must have a name.");
        }
        rtn = c.call(pc, KeyConstants._init, args);
    }
    if (rtn == null || (c.getPageSource() != null && c.getPageSource().getDialect() == CFMLEngine.DIALECT_LUCEE))
        return c;
    return rtn;
}
Also used : UDF(lucee.runtime.type.UDF) FunctionValue(lucee.runtime.type.FunctionValue) Component(lucee.runtime.Component) ExpressionException(lucee.runtime.exp.ExpressionException) Struct(lucee.runtime.type.Struct)

Aggregations

UDF (lucee.runtime.type.UDF)42 Key (lucee.runtime.type.Collection.Key)14 Struct (lucee.runtime.type.Struct)14 Component (lucee.runtime.Component)9 Entry (java.util.Map.Entry)7 PageException (lucee.runtime.exp.PageException)7 Member (lucee.runtime.component.Member)6 FunctionArgument (lucee.runtime.type.FunctionArgument)6 StructImpl (lucee.runtime.type.StructImpl)6 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)6 Iterator (java.util.Iterator)5 ComponentScope (lucee.runtime.ComponentScope)5 ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)5 PageContextImpl (lucee.runtime.PageContextImpl)5 Property (lucee.runtime.component.Property)5 Array (lucee.runtime.type.Array)5 Collection (lucee.runtime.type.Collection)5 IOException (java.io.IOException)4 Map (java.util.Map)4 HashMap (java.util.HashMap)3