Search in sources :

Example 6 with ArrayImpl

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

the class _GetElement method toStruct.

@Override
public Object toStruct() {
    Resource[] locs = getCfcLocations();
    Array arrLocs = new ArrayImpl();
    if (locs != null)
        for (int i = 0; i < locs.length; i++) {
            arrLocs.appendEL(getAbsolutePath(locs[i]));
        }
    Struct sct = new StructImpl();
    sct.setEL(AUTO_GEN_MAP, this.autogenmap());
    sct.setEL(CATALOG, StringUtil.emptyIfNull(getCatalog()));
    sct.setEL(CFC_LOCATION, arrLocs);
    sct.setEL(IS_DEFAULT_CFC_LOCATION, isDefaultCfcLocation());
    sct.setEL(DB_CREATE, dbCreateAsString(getDbCreate()));
    sct.setEL(DIALECT, StringUtil.emptyIfNull(getDialect()));
    sct.setEL(EVENT_HANDLING, eventHandling());
    sct.setEL(EVENT_HANDLER, eventHandler());
    sct.setEL(NAMING_STRATEGY, namingStrategy());
    sct.setEL(FLUSH_AT_REQUEST_END, flushAtRequestEnd());
    sct.setEL(LOG_SQL, logSQL());
    sct.setEL(SAVE_MAPPING, saveMapping());
    sct.setEL(SCHEMA, StringUtil.emptyIfNull(getSchema()));
    sct.setEL(SECONDARY_CACHE_ENABLED, secondaryCacheEnabled());
    sct.setEL(SQL_SCRIPT, StringUtil.toStringEmptyIfNull(getSqlScript()));
    sct.setEL(USE_DB_FOR_MAPPING, useDBForMapping());
    sct.setEL(CACHE_CONFIG, getAbsolutePath(getCacheConfig()));
    sct.setEL(CACHE_PROVIDER, StringUtil.emptyIfNull(getCacheProvider()));
    sct.setEL(ORM_CONFIG, getAbsolutePath(getOrmConfig()));
    return sct;
}
Also used : Array(lucee.runtime.type.Array) StructImpl(lucee.runtime.type.StructImpl) ArrayImpl(lucee.runtime.type.ArrayImpl) Resource(lucee.commons.io.res.Resource) Struct(lucee.runtime.type.Struct)

Example 7 with ArrayImpl

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

the class SoftMethodStorage method storeMethod.

/**
 * stores a single method
 * @param method
 * @param methodsMap
 */
private void storeMethod(Method method, Map<Key, Array> methodsMap) {
    Key methodName = KeyImpl.init(method.getName());
    Array methodArgs;
    synchronized (methodsMap) {
        methodArgs = methodsMap.get(methodName);
        if (methodArgs == null) {
            methodArgs = new ArrayImpl();
            methodsMap.put(methodName, methodArgs);
        }
    }
    storeArgs(method, methodArgs);
// Modifier.isStatic(method.getModifiers());
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) Key(lucee.runtime.type.Collection.Key)

Example 8 with ArrayImpl

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

the class Perl5Util method match.

public static Array match(String strPattern, String strInput, int offset, boolean caseSensitive) throws MalformedPatternException {
    Perl5Matcher matcher = new Perl5Matcher();
    PatternMatcherInput input = new PatternMatcherInput(strInput);
    int compileOptions = caseSensitive ? 0 : Perl5Compiler.CASE_INSENSITIVE_MASK;
    compileOptions += Perl5Compiler.MULTILINE_MASK;
    if (offset < 1)
        offset = 1;
    Pattern pattern = getPattern(strPattern, compileOptions);
    Array rtn = new ArrayImpl();
    MatchResult result;
    while (matcher.contains(input, pattern)) {
        result = matcher.getMatch();
        rtn.appendEL(result.toString());
    }
    return rtn;
}
Also used : Array(lucee.runtime.type.Array) Pattern(org.apache.oro.text.regex.Pattern) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) ArrayImpl(lucee.runtime.type.ArrayImpl) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 9 with ArrayImpl

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

the class Caster method toArray.

