Search in sources :

Example 31 with Component

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

the class ComponentHandler method setupService.

/**
 * handle all the work necessary set
 * up the "proxy" RPC service surrounding it as the MessageContext's
 * active service.
 */
protected void setupService(MessageContext msgContext) throws Exception {
    RefBoolean isnew = new RefBooleanImpl(false);
    Component cfc = (Component) msgContext.getProperty(Constants.COMPONENT);
    Class clazz = cfc.getJavaAccessClass(ThreadLocalPageContext.get(), isnew, false, true, true, true);
    String clazzName = clazz.getName();
    ClassLoader classLoader = clazz.getClassLoader();
    Pair pair;
    SOAPService rpc = null;
    if (!isnew.toBooleanValue() && (pair = (Pair) soapServices.get(clazzName)) != null) {
        if (classLoader == pair.classloader)
            rpc = pair.rpc;
    }
    // else classLoader = clazz.getClassLoader();
    // print.out("cl:"+classLoader);
    msgContext.setClassLoader(classLoader);
    if (rpc == null) {
        rpc = new SOAPService(new RPCProvider());
        rpc.setName(clazzName);
        rpc.setOption(JavaProvider.OPTION_CLASSNAME, clazzName);
        rpc.setEngine(msgContext.getAxisEngine());
        rpc.setOption(JavaProvider.OPTION_ALLOWEDMETHODS, "*");
        rpc.setOption(JavaProvider.OPTION_SCOPE, Scope.REQUEST.getName());
        rpc.getInitializedServiceDesc(msgContext);
        soapServices.put(clazzName, new Pair(classLoader, rpc));
    }
    rpc.setEngine(msgContext.getAxisEngine());
    // ??
    rpc.init();
    msgContext.setService(rpc);
}
Also used : SOAPService(org.apache.axis.handlers.soap.SOAPService) RefBoolean(lucee.commons.lang.types.RefBoolean) RPCProvider(org.apache.axis.providers.java.RPCProvider) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Component(lucee.runtime.Component)

Example 32 with Component

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

the class ComponentProvider method invokeMethod.

@Override
protected Object invokeMethod(MessageContext mc, Method method, Object trg, Object[] args) throws Exception {
    PageContext pc = (PageContext) mc.getProperty(Constants.PAGE_CONTEXT);
    Component c = (Component) mc.getProperty(Constants.COMPONENT);
    RPCServer server = RPCServer.getInstance(pc.getId(), pc, pc.getServletContext());
    // TypeMappingUtil.getServerTypeMapping(server.getEngine().getTypeMappingRegistry());
    TypeMapping tm = mc.getTypeMapping();
    return AxisCaster.toAxisType(tm, c.call(pc, method.getName(), toLuceeType(pc, args)), null);
}
Also used : TypeMapping(javax.xml.rpc.encoding.TypeMapping) PageContext(lucee.runtime.PageContext) Component(lucee.runtime.Component)

Example 33 with Component

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

the class Decision method _isCastableTo.

private static boolean _isCastableTo(PageContext pcMaybeNull, String type, Object o) {
    if (o instanceof Component) {
        Component comp = ((Component) o);
        return comp.instanceOf(type);
    }
    if (o instanceof Pojo) {
        pcMaybeNull = ThreadLocalPageContext.get(pcMaybeNull);
        return pcMaybeNull != null && AxisCaster.toComponent(pcMaybeNull, ((Pojo) o), type, null) != null;
    }
    if (isArrayType(type) && isArray(o)) {
        String _strType = type.substring(0, type.length() - 2);
        short _type = CFTypes.toShort(_strType, false, (short) -1);
        Array arr = Caster.toArray(o, null);
        if (arr != null) {
            Iterator<Object> it = arr.valueIterator();
            while (it.hasNext()) {
                Object obj = it.next();
                if (!isCastableTo(pcMaybeNull, _type, _strType, obj))
                    return false;
            }
            return true;
        }
    }
    return false;
}
Also used : Array(lucee.runtime.type.Array) Pojo(lucee.runtime.net.rpc.Pojo) JavaObject(lucee.runtime.java.JavaObject) Component(lucee.runtime.Component)

