public void renderValue(Object aObj, JSONObject aParent, JSONMarshall aMarshall, HashMap aPool) throws MarshallException { final Color lColor = (Color) aObj; aParent.getValue().put(JSONMarshall.RNDR_ATTR_VALUE, new JSONString("" + lColor.getRGB())); }
public void renderValue(Object aObj, JSONObject aParent, JSONMarshall aMarshall, HashMap aPool) throws MarshallException { aParent.getValue().put(JSONMarshall.RNDR_ATTR_VALUE, new JSONString(aObj.toString())); } }
public void renderValue(Object aObj, JSONObject aObjectElement, JSONMarshall aMarshall, HashMap aPool) throws MarshallException { aObjectElement.getValue().put(JSONMarshall.RNDR_ATTR_VALUE, new JSONString(dateFormat.format((Date) aObj))); }
private JSONObject marshallPrimitive(String aType, String aValue) { final JSONObject lElement = new JSONObject(); lElement.getValue().put(RNDR_ATTR_KIND, new JSONString(RNDR_PRIM)); lElement.getValue().put(RNDR_ATTR_TYPE, new JSONString(aType)); lElement.getValue().put(RNDR_ATTR_VALUE, new JSONString(aValue)); return lElement; }
public void renderValue(Object aObj, JSONObject aParent, JSONMarshall aMarshall, HashMap aPool) throws MarshallException { final Font lFont = (Font) aObj; final int lFontStyle = lFont.getStyle(); String lStyle; switch(lFontStyle) { case Font.PLAIN: lStyle = "PLAIN"; break; case Font.BOLD: lStyle = "BOLD"; break; case Font.ITALIC: lStyle = "ITALIC";break; case 3: lStyle = "BOLDITALIC";break; default: lStyle="PLAIN"; } aParent.getValue().put(JSONMarshall.RNDR_ATTR_VALUE, new JSONString( lFont.getName() + "-"+ lStyle + "-" + lFont.getSize())); }
public JSONValue toJSON(Object aPojo) throws MapperException { final JSONObject lObj = new JSONObject(); if(! Map.class.isAssignableFrom(aPojo.getClass())) throw new MapperException("MapMapper cannot map: " + aPojo.getClass().getName()); Map lMap = (Map) aPojo; for(Object lKey : lMap.keySet()) { lObj.getValue().put(lKey.toString(), JSONMapper.toJSON(lMap.get(lKey))); } return lObj; } }
private JSONObject marshallImplObject(Object aObj, String aObjId, Class aObjClass, String aObjClassName, HashMap aPool) throws MarshallException { final JSONObject lObjElement = new JSONObject(); lObjElement.getValue().put(RNDR_ATTR_KIND, new JSONString(RNDR_OBJ)); lObjElement.getValue().put(RNDR_ATTR_ID, new JSONString(aObjId)); lObjElement.getValue().put(RNDR_ATTR_CLASS, new JSONString(aObjClassName)); final MarshallHelper lHelper = repo.findHelper(aObjClass); lHelper.renderValue(aObj, lObjElement, this, aPool); return lObjElement; }
public void renderValue(Object aObj, JSONObject aObjectElement, JSONMarshall aMarshall, HashMap aPool) throws MarshallException { // We create a new JSON array where we will collect the elements of the // map. We attach this new array as the parent object value. final JSONArray lArray = new JSONArray(); aObjectElement.getValue().put(JSONMarshall.RNDR_ATTR_VALUE, lArray); // We iterate through the keys of the map, render these as // JSON values and put these values in the array created above. final Map lMap = (Map) aObj; final Iterator lIter = lMap.keySet().iterator(); for(Object lKey : lMap.keySet()) { // Get hold of each key-value pair. final Object lValue = lMap.get(lKey); // We create a JSON object to render the key-value pairs. final JSONObject lKeyValuePair = new JSONObject(); lArray.getValue().add(lKeyValuePair); lKeyValuePair.getValue().put(ATTR_KEY, aMarshall.marshallImpl(lKey, aPool)); lKeyValuePair.getValue().put(ATTR_VALUE, aMarshall.marshallImpl(lValue, aPool)); } }
private JSONObject marshallImplArray(Object aObj, HashMap aPool) throws MarshallException { final Class lClass = aObj.getClass(); final String lObjClassName = lClass.getName(); // Construct the component class name. String lComponentClassName = "unknown"; if(lObjClassName.startsWith("[L")) // Array of objects. lComponentClassName = lObjClassName.substring(2, lObjClassName.length() - 1); else // Array of array; Array of primitive types. lComponentClassName = lObjClassName.substring(1); final JSONObject lArrElement = new JSONObject(); lArrElement.getValue().put(RNDR_ATTR_KIND, new JSONString(RNDR_ARR)); lArrElement.getValue().put(RNDR_ATTR_CLASS, new JSONString(lComponentClassName)); final ArrayHelper lAh = new ArrayHelper(); lAh.renderValue(aObj, lArrElement, this, aPool); return lArrElement; }
public void renderValue(Object aObj, JSONObject aObjectElement, JSONMarshall aMarshall, HashMap aPool) throws MarshallException { // We create a new JSON array where we will collect the elements of the // collection. We attach this new array as the parent object value. final JSONArray lArray = new JSONArray(); aObjectElement.getValue().put(JSONMarshall.RNDR_ATTR_VALUE, lArray); // We iterate through the elements of the collection, render these as // JSON values and put these values in the array created above. final Collection lCollection = (Collection) aObj; for(Object lColEl : lCollection) { lArray.getValue().add(aMarshall.marshallImpl(lColEl, aPool)); } }
public void validate(JSONValue aValue) throws ValidationException { Iterator<JSONValue> lIter = null; if(aValue.isArray()) lIter = ((JSONArray) aValue).getValue().iterator(); else if(aValue.isObject()) lIter = ((JSONObject) aValue).getValue().values().iterator(); else fail("The value is not a JSONComplex, it has no content.", aValue); // Finally we apply the internal rule to all elements. if(lIter != null) { while(lIter.hasNext()) { JSONValue lVal = (JSONValue) lIter.next(); rule.validate(lVal); } } } }
lElements.getValue().put(lPropName, JSONMapper.toJSON(lReader.invoke(aPojo)));
public Object parseValue(JSONObject aObjectElement, JSONMarshall aMarshall, HashMap aPool) throws MarshallException final JSONArray lArray = (JSONArray) aObjectElement.getValue().get(JSONMarshall.RNDR_ATTR_VALUE); Object lKey = aMarshall.unmarshallImpl((JSONObject) ((JSONObject) lKeyValue).getValue().get(ATTR_KEY), aPool); Object lValue = aMarshall.unmarshallImpl((JSONObject) ((JSONObject) lKeyValue).getValue().get(ATTR_VALUE), aPool); lMap.put(lKey, lValue);
public void validate(JSONValue aValue) throws ValidationException { int lSize = 0; if(aValue.isArray()) lSize = ((JSONArray) aValue).getValue().size(); else if(aValue.isString()) lSize = ((JSONString) aValue).getValue().length(); else if(aValue.isObject()) lSize = ((JSONObject) aValue).getValue().size(); else fail("The value is not a JSONArray, JSONString or JSONObject.", aValue); // If there are lenght specs, we check them. if(minLength != null) { if(lSize < minLength) fail("The size (" + lSize +") is smaller then allowed (" + minLength + ").", aValue); } if(maxLength != null) { if( lSize > maxLength ) fail("The size (" + lSize +") is larger then allowed (" + maxLength + ").", aValue); } } }
lObj.getValue().put((String) lKey, decorate(((Map)anObject).get(lKey)));
public Object parseValue(JSONObject aObjectElement, JSONMarshall aMarshall, HashMap aPool) throws MarshallException final JSONArray lArray = (JSONArray) aObjectElement.getValue().get(JSONMarshall.RNDR_ATTR_VALUE);
public void validate(JSONValue aValue) throws ValidationException { // Only for objects. if(!aValue.isObject()) fail("The value is not a JSONObject.", aValue); JSONObject lObj = (JSONObject) aValue; // First we check if required keys are there. for(PropRule aRequired : required) { if(!lObj.containsKey(aRequired.getKey())) fail("The object lacks a required key: \"" + aRequired.getKey() + "\".", aValue); } // Now we iterate over all keys in the object and lookup the spec. for(String lKey : lObj.getValue().keySet()) { if(!all.containsKey(lKey)) fail("The object contains an unspecified key: \"" + lKey + "\".", aValue); PropRule lRule = all.get(lKey); try { lRule.getRule().validate(lObj.get(lKey)); } catch(ValidationException e) { fail("The object property: \"" + lKey + "\" has invalid content. Internal message: " + e.getMessage(), aValue); } } } }