Search in sources :

Example 16 with Component

use of lucee.runtime.Component in project Lucee by lucee.

the class ModernAppListener method onSessionEnd.

@Override
public void onSessionEnd(CFMLFactory factory, String applicationName, String cfid) throws PageException {
    Component app = apps.get(applicationName);
    if (app == null || !app.containsKey(ON_SESSION_END))
        return;
    PageContextImpl pc = null;
    try {
        pc = createPageContext(factory, app, applicationName, cfid, ON_SESSION_END, true, -1);
        call(app, pc, ON_SESSION_END, new Object[] { pc.sessionScope(false), pc.applicationScope() }, true);
    } finally {
        if (pc != null) {
            factory.releaseLuceePageContext(pc, true);
        }
    }
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl) Component(lucee.runtime.Component)

Example 17 with Component

use of lucee.runtime.Component in project Lucee by lucee.

the class CreateComponent method call.

public static Component call(PageContext pc, String path, Object args) throws PageException {
    // first argument is the component itself
    Component c = CreateObject.doComponent(pc, path);
    if (c.get(KeyConstants._init, null) instanceof UDF) {
        // no arguments
        if (args == null) {
            c.call(pc, KeyConstants._init, EMPTY);
        } else // named arguments
        if (Decision.isStruct(args)) {
            Struct sct = Caster.toStruct(args);
            c.callWithNamedValues(pc, KeyConstants._init, sct);
        } else // not named arguments
        if (Decision.isArray(args)) {
            Object[] arr = Caster.toNativeArray(args);
            c.call(pc, KeyConstants._init, arr);
        } else {
            c.call(pc, KeyConstants._init, new Object[] { args });
        }
    }
    return c;
}
Also used : UDF(lucee.runtime.type.UDF) Component(lucee.runtime.Component) Struct(lucee.runtime.type.Struct)

Example 18 with Component

use of lucee.runtime.Component in project Lucee by lucee.

the class CreateDynamicProxy method _call.

public static Object _call(PageContext pc, Object oCFC, Object oInterfaces) throws PageException, IOException {
    if (SystemUtil.getLoaderVersion() < 5.9D)
        throw new ApplicationException("You need to update your lucee.jar to execute the function [createDynamicProxy], you can download the latest jar from http://download.lucee.org.");
    // Component
    Component cfc;
    if (oCFC instanceof Component)
        cfc = (Component) oCFC;
    else
        cfc = pc.loadComponent(Caster.toString(oCFC));
    // string list to array
    if (Decision.isString(oInterfaces)) {
        String list = Caster.toString(oInterfaces);
        oInterfaces = ListUtil.listToStringArray(list, ',');
    }
    Class[] interfaces = null;
    if (Decision.isArray(oInterfaces)) {
        Object[] arr = Caster.toNativeArray(oInterfaces);
        ClassLoader cl = ((PageContextImpl) pc).getClassLoader();
        interfaces = new Class[arr.length];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] instanceof JavaObject)
                interfaces[i] = ((JavaObject) arr[i]).getClazz();
            else
                interfaces[i] = ClassUtil.loadClass(cl, Caster.toString(arr[i]));
        }
    // strInterfaces=ListUtil.toStringArray(Caster.toArray(oInterfaces));
    } else if (oInterfaces instanceof JavaObject) {
        interfaces = new Class[] { ((JavaObject) oInterfaces).getClazz() };
    } else
        throw new FunctionException(pc, "CreateDynamicProxy", 2, "interfaces", "invalid type [" + Caster.toClassName(oInterfaces) + "] for class defintion");
    // check if all classes are interfaces
    for (int i = 0; i < interfaces.length; i++) {
        if (!interfaces[i].isInterface())
            throw new FunctionException(pc, "CreateDynamicProxy", 2, "interfaces", "definition [" + interfaces[i].getClass() + "] is a class and not a interface");
    }
    return JavaProxyFactory.createProxy(pc, cfc, null, interfaces);
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) JavaObject(lucee.runtime.java.JavaObject) FunctionException(lucee.runtime.exp.FunctionException) JavaObject(lucee.runtime.java.JavaObject) PageContextImpl(lucee.runtime.PageContextImpl) Component(lucee.runtime.Component)

Example 19 with Component

use of lucee.runtime.Component in project Lucee by lucee.

the class _GetSuperStaticScope method call.

public static Struct call(PageContext pc) throws PageException {
    Component cfc = pc.getActiveComponent();
    if (cfc == null)
        throw new ApplicationException("[static::] is not supported outside a component.");
    Component base = cfc.getBaseComponent();
    if (base == null)
        throw new ApplicationException("component [" + cfc.getCallName() + "] does not have a base component.");
    return base.staticScope();
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) Component(lucee.runtime.Component)

Example 20 with Component

use of lucee.runtime.Component in project Lucee by lucee.

the class EntityNew method call.

public static Object call(PageContext pc, String name, Struct properties) throws PageException {
    ORMSession session = ORMUtil.getSession(pc);
    if (properties == null)
        return session.create(pc, name);
    Component entity = session.create(pc, name);
    setPropeties(pc, entity, properties, false);
    return entity;
}
Also used : ORMSession(lucee.runtime.orm.ORMSession) Component(lucee.runtime.Component)

Aggregations

Component (lucee.runtime.Component)36 PageException (lucee.runtime.exp.PageException)12 Key (lucee.runtime.type.Collection.Key)12 Struct (lucee.runtime.type.Struct)12 PageContextImpl (lucee.runtime.PageContextImpl)9 UDF (lucee.runtime.type.UDF)9 Entry (java.util.Map.Entry)7 ComponentScope (lucee.runtime.ComponentScope)7 PageContext (lucee.runtime.PageContext)7 Array (lucee.runtime.type.Array)7 JavaObject (lucee.runtime.java.JavaObject)6 IOException (java.io.IOException)5 PageSource (lucee.runtime.PageSource)5 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 Collection (lucee.runtime.type.Collection)5 ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)4 Property (lucee.runtime.component.Property)4 ArrayImpl (lucee.runtime.type.ArrayImpl)4 StructImpl (lucee.runtime.type.StructImpl)4