Search in sources :

Example 1 with QueryBean

use of coldfusion.xml.rpc.QueryBean in project Lucee by lucee.

the class AxisCaster method toLuceeType.

public static Object toLuceeType(PageContext pc, String customType, Object value) throws PageException {
    pc = ThreadLocalPageContext.get(pc);
    if (pc != null && value instanceof Pojo) {
        if (!StringUtil.isEmpty(customType)) {
            Component cfc = toComponent(pc, (Pojo) value, customType, null);
            if (cfc != null)
                return cfc;
        }
    /*
    		// try package/class name as component name
    		String compPath=value.getClass().getName();
    		Component cfc = toComponent(pc, (Pojo)value, compPath, null);
    		if(cfc!=null) return cfc;
    		
    		// try class name as component name
    		compPath=ListUtil.last(compPath, '.');
    		cfc = toComponent(pc, (Pojo)value, compPath, null);
    		if(cfc!=null) return cfc;
    		*/
    }
    if (value instanceof Date || value instanceof Calendar) {
        // do not change to caster.isDate
        return Caster.toDate(value, null);
    }
    if (value instanceof Object[]) {
        Object[] arr = (Object[]) value;
        if (!ArrayUtil.isEmpty(arr)) {
            boolean allTheSame = true;
            // byte
            if (arr[0] instanceof Byte) {
                for (int i = 1; i < arr.length; i++) {
                    if (!(arr[i] instanceof Byte)) {
                        allTheSame = false;
                        break;
                    }
                }
                if (allTheSame) {
                    byte[] bytes = new byte[arr.length];
                    for (int i = 0; i < arr.length; i++) {
                        bytes[i] = Caster.toByteValue(arr[i]);
                    }
                    return bytes;
                }
            }
        }
    }
    if (value instanceof Byte[]) {
        Byte[] arr = (Byte[]) value;
        if (!ArrayUtil.isEmpty(arr)) {
            byte[] bytes = new byte[arr.length];
            for (int i = 0; i < arr.length; i++) {
                bytes[i] = arr[i].byteValue();
            }
            return bytes;
        }
    }
    if (value instanceof byte[]) {
        return value;
    }
    if (Decision.isArray(value)) {
        Array a = Caster.toArray(value);
        int len = a.size();
        Object o;
        String ct;
        for (int i = 1; i <= len; i++) {
            o = a.get(i, null);
            if (o != null) {
                ct = customType != null && customType.endsWith("[]") ? customType.substring(0, customType.length() - 2) : null;
                a.setEL(i, toLuceeType(pc, ct, o));
            }
        }
        return a;
    }
    if (value instanceof Map) {
        Struct sct = new StructImpl();
        Iterator it = ((Map) value).entrySet().iterator();
        Map.Entry entry;
        while (it.hasNext()) {
            entry = (Entry) it.next();
            sct.setEL(Caster.toString(entry.getKey()), toLuceeType(pc, null, entry.getValue()));
        }
        return sct;
    // return StructUtil.copyToStruct((Map)value);
    }
    if (isQueryBean(value)) {
        QueryBean qb = (QueryBean) value;
        String[] strColumns = qb.getColumnList();
        Object[][] data = qb.getData();
        int recorcount = data.length;
        Query qry = new QueryImpl(strColumns, recorcount, "QueryBean");
        QueryColumn[] columns = new QueryColumn[strColumns.length];
        for (int i = 0; i < columns.length; i++) {
            columns[i] = qry.getColumn(strColumns[i]);
        }
        int row;
        for (row = 1; row <= recorcount; row++) {
            for (int i = 0; i < columns.length; i++) {
                columns[i].set(row, toLuceeType(pc, null, data[row - 1][i]));
            }
        }
        return qry;
    }
    if (Decision.isQuery(value)) {
        Query q = Caster.toQuery(value);
        int recorcount = q.getRecordcount();
        String[] strColumns = q.getColumns();
        QueryColumn col;
        int row;
        for (int i = 0; i < strColumns.length; i++) {
            col = q.getColumn(strColumns[i]);
            for (row = 1; row <= recorcount; row++) {
                col.set(row, toLuceeType(pc, null, col.get(row, null)));
            }
        }
        return q;
    }
    return value;
}
Also used : Entry(java.util.Map.Entry) Query(lucee.runtime.type.Query) Struct(lucee.runtime.type.Struct) QueryBean(coldfusion.xml.rpc.QueryBean) QueryImpl(lucee.runtime.type.QueryImpl) Iterator(java.util.Iterator) Component(lucee.runtime.Component) Calendar(java.util.Calendar) Date(java.util.Date) Array(lucee.runtime.type.Array) StructImpl(lucee.runtime.type.StructImpl) QueryColumn(lucee.runtime.type.QueryColumn) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with QueryBean

use of coldfusion.xml.rpc.QueryBean in project Lucee by lucee.

the class AxisCaster method toQueryBean.

private static QueryBean toQueryBean(TypeMapping tm, Object value, Set<Object> done) throws PageException {
    Query query = Caster.toQuery(value);
    int recordcount = query.getRecordcount();
    String[] columnList = query.getColumns();
    QueryColumn[] columns = new QueryColumn[columnList.length];
    Object[][] data = new Object[recordcount][columnList.length];
    for (int i = 0; i < columnList.length; i++) {
        columns[i] = query.getColumn(columnList[i]);
    }
    int row;
    for (row = 1; row <= recordcount; row++) {
        for (int i = 0; i < columns.length; i++) {
            data[row - 1][i] = _toAxisType(tm, null, null, null, null, columns[i].get(row, null), done);
        }
    }
    QueryBean qb = new QueryBean();
    qb.setColumnList(columnList);
    qb.setData(data);
    return qb;
}
Also used : Query(lucee.runtime.type.Query) QueryColumn(lucee.runtime.type.QueryColumn) QueryBean(coldfusion.xml.rpc.QueryBean)

Aggregations

QueryBean (coldfusion.xml.rpc.QueryBean)2 Query (lucee.runtime.type.Query)2 QueryColumn (lucee.runtime.type.QueryColumn)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Component (lucee.runtime.Component)1 Array (lucee.runtime.type.Array)1 QueryImpl (lucee.runtime.type.QueryImpl)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1