src/org/ohmage/domain/campaign/prompt/SingleChoiceCustomPrompt.java
@Override
	public Object validateValue(final Object value) throws DomainException {
		// If it's already a NoResponse value, then make sure that if it
		// was skipped that it is 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;
		}
		else if(value instanceof String) {
			try {
				return NoResponse.valueOf((String) value);
			}
			catch(IllegalArgumentException notNoResponse) {
				Map<Integer, LabelValuePair> choices = getAllChoices();
				
				boolean exists = false;
				for(LabelValuePair vlp : choices.values()) {
					if(vlp.getLabel().equals(value)) {
						exists = true;
						break;
					}
				}
				
				if(! exists) {
					if(choices.isEmpty()) {
						addChoice(0, (String) value, null);
					} 
					else {
						List<Integer> keys = 
								new ArrayList<Integer>(choices.keySet());
						Collections.sort(keys);
						int key = keys.get(keys.size() - 1) + 1;
						addChoice(key, (String) value, null);
					}
				}
				
				return (String) value;
			}
		}
		else {
			throw new DomainException(
					"The value for prompt '" +
						getId() +
						"' is not decodable as a reponse value: " + 
						value);
		}
	}
/**
	 * 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 String} that represents:</li>
	 * 				  <ul>
	 * 				    <li>{@link NoResponse}</li>
	 * 				    <li>The label of the item the user chose.</li>
	 * 				  <ul>
	 * 				</ul>
	 * 
	 * @return A String representing a label 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
 String that represents:

 NoResponse
The label of the item the user chose.



@return A String representing a label 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 String that represents : NoResponse The label of the item the user chose . @return A String representing a label or a NoResponse object . @throws DomainException The value is invalid .
@Override
	public Object validateValue(final Object value) throws DomainException {
		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 String) {
			try {
				return NoResponse.valueOf((String) value);
			}
			catch(IllegalArgumentException notNoResponse) {
				Map<Integer, LabelValuePair> choices = getAllChoices();
				boolean exists = false;
				for(LabelValuePair vlp : choices.values()) {
					if(vlp.getLabel().equals(value)) {
						exists = true;
						break;
					}
				}
				if(! exists) {
					if(choices.isEmpty()) {
						addChoice(0, (String) value, null);
					} 
					else {
						List<Integer> keys = 
								new ArrayList<Integer>(choices.keySet());
						Collections.sort(keys);
						int key = keys.get(keys.size() - 1) + 1;
						addChoice(key, (String) value, null);
					}
				}
				return (String) value;
			}
		}
		else {
			throw new DomainException(
					"The value for prompt '" +
						getId() +
						"' is not decodable as a reponse value: " + 
						value);
		}
	}
@ Override public Object validateValue ( final Object value ) throws DomainException { 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 String ) { try { return NoResponse . valueOf ( ( String ) value ) ; } catch ( IllegalArgumentException notNoResponse ) { Map < Integer , LabelValuePair > choices = getAllChoices ( ) ; boolean exists = false ; for ( LabelValuePair vlp : choices . values ( ) ) { if ( vlp . getLabel ( ) . equals ( value ) ) { exists = true ; break ; } } if ( ! exists ) { if ( choices . isEmpty ( ) ) { addChoice ( 0 , ( String ) value , null ) ; } else { List < Integer > keys = new ArrayList < Integer > ( choices . keySet ( ) ) ; Collections . sort ( keys ) ; int key = keys . get ( keys . size ( ) - 1 ) + 1 ; addChoice ( key , ( String ) value , null ) ; } } return ( String ) value ; } } else { throw new DomainException ( "The value for prompt '" + getId ( ) + "' is not decodable as a reponse value: " + value ) ; } }
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 make sure that if it // was skipped that it is skippable.