Search in sources :

Example 1 with IGxJSONAble

use of com.genexus.internet.IGxJSONAble in project JavaClasses by genexuslabs.

the class GXWebRow method AddColumnProperties.

public void AddColumnProperties(int valueIndex, boolean valueWithProps, Object[] props) {
    Iterator it = this.initializePptyIterator();
    // ColProps Reversed
    JSONArray colPropsRev = new JSONArray();
    Object value = "";
    JSONArray colProps = new JSONArray();
    boolean equal = it != null && !((HttpContext) context.getHttpContext()).isAjaxCallMode();
    Object current = null;
    for (int i = props.length - 1; i >= 0; i--) {
        Object prop = props[i];
        if (IGxJSONAble.class.isAssignableFrom(prop.getClass()))
            prop = ((IGxJSONAble) prop).GetJSONObject();
        if (i != valueIndex) {
            equal = equal && it.hasNext();
            if (equal)
                current = it.next();
            if (!(equal && (current.equals(prop)))) {
                equal = false;
                try {
                    colProps.putIndex(0, prop);
                } catch (JSONException e) {
                }
                if (it == null)
                    colPropsRev.put(prop);
            }
        } else if (valueWithProps)
            value = prop;
        else {
            CommonUtil.strReplace(prop.toString(), "'", "\'");
            _Values.put(prop);
        }
    }
    if (// If is the first Row.
    this._parentGrid != null && it == null) {
        this._parentGrid.GetColsPropsCommon().add(colPropsRev);
    }
    if (valueWithProps)
        colProps.put(value);
    else if (valueIndex < 0)
        _Values.put("");
    _Columns.put(colProps);
    _Count++;
}
Also used : IGxJSONAble(com.genexus.internet.IGxJSONAble) Iterator(java.util.Iterator) JSONArray(json.org.json.JSONArray) HttpContext(com.genexus.internet.HttpContext) JSONException(json.org.json.JSONException) JSONObject(json.org.json.JSONObject)

Example 2 with IGxJSONAble

use of com.genexus.internet.IGxJSONAble in project JavaClasses by genexuslabs.

the class GXBaseCollection method FromJSONObject.

