public JsonValue getItem(int index) { JSONValue item = ((JSONArray) jsonValue).get(index); return new JsonValue(item); }
public JSONValue toJSON(Object aPojo) throws MapperException { JSONArray lArray = new JSONArray(); if(! Collection.class.isAssignableFrom(aPojo.getClass())) throw new MapperException("CollectionMapper cannot map: " + aPojo.getClass().getName()); Collection lColl = (Collection) aPojo; for(Object lEl : lColl) { lArray.getValue().add(JSONMapper.toJSON(lEl)); } return lArray; } }
public final JSONArray array( String aStreamName ) throws RecognitionException, TokenStreamException { JSONArray lResult=new JSONArray(); begin = LT(1); match(LBRACK); lResult.setLineCol(begin.getLine(), begin.getColumn()); lResult.setStreamName(aStreamName); lResult.getValue().add(lVal); match(COMMA); lVal=value(aStreamName); lResult.getValue().add(lVal);
public Enumeration(String aName, JSONObject aRule) throws ValidationException { super(aName, aRule); ValidatorUtil.requiresAttribute(aRule, ValidatorUtil.PARAM_VALUES, JSONArray.class); enumValues = ((JSONArray) aRule.get(ValidatorUtil.PARAM_VALUES)).getValue(); }
public String toString() { final StringBuilder lBuf = new StringBuilder(); lBuf.append("JSONArray(").append(getLine()).append(":").append(getCol()).append(")["); for (int i = 0; i < array.size(); i++) { JSONValue jsonValue = array.get(i); lBuf.append(jsonValue.toString()); if(i < array.size() - 1) lBuf.append(", "); } lBuf.append("]"); return lBuf.toString(); }
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 Or(String aName, JSONObject aRule, HashMap<String,Validator> aRuleset) throws ValidationException { super(aName, aRule); ValidatorUtil.requiresAttribute(aRule, ValidatorUtil.PARAM_RULES, JSONArray.class); List<JSONValue> lRules = ((JSONArray) aRule.get(ValidatorUtil.PARAM_RULES)).getValue(); for (JSONValue lRule : lRules) { Validator lValidator = ValidatorUtil.buildValidator(lRule, aRuleset); rules.add(lValidator); } }
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)); } }
public And(String aName, JSONObject aRule, HashMap<String,Validator> aRuleset) throws ValidationException { super(aName, aRule); ValidatorUtil.requiresAttribute(aRule, ValidatorUtil.PARAM_RULES, JSONArray.class); List<JSONValue> lRules = ((JSONArray) aRule.get(ValidatorUtil.PARAM_RULES)).getValue(); for (JSONValue lRule : lRules) { Validator lValidator = ValidatorUtil.buildValidator(lRule, aRuleset); rules.add(lValidator); } }
final JSONArray lElements = new JSONArray(); lElements.getValue().add(JSONMapper.toJSON(lArr[i])); lElements.getValue().add(JSONMapper.toJSON(lArr[i])); lElements.getValue().add(JSONMapper.toJSON(lArr[i])); lElements.getValue().add(JSONMapper.toJSON(lArr[i])); lElements.getValue().add(JSONMapper.toJSON(lArr[i])); lElements.getValue().add(JSONMapper.toJSON(lArr[i])); lElements.getValue().add(JSONMapper.toJSON(lArr[i])); lElements.getValue().add(JSONMapper.toJSON(lArr[i])); lElements.getValue().add(JSONMapper.toJSON(lArrEl));
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); } } } }
final String lComponentName = lComponentAttr.getValue(); final JSONArray lElements = new JSONArray(); aObjectElement.getValue().put(JSONMarshall.RNDR_ATTR_VALUE, lElements); lElements.getValue().add(aMarshall.marshall(lArr[i])); lElements.getValue().add(aMarshall.marshall(lArr[i])); lElements.getValue().add(aMarshall.marshall(lArr[i])); lElements.getValue().add(aMarshall.marshall(lArr[i])); lElements.getValue().add(aMarshall.marshall(lArr[i]));; lElements.getValue().add(aMarshall.marshall(lArr[i])); lElements.getValue().add(aMarshall.marshall(lArr[i])); lElements.getValue().add(aMarshall.marshall(lArr[i]));; lElements.getValue().add(aMarshall.marshallImpl(lArrEl, aPool));
for (JSONValue jsonValue : lValues.getValue())
for (JSONValue jsonValue : lValues.getValue())
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); } } }
for(JSONValue lVal : lArray.getValue())
for(JSONValue lKeyValue : lArray.getValue())
public Let(String aName, JSONObject aRule, HashMap<String,Validator> aRuleset) throws ValidationException { super(aName, aRule); ruleset = aRuleset; ValidatorUtil.requiresAttribute(aRule, ValidatorUtil.PARAM_RULES, JSONArray.class); List<JSONValue> lRules = ((JSONArray) aRule.get(ValidatorUtil.PARAM_RULES)).getValue(); for (JSONValue lRule : lRules) { JSONValue lVal = lRule; ValidatorUtil.buildValidator(lVal, ruleset); } ValidatorUtil.requiresAttribute(aRule, ValidatorUtil.PARAM_REF, JSONString.class); ref = ((JSONString) aRule.get(ValidatorUtil.PARAM_REF)).getValue(); }