src/org/ohmage/domain/campaign/prompt/RemoteActivityPrompt.java
@Override
	public Object validateValue(final Object value) throws DomainException {
		JSONArray valueJson;
		
		// If it's already a NoResponse value, then return make sure that if it
		// was skipped that it as skippable.
		if(value instanceof NoResponse) {
			if(NoResponse.SKIPPED.equals(value) && (! skippable())) {
				throw new DomainException(
						"The prompt, '" +
							getId() +
							"', was skipped, but it is not skippable.");
			}
			
			return value;
		}
		// If it's already a JSONObject value, then set that to be validated.
		else if(value instanceof JSONArray) {
			valueJson = (JSONArray) value;
		}
		// If it's a JSON
		// If it is a string, parse it to check if it's a NoResponse value and,
		// if not, parse it as a JSONObject to be validated.
		else if(value instanceof String) {
			String valueString = (String) value;
			
			try {
				return NoResponse.valueOf(valueString);
			}
			catch(IllegalArgumentException iae) {
				try {
					valueJson = new JSONArray((String) valueString);
				}
				catch(JSONException e) {
					throw new DomainException(
							"The string value could not be decoded as a NoResponse or JSONObject object for prompt '" +
								getId() +
								"': " +
								valueString);
				}
			}
		}
		// Finally, if its type is unknown, throw an exception.
		else {
			throw new DomainException(
					"The value is not decodable as a response value for prompt '" +
						getId() +
						"'.");
		}
		
		int numResponses = valueJson.length();
		for(int i = 0; i < numResponses; i++) {
			JSONObject currResponse;
			try {
				currResponse = valueJson.getJSONObject(i);
			}
			catch(JSONException e) {
				throw new DomainException(
						"The item at index '" +
							i +
							"' isn't a valid JSONObject for prompt '" +
							getId() +
							"'.",
						e);
			}
			
			try {
				currResponse.getDouble(JSON_KEY_SCORE);
			}
			catch(JSONException e) {
				throw new DomainException(
						"The JSON response value must contain the key '" +
							JSON_KEY_SCORE +
							"' which must be a numeric value for prompt '" +
							getId() +
							"'.",
						e);
			}
		}
		
		return valueJson;
	}
/**
	 * Validates that a given value is valid and, if so, converts it into an
	 * appropriate object.
	 * 
	 * @param value The value to be validated. This must be one of the  
	 * 				following:<br />
	 * 				<ul>
	 * 				<li>{@link NoResponse}</li>
	 * 				<li>{@link JSONArray}</li>
	 * 				<li>{@link String} that represents:</li>
	 * 				  <ul>
	 * 				    <li>{@link NoResponse}</li>
	 * 				    <li>A JSONArray.</li>
	 * 				  <ul>
	 * 				</ul>
	 * 
	 * @return A JSONArray object or a {@link NoResponse} object.
	 * 
	 * @throws DomainException The value is invalid.
	 */
Validates that a given value is valid and, if so, converts it into an
appropriate object.

@param value The value to be validated. This must be one of the
following:

 NoResponse
 JSONArray
 String that represents:

 NoResponse
A JSONArray.



@return A JSONArray object or a  NoResponse object.

@throws DomainException The value is invalid.
Validates that a given value is valid and if so converts it into an appropriate object . @param value The value to be validated . This must be one of the following : NoResponse JSONArray String that represents : NoResponse A JSONArray . @return A JSONArray object or a NoResponse object . @throws DomainException The value is invalid .
@Override
	public Object validateValue(final Object value) throws DomainException {
		JSONArray valueJson;
		if(value instanceof NoResponse) {
			if(NoResponse.SKIPPED.equals(value) && (! skippable())) {
				throw new DomainException(
						"The prompt, '" +
							getId() +
							"', was skipped, but it is not skippable.");
			}
			return value;
		}
		else if(value instanceof JSONArray) {
			valueJson = (JSONArray) value;
		}
		else if(value instanceof String) {
			String valueString = (String) value;
			try {
				return NoResponse.valueOf(valueString);
			}
			catch(IllegalArgumentException iae) {
				try {
					valueJson = new JSONArray((String) valueString);
				}
				catch(JSONException e) {
					throw new DomainException(
							"The string value could not be decoded as a NoResponse or JSONObject object for prompt '" +
								getId() +
								"': " +
								valueString);
				}
			}
		}
		else {
			throw new DomainException(
					"The value is not decodable as a response value for prompt '" +
						getId() +
						"'.");
		}
		int numResponses = valueJson.length();
		for(int i = 0; i < numResponses; i++) {
			JSONObject currResponse;
			try {
				currResponse = valueJson.getJSONObject(i);
			}
			catch(JSONException e) {
				throw new DomainException(
						"The item at index '" +
							i +
							"' isn't a valid JSONObject for prompt '" +
							getId() +
							"'.",
						e);
			}
			try {
				currResponse.getDouble(JSON_KEY_SCORE);
			}
			catch(JSONException e) {
				throw new DomainException(
						"The JSON response value must contain the key '" +
							JSON_KEY_SCORE +
							"' which must be a numeric value for prompt '" +
							getId() +
							"'.",
						e);
			}
		}
		return valueJson;
	}
@ Override public Object validateValue ( final Object value ) throws DomainException { JSONArray valueJson ; if ( value instanceof NoResponse ) { if ( NoResponse . SKIPPED . equals ( value ) && ( ! skippable ( ) ) ) { throw new DomainException ( "The prompt, '" + getId ( ) + "', was skipped, but it is not skippable." ) ; } return value ; } else if ( value instanceof JSONArray ) { valueJson = ( JSONArray ) value ; } else if ( value instanceof String ) { String valueString = ( String ) value ; try { return NoResponse . valueOf ( valueString ) ; } catch ( IllegalArgumentException iae ) { try { valueJson = new JSONArray ( ( String ) valueString ) ; } catch ( JSONException e ) { throw new DomainException ( "The string value could not be decoded as a NoResponse or JSONObject object for prompt '" + getId ( ) + "': " + valueString ) ; } } } else { throw new DomainException ( "The value is not decodable as a response value for prompt '" + getId ( ) + "'." ) ; } int numResponses = valueJson . length ( ) ; for ( int i = 0 ; i < numResponses ; i ++ ) { JSONObject currResponse ; try { currResponse = valueJson . getJSONObject ( i ) ; } catch ( JSONException e ) { throw new DomainException ( "The item at index '" + i + "' isn't a valid JSONObject for prompt '" + getId ( ) + "'." , e ) ; } try { currResponse . getDouble ( JSON_KEY_SCORE ) ; } catch ( JSONException e ) { throw new DomainException ( "The JSON response value must contain the key '" + JSON_KEY_SCORE + "' which must be a numeric value for prompt '" + getId ( ) + "'." , e ) ; } } return valueJson ; }
Validates that a given value is valid and, if so, converts it into an
 appropriate object.
Validates that a given value is valid and if so converts it into an appropriate object .
// If it's already a NoResponse value, then return make sure that if it // was skipped that it as skippable. // If it's already a JSONObject value, then set that to be validated. // If it's a JSON // If it is a string, parse it to check if it's a NoResponse value and, // if not, parse it as a JSONObject to be validated. // Finally, if its type is unknown, throw an exception.