public String toClient(E value) { if (value == null) return null; return typeCoercer.coerce(value, String.class); }
private Object getObjectAsCorrectType(Object val) { if (val != null && boundType != null && !boundType.isAssignableFrom(val.getClass())) { return typeCoercer.coerce(val, boundType); } return val; }
@Override public String toClient(E value) { if (value == null) return null; Object id = propertyAdapter.get(value); if (id == null) { return null; } return typeCoercer.coerce(id, String.class); }
@Override public String toClient(E value) { if (value == null) return null; Object id = propertyAdapter.get(value); if (id == null) { return null; } return typeCoercer.coerce(id, String.class); }
@Override public <T> T get(Class<T> desiredType, int index) { if (index == 0) { return coercer.coerce(input, desiredType); } return context.get(desiredType, index-1); } };
public E toValue(String clientValue) { if (InternalUtils.isBlank(clientValue)) return null; return typeCoercer.coerce(clientValue, enumType); }
@Override public <S, T> T coerce(S input, Class<T> targetType) { if (targetType.isInstance(input)) return targetType.cast(input); return delegate().coerce(input, targetType); }
public boolean handleResult(Object result) { List matches = coercer.coerce(result, List.class); matchesHolder.put(matches); return true; } };
private RenderCommand toRenderer(String zoneId, Object provided) { try { return typeCoercer.coerce(provided, RenderCommand.class); } catch (Exception ex) { throw new IllegalArgumentException(String.format("Failure converting renderer for zone '%s': %s", zoneId, ExceptionUtils.toMessage(ex)), ex); } } }
@Override public <S, T> T coerce(S input, Class<T> targetType) { if (targetType.isInstance(input)) return targetType.cast(input); return delegate().coerce(input, targetType); }
private String getLocale() { final String prefix = String.format("classpath:/META-INF/modules/tjq/vendor/ui/i18n/jquery.ui.datepicker-%s", locale.getLocale().getLanguage()); final Resource withCountryExtension = typeCoercer.coerce(String.format("%s-%s.js", prefix, locale.getLocale().getCountry()), Resource.class); if (withCountryExtension.exists()) { return String.format("%s-%s", locale.getLocale().getLanguage(), locale.getLocale().getCountry()); } final Resource withLanguageExtension = typeCoercer.coerce(String.format("%s.js", prefix), Resource.class); if (withLanguageExtension.exists()) { return locale.getLocale().getLanguage(); } return "en-GB"; }
private Asset getLocaleAsset(Locale locale, String jQueryUIPath) { final String prefix = String.format("%s/i18n/datepicker-%s", jQueryUIPath, locale.getLanguage()); final Resource withCountryExtension = typeCoercer.coerce(String.format("%s-%s.js", prefix, locale.getCountry()), Resource.class); if (withCountryExtension.exists()) { return assetSource.getClasspathAsset(withCountryExtension.getPath()); } final Resource withLanguageExtension = typeCoercer.coerce(String.format("%s.js", prefix), Resource.class); if (withLanguageExtension.exists()) { return assetSource.getClasspathAsset(withLanguageExtension.getPath()); } return null; }
private Object computeConstraintValue(String validatorType, Validator validator, String constraintValue, String formId, String overrideId, Messages overrideMessages) { Class constraintType = validator.getConstraintType(); String constraintText = findConstraintValue(validatorType, constraintType, constraintValue, formId, overrideId, overrideMessages); if (constraintText == null) return null; return typeCoercer.coerce(constraintText, constraintType); }
public Object get(Object instance, InstanceContext context) { // For the moment, this results in two passes through the TypeCoercer; we'll look // to optimize that in the future. The first pass is deep inside ParameterConduit (coercing // to the component parameter field type), the second is here (usually the same type so no // real coercion necessary). Object result = getParameterConduit().get(instance, context); return typeCoercer.coerce(result, fieldType); }
public void render(MarkupWriter writer, RenderQueue queue) { String value = cached ? cachedValue : coercer.coerce(binding.get(), String.class); if (invariant && !cached) { cachedValue = value; cached = true; } writer.write(value); }
@Override public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) { Value annotation = annotationProvider.getAnnotation(Value.class); if (annotation == null) return null; String value = annotation.value(); Object expanded = symbolSource.expandSymbols(value); IntermediateType intermediate = annotationProvider.getAnnotation(IntermediateType.class); if (intermediate != null) expanded = typeCoercer.coerce(expanded, intermediate.value()); return typeCoercer.coerce(expanded, objectType); } }
@Override public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) { Symbol annotation = annotationProvider.getAnnotation(Symbol.class); if (annotation == null) return null; Object value = symbolSource.valueForSymbol(annotation.value()); IntermediateType it = annotationProvider.getAnnotation(IntermediateType.class); if (it != null) value = typeCoercer.coerce(value, it.value()); return typeCoercer.coerce(value, objectType); }
@Override public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) { Symbol annotation = annotationProvider.getAnnotation(Symbol.class); if (annotation == null) return null; Object value = symbolSource.valueForSymbol(annotation.value()); IntermediateType it = annotationProvider.getAnnotation(IntermediateType.class); if (it != null) value = typeCoercer.coerce(value, it.value()); return typeCoercer.coerce(value, objectType); }
public void render(Object object, MarkupWriter writer) { writer.element("pre"); writer.write(typeCoercer.coerce(object, String.class)); writer.end(); } };
@Test public void type_coersion_from_component_resources_aware_to_component_resources() { ComponentResourcesAware input = newMock(ComponentResourcesAware.class); ComponentResources resources = mockComponentResources(); expect(input.getComponentResources()).andReturn(resources); TypeCoercer coercer = getObject(TypeCoercer.class, null); replay(); ComponentResources actual = coercer.coerce(input, ComponentResources.class); assertSame(actual, resources); verify(); }