Search in sources :

Example 21 with ClassDefinition

use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.

the class TagHelper method writeOut.

/**
 * writes out the tag
 * @param tag
 * @param bc
 * @param doReuse
 * @throws TransformerException
 * @throws BundleException
 * @throws ClassException
 */
public static void writeOut(Tag tag, BytecodeContext bc, boolean doReuse, final FlowControlFinal fcf) throws TransformerException {
    final GeneratorAdapter adapter = bc.getAdapter();
    final TagLibTag tlt = tag.getTagLibTag();
    final ClassDefinition cd = tlt.getTagClassDefinition();
    final boolean fromBundle = cd.getName() != null;
    final Type currType;
    if (fromBundle) {
        try {
            if (Reflector.isInstaneOf(cd.getClazz(), BodyTag.class))
                currType = BODY_TAG;
            else
                currType = TAG;
        } catch (Exception e) {
            if (e instanceof TransformerException)
                throw (TransformerException) e;
            throw new TransformerException(e, tag.getStart());
        }
    } else
        currType = getTagType(tag);
    final int currLocal = adapter.newLocal(currType);
    Label tagBegin = new Label();
    Label tagEnd = new Label();
    ExpressionUtil.visitLine(bc, tag.getStart());
    // TODO adapter.visitLocalVariable("tag", "L"+currType.getInternalName()+";", null, tagBegin, tagEnd, currLocal);
    adapter.visitLabel(tagBegin);
    // tag=pc.use(String tagClassName,String tagBundleName, String tagBundleVersion, String fullname,int attrType) throws PageException {
    adapter.loadArg(0);
    adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
    adapter.push(cd.getClassName());
    // has bundle info/version
    if (fromBundle) {
        // name
        adapter.push(cd.getName());
        // version
        if (cd.getVersion() != null)
            adapter.push(cd.getVersionAsString());
        else
            ASMConstants.NULL(adapter);
    }
    adapter.push(tlt.getFullName());
    adapter.push(tlt.getAttributeType());
    adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, fromBundle ? USE5 : USE3);
    if (currType != TAG)
        adapter.checkCast(currType);
    adapter.storeLocal(currLocal);
    TryFinallyVisitor outerTcfv = new TryFinallyVisitor(new OnFinally() {

        @Override
        public void _writeOut(BytecodeContext bc) {
            adapter.loadArg(0);
            adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
            adapter.loadLocal(currLocal);
            if (cd.getName() != null) {
                adapter.push(cd.getName());
                if (cd.getVersion() != null)
                    adapter.push(cd.getVersionAsString());
                else
                    ASMConstants.NULL(adapter);
            }
            adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, fromBundle ? RE_USE3 : RE_USE1);
        }
    }, null);
    if (doReuse)
        outerTcfv.visitTryBegin(bc);
    // appendix
    if (tlt.hasAppendix()) {
        adapter.loadLocal(currLocal);
        adapter.push(tag.getAppendix());
        if (// PageContextUtil.setAppendix(tag,appendix)
        fromBundle)
            ASMUtil.invoke(ASMUtil.STATIC, adapter, Types.TAG_UTIL, SET_APPENDIX2);
        else
            // tag.setAppendix(appendix)
            ASMUtil.invoke(ASMUtil.VIRTUAL, adapter, currType, SET_APPENDIX1);
    }
    // hasBody
    boolean hasBody = tag.getBody() != null;
    if (tlt.isBodyFree() && tlt.hasBodyMethodExists()) {
        adapter.loadLocal(currLocal);
        adapter.push(hasBody);
        if (// PageContextUtil.setAppendix(tag,appendix)
        fromBundle)
            ASMUtil.invoke(ASMUtil.STATIC, adapter, Types.TAG_UTIL, HAS_BODY2);
        else
            // tag.setAppendix(appendix)
            ASMUtil.invoke(ASMUtil.VIRTUAL, adapter, currType, HAS_BODY1);
    }
    // default attributes (get overwritten by attributeCollection because of that set before)
    setAttributes(bc, tag, currLocal, currType, true, fromBundle);
    // attributeCollection
    Attribute attrColl = tag.getAttribute("attributecollection");
    if (attrColl != null) {
        int attrType = tag.getTagLibTag().getAttributeType();
        if (TagLibTag.ATTRIBUTE_TYPE_NONAME != attrType) {
            tag.removeAttribute("attributecollection");
            // TagUtil.setAttributeCollection(Tag, Struct)
            adapter.loadArg(0);
            adapter.loadLocal(currLocal);
            if (currType != TAG)
                adapter.cast(currType, TAG);
            // /
            TagLibTagAttr[] missings = tag.getMissingAttributes();
            if (!ArrayUtil.isEmpty(missings)) {
                ArrayVisitor av = new ArrayVisitor();
                av.visitBegin(adapter, MISSING_ATTRIBUTE, missings.length);
                int count = 0;
                TagLibTagAttr miss;
                for (int i = 0; i < missings.length; i++) {
                    miss = missings[i];
                    av.visitBeginItem(adapter, count++);
                    bc.getFactory().registerKey(bc, bc.getFactory().createLitString(miss.getName()), false);
                    adapter.push(miss.getType());
                    if (ArrayUtil.isEmpty(miss.getAlias()))
                        adapter.invokeStatic(MISSING_ATTRIBUTE, NEW_INSTANCE_MAX2);
                    else {
                        new LiteralStringArray(bc.getFactory(), miss.getAlias()).writeOut(bc, Expression.MODE_REF);
                        adapter.invokeStatic(MISSING_ATTRIBUTE, NEW_INSTANCE_MAX3);
                    }
                    av.visitEndItem(bc.getAdapter());
                }
                av.visitEnd();
            } else {
                ASMConstants.NULL(adapter);
            }
            // /
            attrColl.getValue().writeOut(bc, Expression.MODE_REF);
            adapter.push(attrType);
            adapter.invokeStatic(TAG_UTIL, SET_ATTRIBUTE_COLLECTION);
        }
    }
    // metadata
    Attribute attr;
    Map<String, Attribute> metadata = tag.getMetaData();
    if (metadata != null) {
        Iterator<Attribute> it = metadata.values().iterator();
        while (it.hasNext()) {
            attr = it.next();
            adapter.loadLocal(currLocal);
            adapter.push(attr.getName());
            attr.getValue().writeOut(bc, Expression.MODE_REF);
            if (fromBundle)
                ASMUtil.invoke(ASMUtil.STATIC, adapter, Types.TAG_UTIL, SET_META_DATA3);
            else
                ASMUtil.invoke(ASMUtil.VIRTUAL, adapter, currType, SET_META_DATA2);
        }
    }
    // set attributes
    setAttributes(bc, tag, currLocal, currType, false, fromBundle);
    // Body
    if (hasBody) {
        final int state = adapter.newLocal(Types.INT_VALUE);
        // int state=tag.doStartTag();
        adapter.loadLocal(currLocal);
        ASMUtil.invoke(fromBundle ? ASMUtil.INTERFACE : ASMUtil.VIRTUAL, adapter, currType, DO_START_TAG);
        // adapter.invokeVirtual(currType, DO_START_TAG);
        adapter.storeLocal(state);
        // if (state!=Tag.SKIP_BODY)
        Label endBody = new Label();
        adapter.loadLocal(state);
        adapter.push(javax.servlet.jsp.tagext.Tag.SKIP_BODY);
        adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, endBody);
        // pc.initBody(tag, state);
        adapter.loadArg(0);
        adapter.loadLocal(currLocal);
        adapter.loadLocal(state);
        adapter.invokeVirtual(Types.PAGE_CONTEXT, INIT_BODY);
        OnFinally onFinally = new OnFinally() {

            @Override
            public void _writeOut(BytecodeContext bc) {
                Label endIf = new Label();
                /*if(tlt.handleException() && fcf!=null && fcf.getAfterFinalGOTOLabel()!=null){
							ASMUtil.visitLabel(adapter, fcf.getFinalEntryLabel());
						}*/
                adapter.loadLocal(state);
                adapter.push(javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE);
                adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, endIf);
                // ... pc.popBody();
                adapter.loadArg(0);
                adapter.invokeVirtual(Types.PAGE_CONTEXT, POP_BODY);
                adapter.pop();
                adapter.visitLabel(endIf);
                // tag.doFinally();
                if (tlt.handleException()) {
                    adapter.loadLocal(currLocal);
                    ASMUtil.invoke(fromBundle ? ASMUtil.INTERFACE : ASMUtil.VIRTUAL, adapter, currType, DO_FINALLY);
                // adapter.invokeVirtual(currType, DO_FINALLY);
                }
            // GOTO after execution body, used when a continue/break was called before
            /*if(fcf!=null) {
							Label l = fcf.getAfterFinalGOTOLabel();
							if(l!=null)adapter.visitJumpInsn(Opcodes.GOTO, l);
						}*/
            }
        };
        if (tlt.handleException()) {
            TryCatchFinallyVisitor tcfv = new TryCatchFinallyVisitor(onFinally, fcf);
            tcfv.visitTryBegin(bc);
            doTry(bc, adapter, tag, currLocal, currType, fromBundle);
            int t = tcfv.visitTryEndCatchBeging(bc);
            // tag.doCatch(t);
            adapter.loadLocal(currLocal);
            adapter.loadLocal(t);
            // adapter.visitVarInsn(Opcodes.ALOAD,t);
            ASMUtil.invoke(fromBundle ? ASMUtil.INTERFACE : ASMUtil.VIRTUAL, adapter, currType, DO_CATCH);
            // adapter.invokeVirtual(currType, DO_CATCH);
            tcfv.visitCatchEnd(bc);
        } else {
            TryFinallyVisitor tfv = new TryFinallyVisitor(onFinally, fcf);
            tfv.visitTryBegin(bc);
            doTry(bc, adapter, tag, currLocal, currType, fromBundle);
            tfv.visitTryEnd(bc);
        }
        adapter.visitLabel(endBody);
    } else {
        // tag.doStartTag();
        adapter.loadLocal(currLocal);
        ASMUtil.invoke(fromBundle ? ASMUtil.INTERFACE : ASMUtil.VIRTUAL, adapter, currType, DO_START_TAG);
        // adapter.invokeVirtual(currType, DO_START_TAG);
        adapter.pop();
    }
    // if (tag.doEndTag()==Tag.SKIP_PAGE) throw new Abort(0<!-- SCOPE_PAGE -->);
    Label endDoEndTag = new Label();
    adapter.loadLocal(currLocal);
    ASMUtil.invoke(fromBundle ? ASMUtil.INTERFACE : ASMUtil.VIRTUAL, adapter, currType, DO_END_TAG);
    // adapter.invokeVirtual(currType, DO_END_TAG);
    adapter.push(javax.servlet.jsp.tagext.Tag.SKIP_PAGE);
    adapter.visitJumpInsn(Opcodes.IF_ICMPNE, endDoEndTag);
    adapter.push(Abort.SCOPE_PAGE);
    adapter.invokeStatic(ABORT, NEW_INSTANCE);
    adapter.throwException();
    adapter.visitLabel(endDoEndTag);
    if (doReuse) {
        // } finally{pc.reuse(tag);}
        outerTcfv.visitTryEnd(bc);
    }
    adapter.visitLabel(tagEnd);
    ExpressionUtil.visitLine(bc, tag.getEnd());
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) TagLibTag(lucee.transformer.library.tag.TagLibTag) LiteralStringArray(lucee.transformer.bytecode.expression.type.LiteralStringArray) MissingAttribute(lucee.runtime.tag.MissingAttribute) Label(org.objectweb.asm.Label) ClassDefinition(lucee.runtime.db.ClassDefinition) ClassException(lucee.commons.lang.ClassException) TransformerException(lucee.transformer.TransformerException) BundleException(org.osgi.framework.BundleException) Type(org.objectweb.asm.Type) OnFinally(lucee.transformer.bytecode.visitor.OnFinally) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) TryCatchFinallyVisitor(lucee.transformer.bytecode.visitor.TryCatchFinallyVisitor) ArrayVisitor(lucee.transformer.bytecode.visitor.ArrayVisitor) TryFinallyVisitor(lucee.transformer.bytecode.visitor.TryFinallyVisitor) TransformerException(lucee.transformer.TransformerException) BytecodeContext(lucee.transformer.bytecode.BytecodeContext)

