@Test public void test1() throws SecurityException, NoSuchFieldException { Float value = (Float) ConfigurationParameterFactory .getDefaultValue(ConfigurationParameterFactoryTest.class.getDeclaredField("double1")); assertEquals(3.1415, value, 1e-4); Float[] values = (Float[]) ConfigurationParameterFactory .getDefaultValue(ConfigurationParameterFactoryTest.class.getDeclaredField("double2")); assertEquals(1, values.length); assertEquals(3.3333, values[0], 1e-4); IllegalArgumentException iae = null; try { ConfigurationParameterFactory.getDefaultValue(ConfigurationParameterFactoryTest.class .getDeclaredField("double3")); } catch (IllegalArgumentException e) { iae = e; } assertNotNull(iae); }
public static Object getDefaultValue(Field field) { if (isConfigurationParameterField(field)) { org.apache.uima.fit.descriptor.ConfigurationParameter annotation = ReflectionUtil .getAnnotation(field, org.apache.uima.fit.descriptor.ConfigurationParameter.class); String[] stringValue = annotation.defaultValue(); if (stringValue.length == 1 && stringValue[0] .equals(org.apache.uima.fit.descriptor.ConfigurationParameter.NO_DEFAULT_VALUE)) { return null; } String valueType = getConfigurationParameterType(field); boolean isMultiValued = isMultiValued(field); if (!isMultiValued) { if (ConfigurationParameter.TYPE_BOOLEAN.equals(valueType)) { return Boolean.parseBoolean(stringValue[0]); } else if (ConfigurationParameter.TYPE_FLOAT.equals(valueType)) { return Float.parseFloat(stringValue[0]); } else if (ConfigurationParameter.TYPE_INTEGER.equals(valueType)) { return Integer.parseInt(stringValue[0]); } else if (ConfigurationParameter.TYPE_STRING.equals(valueType)) { return stringValue[0]; } throw new UIMA_IllegalArgumentException( UIMA_IllegalArgumentException.METADATA_ATTRIBUTE_TYPE_MISMATCH, new Object[] { valueType, "type" }); } else { if (ConfigurationParameter.TYPE_BOOLEAN.equals(valueType)) { Boolean[] returnValues = new Boolean[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Boolean.parseBoolean(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_FLOAT.equals(valueType)) { Float[] returnValues = new Float[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Float.parseFloat(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_INTEGER.equals(valueType)) { Integer[] returnValues = new Integer[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Integer.parseInt(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_STRING.equals(valueType)) { return stringValue; } throw new UIMA_IllegalArgumentException( UIMA_IllegalArgumentException.METADATA_ATTRIBUTE_TYPE_MISMATCH, new Object[] { valueType, "type" }); } } else { throw new IllegalArgumentException("field is not annotated with annotation of type " + org.apache.uima.fit.descriptor.ConfigurationParameter.class.getName()); } }
ConfigurationParameterFactory { public static Object getDefaultValue(Field field) { if (isConfigurationParameterField(field)) { org.apache.uima.fit.descriptor.ConfigurationParameter annotation = ReflectionUtil .getAnnotation(field, org.apache.uima.fit.descriptor.ConfigurationParameter.class); String[] stringValue = annotation.defaultValue(); if (stringValue.length == 1 && stringValue[0] .equals(org.apache.uima.fit.descriptor.ConfigurationParameter.NO_DEFAULT_VALUE)) { return null; } String valueType = getConfigurationParameterType(field); boolean isMultiValued = isMultiValued(field); if (!isMultiValued) { if (ConfigurationParameter.TYPE_BOOLEAN.equals(valueType)) { return Boolean.parseBoolean(stringValue[0]); } else if (ConfigurationParameter.TYPE_FLOAT.equals(valueType)) { return Float.parseFloat(stringValue[0]); } else if (ConfigurationParameter.TYPE_INTEGER.equals(valueType)) { return Integer.parseInt(stringValue[0]); } else if (ConfigurationParameter.TYPE_STRING.equals(valueType)) { return stringValue[0]; } throw new UIMA_IllegalArgumentException( UIMA_IllegalArgumentException.METADATA_ATTRIBUTE_TYPE_MISMATCH, new Object[] { valueType, "type" }); } else { if (ConfigurationParameter.TYPE_BOOLEAN.equals(valueType)) { Boolean[] returnValues = new Boolean[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Boolean.parseBoolean(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_FLOAT.equals(valueType)) { Float[] returnValues = new Float[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Float.parseFloat(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_INTEGER.equals(valueType)) { Integer[] returnValues = new Integer[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Integer.parseInt(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_STRING.equals(valueType)) { return stringValue; } throw new UIMA_IllegalArgumentException( UIMA_IllegalArgumentException.METADATA_ATTRIBUTE_TYPE_MISMATCH, new Object[] { valueType, "type" }); } } else { throw new IllegalArgumentException("field is not annotated with annotation of type " + org.apache.uima.fit.descriptor.ConfigurationParameter.class.getName()); } } }
ConfigurationParameterFactory { public static Object getDefaultValue(Field field) { if (isConfigurationParameterField(field)) { org.apache.uima.fit.descriptor.ConfigurationParameter annotation = ReflectionUtil .getAnnotation(field, org.apache.uima.fit.descriptor.ConfigurationParameter.class); String[] stringValue = annotation.defaultValue(); if (stringValue.length == 1 && stringValue[0] .equals(org.apache.uima.fit.descriptor.ConfigurationParameter.NO_DEFAULT_VALUE)) { return null; } String valueType = getConfigurationParameterType(field); boolean isMultiValued = isMultiValued(field); if (!isMultiValued) { if (ConfigurationParameter.TYPE_BOOLEAN.equals(valueType)) { return Boolean.parseBoolean(stringValue[0]); } else if (ConfigurationParameter.TYPE_FLOAT.equals(valueType)) { return Float.parseFloat(stringValue[0]); } else if (ConfigurationParameter.TYPE_INTEGER.equals(valueType)) { return Integer.parseInt(stringValue[0]); } else if (ConfigurationParameter.TYPE_STRING.equals(valueType)) { return stringValue[0]; } throw new UIMA_IllegalArgumentException( UIMA_IllegalArgumentException.METADATA_ATTRIBUTE_TYPE_MISMATCH, new Object[] { valueType, "type" }); } else { if (ConfigurationParameter.TYPE_BOOLEAN.equals(valueType)) { Boolean[] returnValues = new Boolean[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Boolean.parseBoolean(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_FLOAT.equals(valueType)) { Float[] returnValues = new Float[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Float.parseFloat(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_INTEGER.equals(valueType)) { Integer[] returnValues = new Integer[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Integer.parseInt(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_STRING.equals(valueType)) { return stringValue; } throw new UIMA_IllegalArgumentException( UIMA_IllegalArgumentException.METADATA_ATTRIBUTE_TYPE_MISMATCH, new Object[] { valueType, "type" }); } } else { throw new IllegalArgumentException("field is not annotated with annotation of type " + org.apache.uima.fit.descriptor.ConfigurationParameter.class.getName()); } } private  ConfigurationParameterFactory(); }
ConfigurationParameterFactory { public static Object getDefaultValue(Field field) { if (isConfigurationParameterField(field)) { org.apache.uima.fit.descriptor.ConfigurationParameter annotation = ReflectionUtil .getAnnotation(field, org.apache.uima.fit.descriptor.ConfigurationParameter.class); String[] stringValue = annotation.defaultValue(); if (stringValue.length == 1 && stringValue[0] .equals(org.apache.uima.fit.descriptor.ConfigurationParameter.NO_DEFAULT_VALUE)) { return null; } String valueType = getConfigurationParameterType(field); boolean isMultiValued = isMultiValued(field); if (!isMultiValued) { if (ConfigurationParameter.TYPE_BOOLEAN.equals(valueType)) { return Boolean.parseBoolean(stringValue[0]); } else if (ConfigurationParameter.TYPE_FLOAT.equals(valueType)) { return Float.parseFloat(stringValue[0]); } else if (ConfigurationParameter.TYPE_INTEGER.equals(valueType)) { return Integer.parseInt(stringValue[0]); } else if (ConfigurationParameter.TYPE_STRING.equals(valueType)) { return stringValue[0]; } throw new UIMA_IllegalArgumentException( UIMA_IllegalArgumentException.METADATA_ATTRIBUTE_TYPE_MISMATCH, new Object[] { valueType, "type" }); } else { if (ConfigurationParameter.TYPE_BOOLEAN.equals(valueType)) { Boolean[] returnValues = new Boolean[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Boolean.parseBoolean(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_FLOAT.equals(valueType)) { Float[] returnValues = new Float[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Float.parseFloat(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_INTEGER.equals(valueType)) { Integer[] returnValues = new Integer[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Integer.parseInt(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_STRING.equals(valueType)) { return stringValue; } throw new UIMA_IllegalArgumentException( UIMA_IllegalArgumentException.METADATA_ATTRIBUTE_TYPE_MISMATCH, new Object[] { valueType, "type" }); } } else { throw new IllegalArgumentException("field is not annotated with annotation of type " + org.apache.uima.fit.descriptor.ConfigurationParameter.class.getName()); } } private  ConfigurationParameterFactory(); static boolean isConfigurationParameterField(Field field); static Object getDefaultValue(Field field); static String getConfigurationParameterName(Field field); static ConfigurationParameter createPrimitiveParameter(Field field); static ConfigurationParameter createPrimitiveParameter(String name,
          Class<?> parameterClass, String parameterDescription, boolean isMandatory); static ConfigurationParameter createPrimitiveParameter(String name, String parameterType,
          String parameterDescription, boolean isMultiValued, boolean isMandatory); static void setParameters(ResourceCreationSpecifier desc,
          Class<?> componentClass, ConfigurationParameter[] configurationParameters,
          Object[] configurationValues); static ConfigurationData createConfigurationData(Object... configurationData); static ConfigurationData createConfigurationData(Class<?> componentClass); static void addConfigurationParameters(ResourceCreationSpecifier specifier,
          Object... configurationData); static void addConfigurationParameters(ResourceCreationSpecifier specifier,
          List<Class<?>> dynamicallyLoadedClasses); static void addConfigurationParameters(ResourceCreationSpecifier specifier,
          Class<?>... dynamicallyLoadedClasses); static void addConfigurationParameter(ResourceCreationSpecifier specifier, String name,
          Object value); static Map<String, Object> getParameterSettings(ResourceSpecifier spec); static void setParameter(ResourceSpecifier aSpec, String name, Object value); static boolean canParameterBeSet(ResourceSpecifier aSpec, String name); }
ConfigurationParameterFactory { public static Object getDefaultValue(Field field) { if (isConfigurationParameterField(field)) { org.apache.uima.fit.descriptor.ConfigurationParameter annotation = ReflectionUtil .getAnnotation(field, org.apache.uima.fit.descriptor.ConfigurationParameter.class); String[] stringValue = annotation.defaultValue(); if (stringValue.length == 1 && stringValue[0] .equals(org.apache.uima.fit.descriptor.ConfigurationParameter.NO_DEFAULT_VALUE)) { return null; } String valueType = getConfigurationParameterType(field); boolean isMultiValued = isMultiValued(field); if (!isMultiValued) { if (ConfigurationParameter.TYPE_BOOLEAN.equals(valueType)) { return Boolean.parseBoolean(stringValue[0]); } else if (ConfigurationParameter.TYPE_FLOAT.equals(valueType)) { return Float.parseFloat(stringValue[0]); } else if (ConfigurationParameter.TYPE_INTEGER.equals(valueType)) { return Integer.parseInt(stringValue[0]); } else if (ConfigurationParameter.TYPE_STRING.equals(valueType)) { return stringValue[0]; } throw new UIMA_IllegalArgumentException( UIMA_IllegalArgumentException.METADATA_ATTRIBUTE_TYPE_MISMATCH, new Object[] { valueType, "type" }); } else { if (ConfigurationParameter.TYPE_BOOLEAN.equals(valueType)) { Boolean[] returnValues = new Boolean[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Boolean.parseBoolean(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_FLOAT.equals(valueType)) { Float[] returnValues = new Float[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Float.parseFloat(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_INTEGER.equals(valueType)) { Integer[] returnValues = new Integer[stringValue.length]; for (int i = 0; i < stringValue.length; i++) { returnValues[i] = Integer.parseInt(stringValue[i]); } return returnValues; } else if (ConfigurationParameter.TYPE_STRING.equals(valueType)) { return stringValue; } throw new UIMA_IllegalArgumentException( UIMA_IllegalArgumentException.METADATA_ATTRIBUTE_TYPE_MISMATCH, new Object[] { valueType, "type" }); } } else { throw new IllegalArgumentException("field is not annotated with annotation of type " + org.apache.uima.fit.descriptor.ConfigurationParameter.class.getName()); } } private  ConfigurationParameterFactory(); static boolean isConfigurationParameterField(Field field); static Object getDefaultValue(Field field); static String getConfigurationParameterName(Field field); static ConfigurationParameter createPrimitiveParameter(Field field); static ConfigurationParameter createPrimitiveParameter(String name,
          Class<?> parameterClass, String parameterDescription, boolean isMandatory); static ConfigurationParameter createPrimitiveParameter(String name, String parameterType,
          String parameterDescription, boolean isMultiValued, boolean isMandatory); static void setParameters(ResourceCreationSpecifier desc,
          Class<?> componentClass, ConfigurationParameter[] configurationParameters,
          Object[] configurationValues); static ConfigurationData createConfigurationData(Object... configurationData); static ConfigurationData createConfigurationData(Class<?> componentClass); static void addConfigurationParameters(ResourceCreationSpecifier specifier,
          Object... configurationData); static void addConfigurationParameters(ResourceCreationSpecifier specifier,
          List<Class<?>> dynamicallyLoadedClasses); static void addConfigurationParameters(ResourceCreationSpecifier specifier,
          Class<?>... dynamicallyLoadedClasses); static void addConfigurationParameter(ResourceCreationSpecifier specifier, String name,
          Object value); static Map<String, Object> getParameterSettings(ResourceSpecifier spec); static void setParameter(ResourceSpecifier aSpec, String name, Object value); static boolean canParameterBeSet(ResourceSpecifier aSpec, String name);  }