View Javadoc

1   package gov.nasa.pds.ltdt.testLabel;
2   
3   import gov.nasa.pds.tools.dict.ElementDefinition;
4   import gov.nasa.pds.tools.dict.type.InvalidTypeException;
5   import gov.nasa.pds.tools.dict.type.Types;
6   import gov.nasa.pds.tools.dict.type.UnsupportedTypeException;
7   
8   
9   /***
10   * This class will generate a test value based on the element definition.
11   * 
12   * 
13   * @author mcayanan
14   *
15   */
16  public class ElementTestValueGenerator implements Types {
17  	
18  	/***
19  	 * Get an appropriate test value based on the element definition.
20  	 * 
21  	 * @param definition The element definition.
22  	 * 
23  	 * @return an appropriate test value. If a standard value list exists in the definition,
24  	 * the first one listed will be returned. Otherwise, we need to generate a test value.
25  	 * 
26  	 * @throws InvalidTypeException
27  	 * @throws UnsupportedTypeException
28  	 */
29  	public static Object getValue(ElementDefinition definition) throws InvalidTypeException, UnsupportedTypeException {
30  		if(definition.hasValidValues()) {
31  			Object validValue = definition.getValues().iterator().next();
32  			return validValue;
33  		}
34  		else {
35  			TestValue value = TestValueFactory.getInstance().newInstance(definition.getDataType());
36  			return value.getTestValue(definition);
37  		}
38  	}
39  }