Example 22 with ClassDefinition

use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.

the class VT method _writeOutFirstBIF.

static Type _writeOutFirstBIF(BytecodeContext bc, BIF bif, int mode, boolean last, Position line) throws TransformerException {
    double start = SystemUtil.millis();
    GeneratorAdapter adapter = bc.getAdapter();
    adapter.loadArg(0);
    // class
    ClassDefinition bifCD = bif.getClassDefinition();
    Class clazz = null;
    try {
        clazz = bifCD.getClazz();
    } catch (Exception e) {
        SystemOut.printDate(e);
    }
    Type rtnType = Types.toType(bif.getReturnType());
    if (rtnType == Types.VOID)
        rtnType = Types.STRING;
    // arguments
    Argument[] args = bif.getArguments();
    Type[] argTypes;
    // MUST setting this to false need to work !!!
    boolean core = bif.getFlf().isCore();
    if (bif.getArgType() == FunctionLibFunction.ARG_FIX && !bifCD.isBundle() && core) {
        if (isNamed(bif.getFlf().getName(), args)) {
            NamedArgument[] nargs = toNamedArguments(args);
            String[] names = new String[nargs.length];
            // get all names
            for (int i = 0; i < nargs.length; i++) {
                names[i] = getName(nargs[i].getName());
            }
            ArrayList<FunctionLibFunctionArg> list = bif.getFlf().getArg();
            Iterator<FunctionLibFunctionArg> it = list.iterator();
            argTypes = new Type[list.size() + 1];
            argTypes[0] = Types.PAGE_CONTEXT;
            FunctionLibFunctionArg flfa;
            int index = 0;
            VT vt;
            while (it.hasNext()) {
                flfa = it.next();
                vt = getMatchingValueAndType(bc.getFactory(), flfa, nargs, names, line);
                if (vt.index != -1)
                    names[vt.index] = null;
                argTypes[++index] = Types.toType(vt.type);
                if (vt.value == null)
                    ASMConstants.NULL(bc.getAdapter());
                else
                    vt.value.writeOut(bc, Types.isPrimitiveType(argTypes[index]) ? MODE_VALUE : MODE_REF);
            }
            for (int y = 0; y < names.length; y++) {
                if (names[y] != null) {
                    TransformerException bce = new TransformerException("argument [" + names[y] + "] is not allowed for function [" + bif.getFlf().getName() + "]", args[y].getStart());
                    UDFUtil.addFunctionDoc(bce, bif.getFlf());
                    throw bce;
                }
            }
        } else {
            argTypes = new Type[args.length + 1];
            argTypes[0] = Types.PAGE_CONTEXT;
            for (int y = 0; y < args.length; y++) {
                argTypes[y + 1] = Types.toType(args[y].getStringType());
                args[y].writeOutValue(bc, Types.isPrimitiveType(argTypes[y + 1]) ? MODE_VALUE : MODE_REF);
            }
            // if no method exists for the exact match of arguments, call the method with all arguments (when exists)
            if (methodExists(clazz, "call", argTypes, rtnType) == Boolean.FALSE) {
                ArrayList<FunctionLibFunctionArg> _args = bif.getFlf().getArg();
                Type[] tmp = new Type[_args.size() + 1];
                // fill the existing
                for (int i = 0; i < argTypes.length; i++) {
                    tmp[i] = argTypes[i];
                }
                // get the rest with default values
                FunctionLibFunctionArg flfa;
                VT def;
                for (int i = argTypes.length; i < tmp.length; i++) {
                    flfa = _args.get(i - 1);
                    tmp[i] = Types.toType(flfa.getTypeAsString());
                    def = getDefaultValue(bc.getFactory(), flfa);
                    if (def.value != null)
                        def.value.writeOut(bc, Types.isPrimitiveType(tmp[i]) ? MODE_VALUE : MODE_REF);
                    else
                        ASMConstants.NULL(bc.getAdapter());
                }
                argTypes = tmp;
            }
        }
    } else // Arg Type DYN or bundle based
    {
        // /////////////////////////////////////////////////////////////
        if (bif.getArgType() == FunctionLibFunction.ARG_FIX) {
            if (isNamed(bif.getFlf().getName(), args)) {
                NamedArgument[] nargs = toNamedArguments(args);
                String[] names = getNames(nargs);
                ArrayList<FunctionLibFunctionArg> list = bif.getFlf().getArg();
                Iterator<FunctionLibFunctionArg> it = list.iterator();
                LinkedList<Argument> tmpArgs = new LinkedList<Argument>();
                LinkedList<Boolean> nulls = new LinkedList<Boolean>();
                FunctionLibFunctionArg flfa;
                VT vt;
                while (it.hasNext()) {
                    flfa = it.next();
                    vt = getMatchingValueAndType(bc.getFactory(), flfa, nargs, names, line);
                    if (vt.index != -1)
                        names[vt.index] = null;
                    if (vt.value == null)
                        // has to by any otherwise a caster is set
                        tmpArgs.add(new Argument(bif.getFactory().createNull(), "any"));
                    else
                        tmpArgs.add(new Argument(vt.value, vt.type));
                    nulls.add(vt.value == null);
                }
                for (int y = 0; y < names.length; y++) {
                    if (names[y] != null) {
                        TransformerException bce = new TransformerException("argument [" + names[y] + "] is not allowed for function [" + bif.getFlf().getName() + "]", args[y].getStart());
                        UDFUtil.addFunctionDoc(bce, bif.getFlf());
                        throw bce;
                    }
                }
                // remove null at the end
                Boolean tmp;
                while ((tmp = nulls.pollLast()) != null) {
                    if (!tmp.booleanValue())
                        break;
                    tmpArgs.pollLast();
                }
                args = tmpArgs.toArray(new Argument[tmpArgs.size()]);
            }
        }
        // /////////////////////////////////////////////////////////////
        argTypes = new Type[2];
        argTypes[0] = Types.PAGE_CONTEXT;
        argTypes[1] = Types.OBJECT_ARRAY;
        ExpressionUtil.writeOutExpressionArray(bc, Types.OBJECT, args);
    }
    // core
    if (core && !bifCD.isBundle()) {
        adapter.invokeStatic(Type.getType(clazz), new Method("call", rtnType, argTypes));
    } else // external
    {
        // className
        if (bifCD.getClassName() != null)
            adapter.push(bifCD.getClassName());
        else
            ASMConstants.NULL(adapter);
        if (// bundle name
        bifCD.getName() != null)
            // bundle name
            adapter.push(bifCD.getName());
        else
            ASMConstants.NULL(adapter);
        if (// bundle version
        bifCD.getVersionAsString() != null)
            // bundle version
            adapter.push(bifCD.getVersionAsString());
        else
            ASMConstants.NULL(adapter);
        adapter.invokeStatic(Types.FUNCTION_HANDLER_POOL, INVOKE);
        rtnType = Types.OBJECT;
    }
    if (mode == MODE_REF || !last) {
        if (Types.isPrimitiveType(rtnType)) {
            adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtnType), new Type[] { rtnType }));
            rtnType = Types.toRefType(rtnType);
        }
    }
    return rtnType;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) ClassDefinition(lucee.runtime.db.ClassDefinition) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg) TransformerException(lucee.transformer.TransformerException) Method(org.objectweb.asm.commons.Method) TransformerException(lucee.transformer.TransformerException) TemplateException(lucee.runtime.exp.TemplateException) LinkedList(java.util.LinkedList) Type(org.objectweb.asm.Type) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter)