@Override
@SuppressWarnings("unchecked")
public void FromJSONObject(IJsonFormattable obj) {
    this.clear();
    JSONArray jsonArr = (JSONArray) obj;
    for (int i = 0; i < jsonArr.length(); i++) {
        try {
            Object jsonObj = jsonArr.get(i);
            Class[] parTypes = new Class[] {};
            Object[] arglist = new Object[] {};
            if (elementsType == null) {
                add((T) jsonObj);
            } else {
                Object currObj = jsonObj;
                if (elementsType.getSuperclass().getName().equals("com.genexus.GxSilentTrnSdt")) {
                    parTypes = new Class[] { int.class };
                    arglist = new Object[] { Integer.valueOf(remoteHandle) };
                }
                if (IGxJSONAble.class.isAssignableFrom(elementsType)) {
                    Constructor<T> constructor = elementsType.getConstructor(parTypes);
                    currObj = constructor.newInstance(arglist);
                    ((IGxJSONAble) currObj).FromJSONObject((IJsonFormattable) jsonObj);
                }
                add((T) currObj);
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    }
}
Also used : IGxJSONAble(com.genexus.internet.IGxJSONAble) JSONArray(json.org.json.JSONArray) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with IGxJSONAble

use of com.genexus.internet.IGxJSONAble in project JavaClasses by genexuslabs.

the class GXSimpleCollection method FromJSONObject.

public void FromJSONObject(IJsonFormattable obj) {
    this.clear();
    JSONArray jsonArr = (JSONArray) obj;
    for (int i = 0; i < jsonArr.length(); i++) {
        try {
            Object jsonObj = jsonArr.get(i);
            Object currObj = jsonObj;
            Class[] parTypes = new Class[] {};
            Object[] arglist = new Object[] {};
            if (elementsType == null) {
                addObject(currObj);
            } else {
                if (elementsType.getSuperclass().getName().equals("com.genexus.GxSilentTrnSdt")) {
                    parTypes = new Class[] { int.class };
                    arglist = new Object[] { new Integer(remoteHandle) };
                }
                if (IGxJSONAble.class.isAssignableFrom(elementsType)) {
                    Constructor constructor = elementsType.getConstructor(parTypes);
                    currObj = constructor.newInstance(arglist);
                    ((IGxJSONAble) currObj).FromJSONObject((IJsonFormattable) jsonObj);
                }
                if (IGxJSONSerializable.class.isAssignableFrom(elementsType)) {
                    Constructor constructor = elementsType.getConstructor(parTypes);
                    currObj = constructor.newInstance(arglist);
                    ((IGxJSONSerializable) currObj).fromJSonString(jsonObj.toString());
                }
                if (elementsType == Integer.class) {
                    currObj = new Integer(jsonArr.getInt(i));
                } else if (elementsType == Short.class) {
                    currObj = new Short((short) jsonArr.getInt(i));
                } else if (elementsType == Boolean.class) {
                    currObj = new Boolean(jsonArr.getBoolean(i));
                } else if (elementsType == Double.class) {
                    currObj = new Double(jsonArr.getDouble(i));
                } else if (elementsType == java.math.BigDecimal.class) {
                    currObj = java.math.BigDecimal.valueOf(jsonArr.getDouble(i));
                } else if (elementsType == Long.class) {
                    currObj = new Long(jsonArr.getLong(i));
                } else if (elementsType == Date.class) {
                    currObj = SpecificImplementation.GXutil.charToTimeREST(jsonArr.getString(i));
                } else if (elementsType == java.util.UUID.class) {
                    currObj = CommonUtil.strToGuid(jsonArr.getString(i));
                } else if (elementsType == String.class && currObj instanceof Number) {
                    currObj = new String().valueOf(currObj);
                }
                addObject(currObj);
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    }
}
Also used : IGxJSONAble(com.genexus.internet.IGxJSONAble) Constructor(java.lang.reflect.Constructor) JSONArray(json.org.json.JSONArray) JSONException(json.org.json.JSONException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IGxJSONSerializable(com.genexus.internet.IGxJSONSerializable)

Example 4 with IGxJSONAble

use of com.genexus.internet.IGxJSONAble in project JavaClasses by genexuslabs.

the class GXXMLSerializable method FromJSONObject.

public void FromJSONObject(IJsonFormattable obj) {
    String className = CommonUtil.classNameNoPackage(this.getClass());
    String name;
    String map;
    Method setMethod;
    Method getMethod;
    Class<?> setClass;
    GXSimpleCollection currColl;
    if (isArrayObject) {
        map = getJsonMap(arrayItemName);
        setMethod = getMethod(SET_METHOD_NAME + className + "_" + (map != null ? map : arrayItemName));
        getMethod = getMethod(GET_METHOD_NAME + className + "_" + (map != null ? map : arrayItemName));
        if ((setMethod != null) && (getMethod != null)) {
            setClass = setMethod.getParameterTypes()[0];
            try {
                if (GXSimpleCollection.class.isAssignableFrom(setClass)) {
                    currColl = (GXSimpleCollection) getMethod.invoke(this, new Object[] {});
                    currColl.clearCollection();
                    collectionFromJSONArray((JSONArray) obj, currColl);
                    setMethod.invoke(this, new Object[] { currColl });
                }
            } catch (java.lang.ClassCastException ex) {
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    } else {
        Iterator it = getFromJSONObjectOrderIterator(((JSONObject) obj).keys());
        while (it.hasNext()) {
            name = (String) it.next();
            map = getJsonMap(name);
            setMethod = getMethod(SET_METHOD_NAME + className + "_" + (map != null ? map : name));
            getMethod = getMethod(GET_METHOD_NAME + className + "_" + (map != null ? map : name));
            if ((setMethod != null) && (getMethod != null)) {
                setClass = setMethod.getParameterTypes()[0];
                try {
                    Object currObj = ((JSONObject) obj).get(name);
                    if (GXSimpleCollection.class.isAssignableFrom(setClass)) {
                        currColl = (GXSimpleCollection) getMethod.invoke(this, new Object[] {});
                        currColl.clearCollection();
                        if (currObj instanceof JSONArray) {
                            collectionFromJSONArray((JSONArray) currObj, currColl);
                            setMethod.invoke(this, new Object[] { currColl });
                        }
                    } else if (IGxJSONAble.class.isAssignableFrom(setClass)) {
                        IGxJSONAble innerObj = (IGxJSONAble) setClass.getConstructor(new Class[] { SpecificImplementation.Application.getModelContextClass() }).newInstance(new Object[] { context });
                        innerObj.FromJSONObject((JSONObject) currObj);
                        setMethod.invoke(this, new Object[] { innerObj });
                    } else {
                        if (getMethod.getName().startsWith("getgxTv_") && getMethod.isAnnotationPresent(GxUpload.class) && !((JSONObject) obj).has(name + "_GXI") && currObj != null) {
                            if (currObj.getClass().equals(String.class) && ((String) currObj).startsWith(com.genexus.CommonUtil.FORMDATA_REFERENCE)) {
                                String varName = ((String) currObj).replace(com.genexus.CommonUtil.FORMDATA_REFERENCE, "");
                                Method setMethod_blob = getMethod(SET_METHOD_NAME + className + "_" + name + "_setblob");
                                currObj = context.cgiGet(varName);
                                if (setMethod_blob != null) {
                                    setMethod_blob.invoke(this, new Object[] { currObj, context.cgiGetFileName(varName), context.cgiGetFileType(varName) });
                                }
                            } else if (!currObj.equals("")) {
                                Method setMethod_GXI = getMethod(SET_METHOD_NAME + className + "_" + name + "_gxi");
                                if (setMethod_GXI != null) {
                                    setMethod_GXI.invoke(this, new Object[] { "" });
                                }
                            }
                        }
                        if (setClass != null)
                            setMethod.invoke(this, new Object[] { convertValueToParmType(currObj, setClass) });
                    }
                } catch (java.lang.ClassCastException ex) {
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
}
Also used : IGxJSONAble(com.genexus.internet.IGxJSONAble) Method(java.lang.reflect.Method) Iterator(java.util.Iterator)

Example 5 with IGxJSONAble

use of com.genexus.internet.IGxJSONAble in project JavaClasses by genexuslabs.

the class EnterpriseConnect method getValue.

public void getValue(String parameterName, IGxJSONAble[] value) {
    try {
        IGxJSONAble struct = value[0];
        JCoStructure jStruct = function.getExportParameterList().getStructure(parameterName);
        JSONObject jRow = new JSONObject();
        for (JCoField field : jStruct) {
            if (field.getType() == JCoMetaData.TYPE_NUM || field.getType() == JCoMetaData.TYPE_FLOAT || field.getType() == JCoMetaData.TYPE_BCD) {
                jRow.put(field.getName(), field.getDouble());
            } else {
                jRow.put(field.getName(), field.getString());
            }
        }
        struct.FromJSONObject(jRow);
    } catch (JSONException ex) {
        throw new RuntimeException(ex.toString());
    }
}
Also used : IGxJSONAble(com.genexus.internet.IGxJSONAble) JSONObject(json.org.json.JSONObject) JCoStructure(com.sap.conn.jco.JCoStructure) JSONException(json.org.json.JSONException) JCoField(com.sap.conn.jco.JCoField)

Aggregations

IGxJSONAble (com.genexus.internet.IGxJSONAble)7 JSONException (json.org.json.JSONException)4 JSONArray (json.org.json.JSONArray)3 JSONObject (json.org.json.JSONObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Iterator (java.util.Iterator)2 HttpContext (com.genexus.internet.HttpContext)1 IGxJSONSerializable (com.genexus.internet.IGxJSONSerializable)1 JCoField (com.sap.conn.jco.JCoField)1 JCoStructure (com.sap.conn.jco.JCoStructure)1 JCoTable (com.sap.conn.jco.JCoTable)1 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1