Search in sources :

Example 6 with IGxJSONAble

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

the class EnterpriseConnect method setValue.

public void setValue(String parameterName, GXSimpleCollection value, Boolean inOut) {
    JCoTable jTable = function.getTableParameterList().getTable(parameterName);
    Boolean setValues = false;
    try {
        for (int i = 1; i <= value.getItemCount(); i++) {
            IGxJSONAble item = (IGxJSONAble) value.item(i);
            if (item != null) {
                setValues = true;
                JSONObject jObj = (JSONObject) item.GetJSONObject();
                jTable.appendRow();
                jTable.lastRow();
                Iterator<?> keys = jObj.keys();
                while (keys.hasNext()) {
                    String key = (String) keys.next();
                    int jcoType = jTable.getRecordMetaData().getType(key);
                    if (jObj.get(key) instanceof String) {
                        jTable.setValue(key, jObj.getString(key));
                    } else if (jcoType == JCoMetaData.TYPE_NUM || jcoType == JCoMetaData.TYPE_INT) {
                        jTable.setValue(key, jObj.getLong(key));
                    } else if (jcoType == JCoMetaData.TYPE_FLOAT || jcoType == JCoMetaData.TYPE_BCD) {
                        jTable.setValue(key, jObj.getDouble(key));
                    } else if (jcoType == JCoMetaData.TYPE_DATE) {
                        jTable.setValue(key, jObj.getString(key));
                    } else if (jcoType == JCoMetaData.TYPE_INT2 || jcoType == JCoMetaData.TYPE_INT1 || jcoType == JCoMetaData.TYPE_BYTE) {
                        jTable.setValue(key, jObj.getInt(key));
                    } else {
                        System.out.println(key + " Invalid Type " + Integer.toString(jcoType));
                    }
                }
            }
        }
    } catch (JSONException ex) {
        throw new RuntimeException(ex.toString());
    }
    if (setValues) {
        function.getTableParameterList().setActive(parameterName, true);
    } else {
        function.getTableParameterList().setActive(parameterName, inOut);
    }
}
Also used : IGxJSONAble(com.genexus.internet.IGxJSONAble) JSONObject(json.org.json.JSONObject) JCoTable(com.sap.conn.jco.JCoTable) JSONException(json.org.json.JSONException)

Example 7 with IGxJSONAble

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

the class GXXMLSerializable method collectionFromJSONArray.

private void collectionFromJSONArray(JSONArray jsonArray, GXSimpleCollection gxColl) {
    try {
        gxColl.clear();
        for (int i = 0; i < jsonArray.length(); i++) {
            Object currObj = jsonArray.get(i);
            if (currObj instanceof JSONObject || !gxColl.IsSimpleCollection()) {
                Class<?> innerClass = gxColl.getElementsType();
                IGxJSONAble innerObj;
                if (GxSilentTrnSdt.class.isAssignableFrom(innerClass)) {
                    innerObj = (IGxJSONAble) innerClass.getConstructor(new Class[] { int.class }).newInstance(new Object[] { new Integer(-1) });
                } else {
                    innerObj = (IGxJSONAble) innerClass.getConstructor(new Class[] { SpecificImplementation.Application.getModelContextClass() }).newInstance(new Object[] { context });
                }
                innerObj.FromJSONObject((IJsonFormattable) currObj);
                gxColl.addBase(innerObj);
            } else {
                gxColl.addBase(currObj);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : IGxJSONAble(com.genexus.internet.IGxJSONAble)

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