Example 34 with Component

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

the class GetTagData method cfmlBasedTag.

private static Struct cfmlBasedTag(PageContext pc, TagLib tld, TagLibTag tag) throws PageException {
    // Map attrs = tag.getAttributes();
    TagLibTagAttr attrFilename = tag.getAttribute("__filename");
    // TagLibTagAttr attrName = tag.getAttribute("__name");
    TagLibTagAttr attrIsWeb = tag.getAttribute("__isweb");
    String filename = Caster.toString(attrFilename.getDefaultValue());
    String name = Caster.toString(attrFilename.getDefaultValue());
    boolean isWeb = Caster.toBooleanValue(attrIsWeb.getDefaultValue());
    InitFile source = CFTagCore.createInitFile(pc, isWeb, filename);
    String callPath = ResourceUtil.removeExtension(source.getFilename(), source.getFilename());
    Component cfc = ComponentLoader.loadComponent(pc, source.getPageSource(), callPath, false, true);
    ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, cfc);
    Struct metadata = Caster.toStruct(cw.get("metadata", null), null, false);
    Struct sct = new StructImpl();
    sct.set("nameSpaceSeperator", tld.getNameSpaceSeparator());
    sct.set("nameSpace", tld.getNameSpace());
    sct.set(KeyConstants._name, name.substring(0, name.lastIndexOf('.')));
    sct.set("hasNameAppendix", Boolean.FALSE);
    sct.set(KeyConstants._status, "implemeted");
    sct.set(KeyConstants._type, "cfml");
    sct.set("bodyType", getBodyType(tag));
    sct.set("attrMin", Caster.toDouble(0));
    sct.set("attrMax", Caster.toDouble(0));
    sct.set("attributeCollection", getSupportAttributeCollection(tag));
    // TODO add support for script for cfml tags
    Struct scp = new StructImpl();
    sct.set(KeyConstants._script, scp);
    scp.set("rtexpr", Boolean.FALSE);
    scp.set(KeyConstants._type, "none");
    if (metadata != null) {
        sct.set(KeyConstants._description, metadata.get("hint", ""));
        sct.set("attributeType", metadata.get("attributeType", ""));
        sct.set("parseBody", Caster.toBoolean(metadata.get("parseBody", Boolean.FALSE), Boolean.FALSE));
        Struct _attrs = new StructImpl();
        sct.set(KeyConstants._attributes, _attrs);
        Struct srcAttrs = Caster.toStruct(metadata.get(KeyConstants._attributes, null), null, false);
        Struct src;
        if (srcAttrs != null) {
            // Key[] keys = srcAttrs.keys();
            Iterator<Entry<Key, Object>> it = srcAttrs.entryIterator();
            Entry<Key, Object> e;
            while (it.hasNext()) {
                e = it.next();
                src = Caster.toStruct(e.getValue(), null, false);
                if (Caster.toBooleanValue(src.get(KeyConstants._hidden, null), false))
                    continue;
                Struct _attr = new StructImpl();
                _attr.set(KeyConstants._status, "implemeted");
                _attr.set(KeyConstants._description, src.get(KeyConstants._hint, ""));
                _attr.set(KeyConstants._type, src.get(KeyConstants._type, "any"));
                _attr.set(KeyConstants._required, Caster.toBoolean(src.get(KeyConstants._required, ""), null));
                _attr.set("scriptSupport", "none");
                _attrs.setEL(e.getKey().getLowerString(), _attr);
            }
        }
    }
    return sct;
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) Struct(lucee.runtime.type.Struct) Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) InitFile(lucee.runtime.customtag.InitFile) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Component(lucee.runtime.Component) Key(lucee.runtime.type.Collection.Key)

Example 35 with Component

use of lucee.runtime.Component 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

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