/**
 * cast a Object to a Array Object
 * @param o Object to cast
 * @return casted Array
 * @throws PageException
 */
public static Array toArray(Object o) throws PageException {
    if (o instanceof Array)
        return (Array) o;
    else if (o instanceof Object[]) {
        return new ArrayImpl((Object[]) o);
    } else if (o instanceof List) {
        // new ArrayImpl(((List) o).toArray());
        return ListAsArray.toArray((List) o);
    } else if (o instanceof Set) {
        // new ArrayImpl(((List) o).toArray());
        return toArray(((Set) o).toArray());
    } else if (o instanceof XMLStruct) {
        XMLMultiElementStruct xmes;
        if (o instanceof XMLMultiElementStruct) {
            xmes = (XMLMultiElementStruct) o;
        } else {
            XMLStruct sct = (XMLStruct) o;
            Array a = new ArrayImpl();
            a.append(o);
            xmes = new XMLMultiElementStruct(a, sct.getCaseSensitive());
        }
        return new XMLMultiElementArray(xmes);
    } else if (o instanceof ObjectWrap) {
        return toArray(((ObjectWrap) o).getEmbededObject());
    } else if (o instanceof Struct) {
        // function _toArray
        if (o instanceof Component) {
            Component c = (Component) o;
            PageContext pc = ThreadLocalPageContext.get();
            if (pc != null) {
                Member member = c.getMember(Component.ACCESS_PRIVATE, KeyConstants.__toArray, false, false);
                // Object o = get(pc,"_toString",null);
                if (member instanceof UDFPlus) {
                    UDFPlus udf = (UDFPlus) member;
                    if (udf.getReturnType() == CFTypes.TYPE_ARRAY && udf.getFunctionArguments().length == 0) {
                        return Caster.toArray(c.call(pc, KeyConstants.__toArray, new Object[0]));
                    }
                }
            }
        }
        Struct sct = (Struct) o;
        Array arr = new ArrayImpl();
        Iterator<Entry<Key, Object>> it = sct.entryIterator();
        Entry<Key, Object> e = null;
        try {
            while (it.hasNext()) {
                e = it.next();
                arr.setE(toIntValue(e.getKey().getString()), e.getValue());
            }
        } catch (ExpressionException ee) {
            throw new ExpressionException("can't cast struct to a array, key [" + e.getKey().getString() + "] is not a number");
        }
        return arr;
    } else if (o instanceof boolean[])
        return new ArrayImpl(ArrayUtil.toReferenceType((boolean[]) o));
    else if (o instanceof byte[])
        return new ArrayImpl(ArrayUtil.toReferenceType((byte[]) o));
    else if (o instanceof char[])
        return new ArrayImpl(ArrayUtil.toReferenceType((char[]) o));
    else if (o instanceof short[])
        return new ArrayImpl(ArrayUtil.toReferenceType((short[]) o));
    else if (o instanceof int[])
        return new ArrayImpl(ArrayUtil.toReferenceType((int[]) o));
    else if (o instanceof long[])
        return new ArrayImpl(ArrayUtil.toReferenceType((long[]) o));
    else if (o instanceof float[])
        return new ArrayImpl(ArrayUtil.toReferenceType((float[]) o));
    else if (o instanceof double[])
        return new ArrayImpl(ArrayUtil.toReferenceType((double[]) o));
    throw new CasterException(o, "Array");
}
Also used : ResultSet(java.sql.ResultSet) Set(java.util.Set) ArrayImpl(lucee.runtime.type.ArrayImpl) ExpressionException(lucee.runtime.exp.ExpressionException) XMLMultiElementStruct(lucee.runtime.text.xml.struct.XMLMultiElementStruct) XMLStruct(lucee.runtime.text.xml.struct.XMLStruct) ObjectStruct(lucee.runtime.type.scope.ObjectStruct) MapAsStruct(lucee.runtime.type.wrap.MapAsStruct) Struct(lucee.runtime.type.Struct) CollectionStruct(lucee.runtime.type.CollectionStruct) Entry(java.util.Map.Entry) XMLMultiElementStruct(lucee.runtime.text.xml.struct.XMLMultiElementStruct) ArrayList(java.util.ArrayList) ArrayAsList(lucee.runtime.type.wrap.ArrayAsList) List(java.util.List) NodeList(org.w3c.dom.NodeList) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) Component(lucee.runtime.Component) Member(lucee.runtime.component.Member) CasterException(lucee.runtime.exp.CasterException) ObjectWrap(lucee.runtime.type.ObjectWrap) XMLMultiElementArray(lucee.runtime.text.xml.struct.XMLMultiElementArray) UDFPlus(lucee.runtime.type.UDFPlus) Array(lucee.runtime.type.Array) XMLMultiElementArray(lucee.runtime.text.xml.struct.XMLMultiElementArray) ListAsArray(lucee.runtime.type.wrap.ListAsArray) XMLStruct(lucee.runtime.text.xml.struct.XMLStruct) JavaObject(lucee.runtime.java.JavaObject) Key(lucee.runtime.type.Collection.Key)

