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++;
}
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();
}
}
}
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();
}
}
}
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();
}
}
}
}
}
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());
}
}
Aggregations