public DataDecoder getDecoder(ContentDeliveryConfig deliveryConfig) { @SuppressWarnings("unchecked") List decoders = deliveryConfig.getObjects("decoder:" + typeAlias); if (decoders == null || decoders.isEmpty()) { if(typeAlias != null) { decoder = DataDecoder.Factory.create(typeAlias); } else { decoder = resolveDecoderReflectively(); } } else if (!(decoders.get(0) instanceof DataDecoder)) { throw new DataDecodeException("Configured decoder '" + typeAlias + ":" + decoders.get(0).getClass().getName() + "' is not an instance of " + DataDecoder.class.getName()); } else { decoder = (DataDecoder) decoders.get(0); } if(decoder instanceof PreprocessDecoder) { PreprocessDecoder preprocessDecoder = (PreprocessDecoder) decoder; if(preprocessDecoder.getBaseDecoder() == null) { preprocessDecoder.setBaseDecoder(resolveDecoderReflectively()); } } return decoder; }
Class<? extends DataDecoder> decoder = DataDecoder.Factory.getInstance(type);
if (dataDecoder == null) { Class<?> dataType = bindingMethod.getParameterTypes()[0]; dataDecoder = DataDecoder.Factory.create(dataType);
try { String type = populatorConfig.getStringParameter("type"); DataDecoder decoder = DataDecoder.Factory.create(type); String reType = UUID.randomUUID().toString();
try { String type = populatorConfig.getStringParameter("type"); DataDecoder decoder = DataDecoder.Factory.create(type); String reType = UUID.randomUUID().toString();
private static <U> DataDecoder createDecoder(Member member, Class type, Class<? extends DataDecoder> decoderClass) { DataDecoder decoder; if(decoderClass.isAssignableFrom(DataDecoder.class)) { // No decoder specified via annotation. Infer from the field type... decoder = DataDecoder.Factory.create(type); if(decoder == null) { throw new SmooksConfigurationException("ContentHandler class member '" + getLongMemberName(member) + "' must define a decoder through it's @ConfigParam annotation. Unable to automatically determine DataDecoder from member type."); } } else { // Decoder specified on annotation... try { decoder = decoderClass.newInstance(); } catch (InstantiationException e) { throw new SmooksConfigurationException("Failed to create DataDecoder instance from class '" + decoderClass.getName() + "'. Make sure the DataDecoder implementation has a public default constructor.", e); } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Failed to create DataDecoder instance from class '" + decoderClass.getName() + "'. Make sure the DataDecoder implementation has a public default constructor.", e); } } return decoder; }
public boolean validateType(String value, List<Map.Entry<String,String>> parameters) { DataDecoder decoder; // Get DataDecoder. if (parameters != null && parameters.size() > 0 && this.name().equals("Custom")) { decoder = DataDecoder.Factory.create(parameters.get(0).getValue()); } else { decoder = DataDecoder.Factory.create(typeAlias); } // If DataDecoder implements Configurable set format. if (decoder instanceof Configurable && parameters != null) { Properties properties = getProperties(parameters); Configurable configurable = (Configurable)decoder; configurable.setConfiguration(properties); } try { decoder.decode(value); } catch (DataDecodeException e) { return false; } return true; }
private DataDecoder getDecoder(ExecutionContext executionContext) throws DataDecodeException { if(decoder == null) { @SuppressWarnings("unchecked") List decoders = executionContext.getDeliveryConfig().getObjects("decoder:" + typeAlias); if (decoders == null || decoders.isEmpty()) { decoder = DataDecoder.Factory.create(typeAlias); } else if (!(decoders.get(0) instanceof DataDecoder)) { throw new DataDecodeException("Configured decoder '" + typeAlias + ":" + decoders.get(0).getClass().getName() + "' is not an instance of " + DataDecoder.class.getName()); } else { decoder = (DataDecoder) decoders.get(0); } } return decoder; }
public String getType() { Class type = property.getType(); if(type.isArray()) { return "$DELETE:NOT-APPLICABLE$"; } Class<? extends DataDecoder> decoder = DataDecoder.Factory.getInstance(type); if(type.isPrimitive() || type.getPackage().equals(String.class.getPackage())) { String typeAlias = decoder.getSimpleName(); if(typeAlias.endsWith("Decoder")) { return typeAlias.substring(0, typeAlias.length() - "Decoder".length()); } } return "$TODO$"; } }
/** * Set the binding value data type. * @param type The data type. * * @return <code>this</code> Value configuration instance. */ public Value setType(Class<?> type) { this.decoder = DataDecoder.Factory.create(type); return this; }
/** * Create a Value binding configuration. * * @param beanId The bean id under which the value will be stored. * @param data The data selector for the data value to be bound. * @param type Data type. */ public Value(String beanId, String data, Class<?> type) { this(beanId, data); AssertArgument.isNotNull(type, "type"); this.decoder = DataDecoder.Factory.create(type); }
private DataDecoder getDecoder(ExecutionContext executionContext) throws DataDecodeException { @SuppressWarnings("unchecked") List decoders = executionContext.getDeliveryConfig().getObjects("decoder:" + typeAlias); if (decoders == null || decoders.isEmpty()) { decoder = DataDecoder.Factory.create(typeAlias); } else if (!(decoders.get(0) instanceof DataDecoder)) { throw new DataDecodeException("Configured decoder '" + typeAlias + ":" + decoders.get(0).getClass().getName() + "' is not an instance of " + DataDecoder.class.getName()); } else { decoder = (DataDecoder) decoders.get(0); } return decoder; }
public void setDataType(String dataType) { this.dataType = dataType; if(dataType != null) { decoder = DataDecoder.Factory.create(dataType); DecodeType decodeType = decoder.getClass().getAnnotation(DecodeType.class); if(decodeType != null) { typeClass = decodeType.value()[0]; } } }
public void setConfiguration(Properties config) throws SmooksException { this.config = config; expression = new MVELExpressionEvaluator(config.getProperty(VALUE_PRE_PROCESSING)); expression.setToType(String.class); String baseDecoderName = config.getProperty(BASE_DECODER); if(baseDecoderName != null) { baseDecoder = DataDecoder.Factory.create(baseDecoderName); if(baseDecoder instanceof Configurable) { ((Configurable)baseDecoder).setConfiguration(config); } } }
private DataDecoder resolveDecoderReflectively() throws DataDecodeException { Class<?> bindType = resolveBindTypeReflectively(); if(bindType != null) { DataDecoder resolvedDecoder = DataDecoder.Factory.create(bindType); if(resolvedDecoder != null) { return resolvedDecoder; } } return new StringDecoder(); }