@SuppressWarnings({"unchecked"}) @Test public void to_client_via_translator() { Object value = new Integer(99); ComponentResources resources = mockComponentResources(); FieldTranslator translator = mockFieldTranslator(); NullFieldStrategy nullFieldStrategy = mockNullFieldStrategy(); expect(translator.getType()).andReturn(Integer.class); String clientValue = "abracadabra"; EasyMock.expect(resources.triggerEvent(EasyMock.eq(EventConstants.TO_CLIENT), EasyMock.aryEq(new Object[]{value}), EasyMock.isA(ComponentEventCallback.class))).andReturn(false); expect(translator.toClient(value)).andReturn(clientValue); replay(); FieldValidationSupport support = new FieldValidationSupportImpl(typeCoercer, propertyAccess); String actual = support.toClient(value, resources, translator, nullFieldStrategy); assertEquals(actual, clientValue); verify(); }
public String toClient(Object value, ComponentResources componentResources, FieldTranslator<Object> translator, NullFieldStrategy nullFieldStrategy) { assert componentResources != null; assert translator != null; assert nullFieldStrategy != null; final Holder<String> resultHolder = Holder.create(); ComponentEventCallback callback = new ComponentEventCallback() { public boolean handleResult(Object result) { if (!(result instanceof String)) throw new RuntimeException("Return value from 'parseClient' event handler method must be a string."); resultHolder.put((String) result); return true; } }; componentResources.triggerEvent(EventConstants.TO_CLIENT, new Object[] {value}, callback); if (resultHolder.hasValue()) return resultHolder.get(); Object effectiveValue = value; if (effectiveValue == null) { effectiveValue = nullFieldStrategy.replaceToClient(); if (effectiveValue == null) return null; } Object coerced = typeCoercer.coerce(effectiveValue, translator.getType()); return translator.toClient(coerced); }
FieldValidationSupportImpl implements FieldValidationSupport { public String toClient(Object value, ComponentResources componentResources, FieldTranslator<Object> translator, NullFieldStrategy nullFieldStrategy) { assert componentResources != null; assert translator != null; assert nullFieldStrategy != null; final Holder<String> resultHolder = Holder.create(); ComponentEventCallback callback = new ComponentEventCallback() { public boolean handleResult(Object result) { if (!(result instanceof String)) throw new RuntimeException("Return value from 'parseClient' event handler method must be a string."); resultHolder.put((String) result); return true; } }; componentResources.triggerEvent(EventConstants.TO_CLIENT, new Object[] {value}, callback); if (resultHolder.hasValue()) return resultHolder.get(); Object effectiveValue = value; if (effectiveValue == null) { effectiveValue = nullFieldStrategy.replaceToClient(); if (effectiveValue == null) return null; } Object coerced = typeCoercer.coerce(effectiveValue, translator.getType()); return translator.toClient(coerced); } }
FieldValidationSupportImpl implements FieldValidationSupport { public String toClient(Object value, ComponentResources componentResources, FieldTranslator<Object> translator, NullFieldStrategy nullFieldStrategy) { assert componentResources != null; assert translator != null; assert nullFieldStrategy != null; final Holder<String> resultHolder = Holder.create(); ComponentEventCallback callback = new ComponentEventCallback() { public boolean handleResult(Object result) { if (!(result instanceof String)) throw new RuntimeException("Return value from 'parseClient' event handler method must be a string."); resultHolder.put((String) result); return true; } }; componentResources.triggerEvent(EventConstants.TO_CLIENT, new Object[] {value}, callback); if (resultHolder.hasValue()) return resultHolder.get(); Object effectiveValue = value; if (effectiveValue == null) { effectiveValue = nullFieldStrategy.replaceToClient(); if (effectiveValue == null) return null; } Object coerced = typeCoercer.coerce(effectiveValue, translator.getType()); return translator.toClient(coerced); } FieldValidationSupportImpl(TypeCoercer typeCoercer, PropertyAccess propertyAccess); }
FieldValidationSupportImpl implements FieldValidationSupport { public String toClient(Object value, ComponentResources componentResources, FieldTranslator<Object> translator, NullFieldStrategy nullFieldStrategy) { assert componentResources != null; assert translator != null; assert nullFieldStrategy != null; final Holder<String> resultHolder = Holder.create(); ComponentEventCallback callback = new ComponentEventCallback() { public boolean handleResult(Object result) { if (!(result instanceof String)) throw new RuntimeException("Return value from 'parseClient' event handler method must be a string."); resultHolder.put((String) result); return true; } }; componentResources.triggerEvent(EventConstants.TO_CLIENT, new Object[] {value}, callback); if (resultHolder.hasValue()) return resultHolder.get(); Object effectiveValue = value; if (effectiveValue == null) { effectiveValue = nullFieldStrategy.replaceToClient(); if (effectiveValue == null) return null; } Object coerced = typeCoercer.coerce(effectiveValue, translator.getType()); return translator.toClient(coerced); } FieldValidationSupportImpl(TypeCoercer typeCoercer, PropertyAccess propertyAccess); String toClient(Object value, ComponentResources componentResources, FieldTranslator<Object> translator,
                           NullFieldStrategy nullFieldStrategy); Object parseClient(String clientValue, ComponentResources componentResources,
                              FieldTranslator<Object> translator, NullFieldStrategy nullFieldStrategy); @SuppressWarnings( {"unchecked"}) void validate(Object value, ComponentResources componentResources, FieldValidator validator); }
FieldValidationSupportImpl implements FieldValidationSupport { public String toClient(Object value, ComponentResources componentResources, FieldTranslator<Object> translator, NullFieldStrategy nullFieldStrategy) { assert componentResources != null; assert translator != null; assert nullFieldStrategy != null; final Holder<String> resultHolder = Holder.create(); ComponentEventCallback callback = new ComponentEventCallback() { public boolean handleResult(Object result) { if (!(result instanceof String)) throw new RuntimeException("Return value from 'parseClient' event handler method must be a string."); resultHolder.put((String) result); return true; } }; componentResources.triggerEvent(EventConstants.TO_CLIENT, new Object[] {value}, callback); if (resultHolder.hasValue()) return resultHolder.get(); Object effectiveValue = value; if (effectiveValue == null) { effectiveValue = nullFieldStrategy.replaceToClient(); if (effectiveValue == null) return null; } Object coerced = typeCoercer.coerce(effectiveValue, translator.getType()); return translator.toClient(coerced); } FieldValidationSupportImpl(TypeCoercer typeCoercer, PropertyAccess propertyAccess); String toClient(Object value, ComponentResources componentResources, FieldTranslator<Object> translator,
                           NullFieldStrategy nullFieldStrategy); Object parseClient(String clientValue, ComponentResources componentResources,
                              FieldTranslator<Object> translator, NullFieldStrategy nullFieldStrategy); @SuppressWarnings( {"unchecked"}) void validate(Object value, ComponentResources componentResources, FieldValidator validator);  }