Example 10 with ArrayImpl

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

the class Caster method _castTo.

private static Object _castTo(PageContext pc, String strType, Object o) throws PageException {
    if (o instanceof Component) {
        Component comp = ((Component) o);
        if (comp.instanceOf(strType))
            return o;
        throw new ExpressionException("can't cast Component of Type [" + comp.getAbsName() + "] to [" + strType + "]");
    }
    if (o instanceof Pojo) {
        Component cfc = AxisCaster.toComponent(pc, ((Pojo) o), strType, null);
        if (cfc != null)
            return cfc;
        throw new ExpressionException("can't cast Pojo of Type [" + o.getClass().getName() + "] to [" + strType + "]");
    }
    if (strType.endsWith("[]") && Decision.isArray(o)) {
        String _strType = strType.substring(0, strType.length() - 2);
        short _type = CFTypes.toShort(_strType, false, (short) -1);
        Array arr = Caster.toArray(o, null);
        if (arr != null) {
            // convert the values
            Iterator<Entry<Key, Object>> it = arr.entryIterator();
            Array _arr = new ArrayImpl();
            Entry<Key, Object> e;
            Object src, trg;
            boolean hasChanged = false;
            while (it.hasNext()) {
                e = it.next();
                src = e.getValue();
                trg = castTo(pc, _type, _strType, src);
                _arr.setEL(e.getKey(), trg);
                if (src != trg)
                    hasChanged = true;
            }
            if (!hasChanged)
                return arr;
            return _arr;
        }
    }
    throw new CasterException(o, strType);
}
Also used : Pojo(lucee.runtime.net.rpc.Pojo) CasterException(lucee.runtime.exp.CasterException) ArrayImpl(lucee.runtime.type.ArrayImpl) ExpressionException(lucee.runtime.exp.ExpressionException) Array(lucee.runtime.type.Array) XMLMultiElementArray(lucee.runtime.text.xml.struct.XMLMultiElementArray) ListAsArray(lucee.runtime.type.wrap.ListAsArray) Entry(java.util.Map.Entry) JavaObject(lucee.runtime.java.JavaObject) Component(lucee.runtime.Component) Key(lucee.runtime.type.Collection.Key)

Aggregations

ArrayImpl (lucee.runtime.type.ArrayImpl)100 Array (lucee.runtime.type.Array)79 Struct (lucee.runtime.type.Struct)33 StructImpl (lucee.runtime.type.StructImpl)24 PageException (lucee.runtime.exp.PageException)14 Entry (java.util.Map.Entry)13 Key (lucee.runtime.type.Collection.Key)12 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 ArrayList (java.util.ArrayList)6 ListIterator (java.util.ListIterator)6 FunctionException (lucee.runtime.exp.FunctionException)6 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)6 ApplicationException (lucee.runtime.exp.ApplicationException)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 Query (lucee.runtime.type.Query)5 QueryImpl (lucee.runtime.type.QueryImpl)5 ListAsArray (lucee.runtime.type.wrap.ListAsArray)5 NodeList (org.w3c.dom.NodeList)5