use of org.apache.commons.beanutils.Converter in project apex-core by apache.
the class StringCodecs method check.
public static void check() {
if (classLoaders.putIfAbsent(Thread.currentThread().getContextClassLoader(), Boolean.TRUE) == null) {
loadDefaultConverters();
for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) {
try {
final StringCodec<?> codecInstance = entry.getValue().newInstance();
ConvertUtils.register(new Converter() {
@Override
public Object convert(Class type, Object value) {
return value == null ? null : codecInstance.fromString(value.toString());
}
}, entry.getKey());
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}
}
use of org.apache.commons.beanutils.Converter in project onebusaway-gtfs-modules by OneBusAway.
the class DeferredValueMatcher method matches.
public boolean matches(Class<?> parentEntityType, String propertyName, Object value) {
if (value == null) {
return _value == null;
} else if (_value == null) {
return false;
}
if (_resolvedValueSet) {
return value.equals(_resolvedValue);
}
Class<?> expectedValueType = value.getClass();
Class<?> actualValueType = _value.getClass();
if (expectedValueType.isAssignableFrom(actualValueType)) {
return value.equals(_value);
}
if (actualValueType == String.class) {
String actualValue = (String) _value;
if (expectedValueType == AgencyAndId.class) {
AgencyAndId expectedId = (AgencyAndId) value;
return expectedId.getId().equals(actualValue);
} else if (IdentityBean.class.isAssignableFrom(expectedValueType)) {
IdentityBean<?> bean = (IdentityBean<?>) value;
Object expectedId = bean.getId();
if (expectedId == null) {
return false;
}
if (expectedId instanceof AgencyAndId) {
AgencyAndId expectedFullId = (AgencyAndId) expectedId;
return expectedFullId.getId().equals(actualValue);
} else if (expectedId instanceof String) {
return expectedId.equals(actualValue);
}
} else {
Converter converter = _support.resolveConverter(parentEntityType, propertyName, expectedValueType);
if (converter != null) {
_resolvedValue = converter.convert(expectedValueType, _value);
_resolvedValueSet = true;
return value.equals(_resolvedValue);
} else {
throw new IllegalStateException("no type conversion from type String to type \"" + expectedValueType.getName() + "\" for value comparison");
}
}
}
throw new IllegalStateException("no type conversion from type \"" + actualValueType.getName() + "\" to type \"" + expectedValueType.getName() + "\" for value comparison");
}
use of org.apache.commons.beanutils.Converter in project onebusaway-gtfs-modules by OneBusAway.
the class EntityFieldMappingImpl method translateFromCSVToObject.
public void translateFromCSVToObject(CsvEntityContext context, Map<String, Object> csvValues, BeanWrapper object) {
if (isMissingAndOptional(csvValues))
return;
Converter converter = create(context);
String entityId = (String) csvValues.get(_csvFieldName);
Object entity = converter.convert(_objFieldType, entityId);
object.setPropertyValue(_objFieldName, entity);
}
use of org.apache.commons.beanutils.Converter in project onebusaway-gtfs-modules by OneBusAway.
the class DeferredValueSupportTest method testResolveConverter.
@Test
public void testResolveConverter() {
Converter converter = _support.resolveConverter(Object.class, "xyz", String.class);
assertSame(ConvertUtils.lookup(String.class), converter);
}
Aggregations