/** * Build an AttributeConverterDefinition from the AttributeConverter instance and * whether or not to auto-apply it. * * @param attributeConverter The AttributeConverter instance * @param autoApply Should the AttributeConverter be auto-applied? * * @return The constructed definition */ public static AttributeConverterDefinition from(AttributeConverter attributeConverter, boolean autoApply) { return new AttributeConverterDefinition( attributeConverter, autoApply ); }
/** * Build an AttributeConverterDefinition from the AttributeConverter Class reference and * whether or not to auto-apply it. * * @param attributeConverterClass The AttributeConverter Class * @param autoApply Should the AttributeConverter be auto-applied? * * @return The constructed definition */ public static AttributeConverterDefinition from(Class<? extends AttributeConverter> attributeConverterClass, boolean autoApply) { return new AttributeConverterDefinition( instantiateAttributeConverter( attributeConverterClass ), autoApply ); }
/** * Build an AttributeConverterDefinition from an AttributeConverter instance. The * converter is searched for a {@link Converter} annotation to determine whether it should * be treated as auto-apply. If the annotation is present, {@link Converter#autoApply()} is * used to make that determination. If the annotation is not present, {@code false} is assumed. * * @param attributeConverter The AttributeConverter instance * * @return The constructed definition */ public static AttributeConverterDefinition from(AttributeConverter attributeConverter) { boolean autoApply = false; Converter converterAnnotation = attributeConverter.getClass().getAnnotation( Converter.class ); if ( converterAnnotation != null ) { autoApply = converterAnnotation.autoApply(); } return new AttributeConverterDefinition( attributeConverter, autoApply ); }
@SuppressWarnings("unchecked") private void setLocalAttributeConverterDefinitions(List<Element> converterElements) { for ( Element converterElement : converterElements ) { final String className = converterElement.attributeValue( "class" ); final String autoApplyAttribute = converterElement.attributeValue( "auto-apply" ); final boolean autoApply = autoApplyAttribute != null && Boolean.parseBoolean( autoApplyAttribute ); try { final Class<? extends AttributeConverter> attributeConverterClass = classLoaderAccess.classForName( className ); attributeConverterInfoList.add( new AttributeConverterDefinition( attributeConverterClass.newInstance(), autoApply ) ); } catch (ClassLoadingException e) { throw new AnnotationException( "Unable to locate specified AttributeConverter implementation class : " + className, e ); } catch (Exception e) { throw new AnnotationException( "Unable to instantiate specified AttributeConverter implementation class : " + className, e ); } } }