Example 23 with ClassDefinition

use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.

the class GetApplicationSettings method call.

public static Struct call(PageContext pc, boolean suppressFunctions) {
    ApplicationContext ac = pc.getApplicationContext();
    Component cfc = null;
    if (ac instanceof ModernApplicationContext)
        cfc = ((ModernApplicationContext) ac).getComponent();
    Struct sct = new StructImpl();
    sct.setEL("applicationTimeout", ac.getApplicationTimeout());
    sct.setEL("clientManagement", Caster.toBoolean(ac.isSetClientManagement()));
    sct.setEL("clientStorage", ac.getClientstorage());
    sct.setEL("sessionStorage", ac.getSessionstorage());
    sct.setEL("customTagPaths", toArray(ac.getCustomTagMappings()));
    sct.setEL("loginStorage", AppListenerUtil.translateLoginStorage(ac.getLoginStorage()));
    sct.setEL(KeyConstants._mappings, toStruct(ac.getMappings()));
    sct.setEL(KeyConstants._name, ac.getName());
    sct.setEL("scriptProtect", AppListenerUtil.translateScriptProtect(ac.getScriptProtect()));
    sct.setEL("secureJson", Caster.toBoolean(ac.getSecureJson()));
    sct.setEL("typeChecking", Caster.toBoolean(ac.getTypeChecking()));
    sct.setEL("secureJsonPrefix", ac.getSecureJsonPrefix());
    sct.setEL("sessionManagement", Caster.toBoolean(ac.isSetSessionManagement()));
    sct.setEL("sessionTimeout", ac.getSessionTimeout());
    sct.setEL("clientTimeout", ac.getClientTimeout());
    sct.setEL("setClientCookies", Caster.toBoolean(ac.isSetClientCookies()));
    sct.setEL("setDomainCookies", Caster.toBoolean(ac.isSetDomainCookies()));
    sct.setEL(KeyConstants._name, ac.getName());
    sct.setEL("localMode", ac.getLocalMode() == Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS ? Boolean.TRUE : Boolean.FALSE);
    sct.setEL(KeyConstants._locale, LocaleFactory.toString(pc.getLocale()));
    sct.setEL(KeyConstants._timezone, TimeZoneUtil.toString(pc.getTimeZone()));
    // scope cascading
    sct.setEL("scopeCascading", ConfigWebUtil.toScopeCascading(ac.getScopeCascading(), null));
    if (ac.getScopeCascading() != Config.SCOPE_SMALL) {
        sct.setEL("searchImplicitScopes", ac.getScopeCascading() == Config.SCOPE_STANDARD);
    }
    Struct cs = new StructImpl();
    cs.setEL("web", pc.getWebCharset().name());
    cs.setEL("resource", ((PageContextImpl) pc).getResourceCharset().name());
    sct.setEL("charset", cs);
    sct.setEL("sessionType", AppListenerUtil.toSessionType(((PageContextImpl) pc).getSessionType(), "application"));
    // TODO impl
    sct.setEL("serverSideFormValidation", Boolean.FALSE);
    sct.setEL("clientCluster", Caster.toBoolean(ac.getClientCluster()));
    sct.setEL("sessionCluster", Caster.toBoolean(ac.getSessionCluster()));
    sct.setEL("invokeImplicitAccessor", Caster.toBoolean(ac.getTriggerComponentDataMember()));
    sct.setEL("triggerDataMember", Caster.toBoolean(ac.getTriggerComponentDataMember()));
    sct.setEL("sameformfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_FORM)));
    sct.setEL("sameurlfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_URL)));
    Object ds = ac.getDefDataSource();
    if (ds instanceof DataSource)
        ds = _call((DataSource) ds);
    else
        ds = Caster.toString(ds, null);
    sct.setEL(KeyConstants._datasource, ds);
    sct.setEL("defaultDatasource", ds);
    Resource src = ac.getSource();
    if (src != null)
        sct.setEL(KeyConstants._source, src.getAbsolutePath());
    // orm
    if (ac.isORMEnabled()) {
        ORMConfiguration conf = ac.getORMConfiguration();
        if (conf != null)
            sct.setEL(KeyConstants._orm, conf.toStruct());
    }
    // s3
    Properties props = ac.getS3();
    if (props != null) {
        sct.setEL(KeyConstants._s3, props.toStruct());
    }
    // ws settings
    {
        Struct wssettings = new StructImpl();
        wssettings.put(KeyConstants._type, AppListenerUtil.toWSType(ac.getWSType(), "Axis1"));
        sct.setEL("wssettings", wssettings);
    }
    // datasources
    Struct _sources = new StructImpl();
    sct.setEL(KeyConstants._datasources, _sources);
    DataSource[] sources = ac.getDataSources();
    if (!ArrayUtil.isEmpty(sources)) {
        for (int i = 0; i < sources.length; i++) {
            _sources.setEL(KeyImpl.init(sources[i].getName()), _call(sources[i]));
        }
    }
    // logs
    Struct _logs = new StructImpl();
    sct.setEL("logs", _logs);
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Iterator<Key> it = acs.getLogNames().iterator();
        Key name;
        while (it.hasNext()) {
            name = it.next();
            _logs.setEL(name, acs.getLogMetaData(name.getString()));
        }
    }
    // mails
    Array _mails = new ArrayImpl();
    sct.setEL("mails", _mails);
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Server[] servers = acs.getMailServers();
        Struct s;
        Server srv;
        if (servers != null) {
            for (int i = 0; i < servers.length; i++) {
                srv = servers[i];
                s = new StructImpl();
                _mails.appendEL(s);
                s.setEL(KeyConstants._host, srv.getHostName());
                s.setEL(KeyConstants._port, srv.getPort());
                if (!StringUtil.isEmpty(srv.getUsername()))
                    s.setEL(KeyConstants._username, srv.getUsername());
                if (!StringUtil.isEmpty(srv.getPassword()))
                    s.setEL(KeyConstants._password, srv.getPassword());
                s.setEL(KeyConstants._readonly, srv.isReadOnly());
                s.setEL("ssl", srv.isSSL());
                s.setEL("tls", srv.isTLS());
                if (srv instanceof ServerImpl) {
                    ServerImpl srvi = (ServerImpl) srv;
                    s.setEL("lifeTimespan", TimeSpanImpl.fromMillis(srvi.getLifeTimeSpan()));
                    s.setEL("idleTimespan", TimeSpanImpl.fromMillis(srvi.getIdleTimeSpan()));
                }
            }
        }
    }
    // tag
    Map<Key, Map<Collection.Key, Object>> tags = ac.getTagAttributeDefaultValues(pc);
    if (tags != null) {
        Struct tag = new StructImpl();
        Iterator<Entry<Key, Map<Collection.Key, Object>>> it = tags.entrySet().iterator();
        Entry<Collection.Key, Map<Collection.Key, Object>> e;
        Iterator<Entry<Collection.Key, Object>> iit;
        Entry<Collection.Key, Object> ee;
        Struct tmp;
        // TagLib lib = ((ConfigImpl)pc.getConfig()).getCoreTagLib();
        while (it.hasNext()) {
            e = it.next();
            iit = e.getValue().entrySet().iterator();
            tmp = new StructImpl();
            while (iit.hasNext()) {
                ee = iit.next();
                // lib.getTagByClassName(ee.getKey());
                tmp.setEL(ee.getKey(), ee.getValue());
            }
            tag.setEL(e.getKey(), tmp);
        }
        sct.setEL(KeyConstants._tag, tag);
    }
    // cache
    String fun = ac.getDefaultCacheName(Config.CACHE_TYPE_FUNCTION);
    String obj = ac.getDefaultCacheName(Config.CACHE_TYPE_OBJECT);
    String qry = ac.getDefaultCacheName(Config.CACHE_TYPE_QUERY);
    String res = ac.getDefaultCacheName(Config.CACHE_TYPE_RESOURCE);
    String tmp = ac.getDefaultCacheName(Config.CACHE_TYPE_TEMPLATE);
    String inc = ac.getDefaultCacheName(Config.CACHE_TYPE_INCLUDE);
    String htt = ac.getDefaultCacheName(Config.CACHE_TYPE_HTTP);
    String fil = ac.getDefaultCacheName(Config.CACHE_TYPE_FILE);
    String wse = ac.getDefaultCacheName(Config.CACHE_TYPE_WEBSERVICE);
    // cache connections
    Struct conns = new StructImpl();
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Key[] names = acs.getCacheConnectionNames();
        for (Key name : names) {
            CacheConnection data = acs.getCacheConnection(name.getString(), null);
            Struct _sct = new StructImpl();
            conns.setEL(name, _sct);
            _sct.setEL(KeyConstants._custom, data.getCustom());
            _sct.setEL(KeyConstants._storage, data.isStorage());
            ClassDefinition cd = data.getClassDefinition();
            if (cd != null) {
                _sct.setEL(KeyConstants._class, cd.getClassName());
                if (!StringUtil.isEmpty(cd.getName()))
                    _sct.setEL(KeyConstants._bundleName, cd.getClassName());
                if (cd.getVersion() != null)
                    _sct.setEL(KeyConstants._bundleVersion, cd.getVersionAsString());
            }
        }
    }
    if (!conns.isEmpty() || fun != null || obj != null || qry != null || res != null || tmp != null || inc != null || htt != null || fil != null || wse != null) {
        Struct cache = new StructImpl();
        sct.setEL(KeyConstants._cache, cache);
        if (fun != null)
            cache.setEL(KeyConstants._function, fun);
        if (obj != null)
            cache.setEL(KeyConstants._object, obj);
        if (qry != null)
            cache.setEL(KeyConstants._query, qry);
        if (res != null)
            cache.setEL(KeyConstants._resource, res);
        if (tmp != null)
            cache.setEL(KeyConstants._template, tmp);
        if (inc != null)
            cache.setEL(KeyConstants._include, inc);
        if (htt != null)
            cache.setEL(KeyConstants._http, htt);
        if (fil != null)
            cache.setEL(KeyConstants._file, fil);
        if (wse != null)
            cache.setEL(KeyConstants._webservice, wse);
        if (conns != null)
            cache.setEL(KeyConstants._connections, conns);
    }
    // java settings
    JavaSettings js = ac.getJavaSettings();
    StructImpl jsSct = new StructImpl();
    jsSct.put("loadCFMLClassPath", js.loadCFMLClassPath());
    jsSct.put("reloadOnChange", js.reloadOnChange());
    jsSct.put("watchInterval", new Double(js.watchInterval()));
    jsSct.put("watchExtensions", ListUtil.arrayToList(js.watchedExtensions(), ","));
    Resource[] reses = js.getResources();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < reses.length; i++) {
        if (i > 0)
            sb.append(',');
        sb.append(reses[i].getAbsolutePath());
    }
    jsSct.put("loadCFMLClassPath", sb.toString());
    sct.put("javaSettings", jsSct);
    if (cfc != null) {
        sct.setEL(KeyConstants._component, cfc.getPageSource().getDisplayPath());
        try {
            ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, cfc);
            Iterator<Key> it = cw.keyIterator();
            Collection.Key key;
            Object value;
            while (it.hasNext()) {
                key = it.next();
                value = cw.get(key);
                if (suppressFunctions && value instanceof UDF)
                    continue;
                if (!sct.containsKey(key))
                    sct.setEL(key, value);
            }
        } catch (PageException e) {
            SystemOut.printDate(e);
        }
    }
    return sct;
}
Also used : Server(lucee.runtime.net.mail.Server) ArrayImpl(lucee.runtime.type.ArrayImpl) Properties(lucee.runtime.net.s3.Properties) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) ModernApplicationContext(lucee.runtime.listener.ModernApplicationContext) ApplicationContext(lucee.runtime.listener.ApplicationContext) Entry(java.util.Map.Entry) ServerImpl(lucee.runtime.net.mail.ServerImpl) UDF(lucee.runtime.type.UDF) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Component(lucee.runtime.Component) ORMConfiguration(lucee.runtime.orm.ORMConfiguration) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) PageException(lucee.runtime.exp.PageException) JavaSettings(lucee.runtime.listener.JavaSettings) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) DataSource(lucee.runtime.db.DataSource) Array(lucee.runtime.type.Array) Key(lucee.runtime.type.Collection.Key) StructImpl(lucee.runtime.type.StructImpl) Collection(lucee.runtime.type.Collection) ModernApplicationContext(lucee.runtime.listener.ModernApplicationContext) Map(java.util.Map) CacheConnection(lucee.runtime.cache.CacheConnection) Key(lucee.runtime.type.Collection.Key)

