@Test public void testEnumDefaultValue() { try { AnalysisEngine aed = AnalysisEngineFactory.createEngine(DefaultEnumValueAE.class, (Object[]) null); DefaultEnumValueAE ae = new DefaultEnumValueAE(); ae.initialize(aed.getUimaContext()); assertEquals(Color.GREEN, ae.color); } catch (Exception e) { e.printStackTrace(); } }
public static void initialize(final Object component, final UimaContext context) throws ResourceInitializationException { MutablePropertyValues values = new MutablePropertyValues(); List<String> mandatoryValues = new ArrayList<>(); for (Field field : getFields(component)) { if (isConfigurationParameterField(field)) { org.apache.uima.fit.descriptor.ConfigurationParameter annotation = getAnnotation(field, org.apache.uima.fit.descriptor.ConfigurationParameter.class); Object parameterValue; String parameterName = getConfigurationParameterName(field); parameterValue = context.getConfigParameterValue(parameterName); if (parameterValue == null) { parameterValue = getDefaultValue(field); } if (parameterValue != null) { values.addPropertyValue(field.getName(), parameterValue); } if (annotation.mandatory()) { mandatoryValues.add(field.getName()); } } } DataBinder binder = new DataBinder(component) { @Override protected void checkRequiredFields(MutablePropertyValues mpvs) { String[] requiredFields = getRequiredFields(); if (!isEmpty(requiredFields)) { Map<String, PropertyValue> propertyValues = new HashMap<>(); PropertyValue[] pvs = mpvs.getPropertyValues(); for (PropertyValue pv : pvs) { propertyValues.put(canonicalPropertyName(pv.getName()), pv); } for (String field : requiredFields) { PropertyValue pv = propertyValues.get(field); boolean empty = (pv == null || pv.getValue() == null); if (empty) { getBindingErrorProcessor().processMissingFieldError(field, getInternalBindingResult()); if (pv != null) { mpvs.removePropertyValue(pv); propertyValues.remove(field); } } } } } }; binder.initDirectFieldAccess(); registerUimaFITEditors(binder); binder.setRequiredFields(mandatoryValues.toArray(new String[mandatoryValues.size()])); binder.bind(values); if (binder.getBindingResult().hasErrors()) { StringBuilder sb = new StringBuilder(); sb.append("Errors initializing [" + component.getClass() + "]"); for (ObjectError error : binder.getBindingResult().getAllErrors()) { if (sb.length() > 0) { sb.append("\n"); } sb.append(error.getDefaultMessage()); } throw new IllegalArgumentException(sb.toString()); } }
ConfigurationParameterInitializer { public static void initialize(final Object component, final UimaContext context) throws ResourceInitializationException { MutablePropertyValues values = new MutablePropertyValues(); List<String> mandatoryValues = new ArrayList<>(); for (Field field : getFields(component)) { if (isConfigurationParameterField(field)) { org.apache.uima.fit.descriptor.ConfigurationParameter annotation = getAnnotation(field, org.apache.uima.fit.descriptor.ConfigurationParameter.class); Object parameterValue; String parameterName = getConfigurationParameterName(field); parameterValue = context.getConfigParameterValue(parameterName); if (parameterValue == null) { parameterValue = getDefaultValue(field); } if (parameterValue != null) { values.addPropertyValue(field.getName(), parameterValue); } if (annotation.mandatory()) { mandatoryValues.add(field.getName()); } } } DataBinder binder = new DataBinder(component) { @Override protected void checkRequiredFields(MutablePropertyValues mpvs) { String[] requiredFields = getRequiredFields(); if (!isEmpty(requiredFields)) { Map<String, PropertyValue> propertyValues = new HashMap<>(); PropertyValue[] pvs = mpvs.getPropertyValues(); for (PropertyValue pv : pvs) { propertyValues.put(canonicalPropertyName(pv.getName()), pv); } for (String field : requiredFields) { PropertyValue pv = propertyValues.get(field); boolean empty = (pv == null || pv.getValue() == null); if (empty) { getBindingErrorProcessor().processMissingFieldError(field, getInternalBindingResult()); if (pv != null) { mpvs.removePropertyValue(pv); propertyValues.remove(field); } } } } } }; binder.initDirectFieldAccess(); registerUimaFITEditors(binder); binder.setRequiredFields(mandatoryValues.toArray(new String[mandatoryValues.size()])); binder.bind(values); if (binder.getBindingResult().hasErrors()) { StringBuilder sb = new StringBuilder(); sb.append("Errors initializing [" + component.getClass() + "]"); for (ObjectError error : binder.getBindingResult().getAllErrors()) { if (sb.length() > 0) { sb.append("\n"); } sb.append(error.getDefaultMessage()); } throw new IllegalArgumentException(sb.toString()); } } }
ConfigurationParameterInitializer { public static void initialize(final Object component, final UimaContext context) throws ResourceInitializationException { MutablePropertyValues values = new MutablePropertyValues(); List<String> mandatoryValues = new ArrayList<>(); for (Field field : getFields(component)) { if (isConfigurationParameterField(field)) { org.apache.uima.fit.descriptor.ConfigurationParameter annotation = getAnnotation(field, org.apache.uima.fit.descriptor.ConfigurationParameter.class); Object parameterValue; String parameterName = getConfigurationParameterName(field); parameterValue = context.getConfigParameterValue(parameterName); if (parameterValue == null) { parameterValue = getDefaultValue(field); } if (parameterValue != null) { values.addPropertyValue(field.getName(), parameterValue); } if (annotation.mandatory()) { mandatoryValues.add(field.getName()); } } } DataBinder binder = new DataBinder(component) { @Override protected void checkRequiredFields(MutablePropertyValues mpvs) { String[] requiredFields = getRequiredFields(); if (!isEmpty(requiredFields)) { Map<String, PropertyValue> propertyValues = new HashMap<>(); PropertyValue[] pvs = mpvs.getPropertyValues(); for (PropertyValue pv : pvs) { propertyValues.put(canonicalPropertyName(pv.getName()), pv); } for (String field : requiredFields) { PropertyValue pv = propertyValues.get(field); boolean empty = (pv == null || pv.getValue() == null); if (empty) { getBindingErrorProcessor().processMissingFieldError(field, getInternalBindingResult()); if (pv != null) { mpvs.removePropertyValue(pv); propertyValues.remove(field); } } } } } }; binder.initDirectFieldAccess(); registerUimaFITEditors(binder); binder.setRequiredFields(mandatoryValues.toArray(new String[mandatoryValues.size()])); binder.bind(values); if (binder.getBindingResult().hasErrors()) { StringBuilder sb = new StringBuilder(); sb.append("Errors initializing [" + component.getClass() + "]"); for (ObjectError error : binder.getBindingResult().getAllErrors()) { if (sb.length() > 0) { sb.append("\n"); } sb.append(error.getDefaultMessage()); } throw new IllegalArgumentException(sb.toString()); } } private  ConfigurationParameterInitializer(); }
ConfigurationParameterInitializer { public static void initialize(final Object component, final UimaContext context) throws ResourceInitializationException { MutablePropertyValues values = new MutablePropertyValues(); List<String> mandatoryValues = new ArrayList<>(); for (Field field : getFields(component)) { if (isConfigurationParameterField(field)) { org.apache.uima.fit.descriptor.ConfigurationParameter annotation = getAnnotation(field, org.apache.uima.fit.descriptor.ConfigurationParameter.class); Object parameterValue; String parameterName = getConfigurationParameterName(field); parameterValue = context.getConfigParameterValue(parameterName); if (parameterValue == null) { parameterValue = getDefaultValue(field); } if (parameterValue != null) { values.addPropertyValue(field.getName(), parameterValue); } if (annotation.mandatory()) { mandatoryValues.add(field.getName()); } } } DataBinder binder = new DataBinder(component) { @Override protected void checkRequiredFields(MutablePropertyValues mpvs) { String[] requiredFields = getRequiredFields(); if (!isEmpty(requiredFields)) { Map<String, PropertyValue> propertyValues = new HashMap<>(); PropertyValue[] pvs = mpvs.getPropertyValues(); for (PropertyValue pv : pvs) { propertyValues.put(canonicalPropertyName(pv.getName()), pv); } for (String field : requiredFields) { PropertyValue pv = propertyValues.get(field); boolean empty = (pv == null || pv.getValue() == null); if (empty) { getBindingErrorProcessor().processMissingFieldError(field, getInternalBindingResult()); if (pv != null) { mpvs.removePropertyValue(pv); propertyValues.remove(field); } } } } } }; binder.initDirectFieldAccess(); registerUimaFITEditors(binder); binder.setRequiredFields(mandatoryValues.toArray(new String[mandatoryValues.size()])); binder.bind(values); if (binder.getBindingResult().hasErrors()) { StringBuilder sb = new StringBuilder(); sb.append("Errors initializing [" + component.getClass() + "]"); for (ObjectError error : binder.getBindingResult().getAllErrors()) { if (sb.length() > 0) { sb.append("\n"); } sb.append(error.getDefaultMessage()); } throw new IllegalArgumentException(sb.toString()); } } private  ConfigurationParameterInitializer(); static void initialize(final Object component, final UimaContext context); static void initialize(final Object component, final Map<String, Object> map); static void initialize(Object component, ResourceSpecifier spec); static void initialize(Object component, Parameter... parameters); static void initialize(Object component, NameValuePair... parameters); static void initialize(Object component, DataResource dataResource); static void initialize(Object component, Object... aParameters); }
ConfigurationParameterInitializer { public static void initialize(final Object component, final UimaContext context) throws ResourceInitializationException { MutablePropertyValues values = new MutablePropertyValues(); List<String> mandatoryValues = new ArrayList<>(); for (Field field : getFields(component)) { if (isConfigurationParameterField(field)) { org.apache.uima.fit.descriptor.ConfigurationParameter annotation = getAnnotation(field, org.apache.uima.fit.descriptor.ConfigurationParameter.class); Object parameterValue; String parameterName = getConfigurationParameterName(field); parameterValue = context.getConfigParameterValue(parameterName); if (parameterValue == null) { parameterValue = getDefaultValue(field); } if (parameterValue != null) { values.addPropertyValue(field.getName(), parameterValue); } if (annotation.mandatory()) { mandatoryValues.add(field.getName()); } } } DataBinder binder = new DataBinder(component) { @Override protected void checkRequiredFields(MutablePropertyValues mpvs) { String[] requiredFields = getRequiredFields(); if (!isEmpty(requiredFields)) { Map<String, PropertyValue> propertyValues = new HashMap<>(); PropertyValue[] pvs = mpvs.getPropertyValues(); for (PropertyValue pv : pvs) { propertyValues.put(canonicalPropertyName(pv.getName()), pv); } for (String field : requiredFields) { PropertyValue pv = propertyValues.get(field); boolean empty = (pv == null || pv.getValue() == null); if (empty) { getBindingErrorProcessor().processMissingFieldError(field, getInternalBindingResult()); if (pv != null) { mpvs.removePropertyValue(pv); propertyValues.remove(field); } } } } } }; binder.initDirectFieldAccess(); registerUimaFITEditors(binder); binder.setRequiredFields(mandatoryValues.toArray(new String[mandatoryValues.size()])); binder.bind(values); if (binder.getBindingResult().hasErrors()) { StringBuilder sb = new StringBuilder(); sb.append("Errors initializing [" + component.getClass() + "]"); for (ObjectError error : binder.getBindingResult().getAllErrors()) { if (sb.length() > 0) { sb.append("\n"); } sb.append(error.getDefaultMessage()); } throw new IllegalArgumentException(sb.toString()); } } private  ConfigurationParameterInitializer(); static void initialize(final Object component, final UimaContext context); static void initialize(final Object component, final Map<String, Object> map); static void initialize(Object component, ResourceSpecifier spec); static void initialize(Object component, Parameter... parameters); static void initialize(Object component, NameValuePair... parameters); static void initialize(Object component, DataResource dataResource); static void initialize(Object component, Object... aParameters);  }