Example 24 with ClassDefinition

use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.

the class ModernApplicationContext method toCacheConnection.

public static CacheConnection toCacheConnection(Config config, String name, Struct data) throws ApplicationException, CacheException, ClassException, BundleException {
    // class definition
    String className = Caster.toString(data.get(KeyConstants._class, null), null);
    if (StringUtil.isEmpty(className))
        throw new ApplicationException("missing key class in struct the defines a cachec connection");
    ClassDefinition cd = new ClassDefinitionImpl(className, Caster.toString(data.get(KeyConstants._bundleName, null), null), Caster.toString(data.get(KeyConstants._bundleVersion, null), null), config.getIdentification());
    CacheConnectionImpl cc = new CacheConnectionImpl(config, name, cd, Caster.toStruct(data.get(KeyConstants._custom, null), null), Caster.toBooleanValue(data.get(KeyConstants._readonly, null), false), Caster.toBooleanValue(data.get(KeyConstants._storage, null), false));
    String id = cc.id();
    CacheConnection icc = initCacheConnections.get(id);
    if (icc != null)
        return icc;
    try {
        Method m = cd.getClazz().getMethod("init", new Class[] { Config.class, String[].class, Struct[].class });
        if (Modifier.isStatic(m.getModifiers()))
            m.invoke(null, new Object[] { config, new String[] { cc.getName() }, new Struct[] { cc.getCustom() } });
        else
            SystemOut.print(config.getErrWriter(), "method [init(Config,String[],Struct[]):void] for class [" + cd.toString() + "] is not static");
        initCacheConnections.put(id, cc);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    return cc;
}
Also used : ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) ApplicationException(lucee.runtime.exp.ApplicationException) CacheConnectionImpl(lucee.runtime.cache.CacheConnectionImpl) Method(java.lang.reflect.Method) ClassDefinition(lucee.runtime.db.ClassDefinition) CacheConnection(lucee.runtime.cache.CacheConnection) Struct(lucee.runtime.type.Struct)

Example 25 with ClassDefinition

use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.

the class Admin method doUpdateAdminSyncClass.

private void doUpdateAdminSyncClass() throws PageException {
    ClassDefinition cd = new ClassDefinitionImpl(getString("admin", action, "class"), getString("bundleName", null), getString("bundleVersion", null), config.getIdentification());
    admin.updateAdminSyncClass(cd);
    store();
}
Also used : ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) ClassDefinition(lucee.runtime.db.ClassDefinition)

Aggregations

ClassDefinition (lucee.runtime.db.ClassDefinition)41 ClassDefinitionImpl (lucee.transformer.library.ClassDefinitionImpl)24 Element (org.w3c.dom.Element)15 ApplicationException (lucee.runtime.exp.ApplicationException)12 lucee.aprint (lucee.aprint)11 Struct (lucee.runtime.type.Struct)10 CFXTagClass (lucee.runtime.cfx.customtag.CFXTagClass)9 CPPCFXTagClass (lucee.runtime.cfx.customtag.CPPCFXTagClass)9 JavaCFXTagClass (lucee.runtime.cfx.customtag.JavaCFXTagClass)9 PageException (lucee.runtime.exp.PageException)9 BundleException (org.osgi.framework.BundleException)9 IOException (java.io.IOException)8 Map (java.util.Map)8 ClassException (lucee.commons.lang.ClassException)8 SecurityException (lucee.runtime.exp.SecurityException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 MalformedURLException (java.net.MalformedURLException)7 HashMap (java.util.HashMap)7 Entry (java.util.Map.Entry)7 StructImpl (lucee.runtime.type.StructImpl)7