use of java.beans.PropertyEditor in project camel by apache.
the class IntrospectionSupport method convert.
private static Object convert(TypeConverter typeConverter, Class<?> type, Object value) throws URISyntaxException, NoTypeConversionAvailableException {
if (typeConverter != null) {
return typeConverter.mandatoryConvertTo(type, value);
}
if (type == URI.class) {
return new URI(value.toString());
}
PropertyEditor editor = PropertyEditorManager.findEditor(type);
if (editor != null) {
// property editor is not thread safe, so we need to lock
Object answer;
synchronized (LOCK) {
editor.setAsText(value.toString());
answer = editor.getValue();
}
return answer;
}
return null;
}
use of java.beans.PropertyEditor in project jdk8u_jdk by JetBrains.
the class Test4274639 method main.
public static void main(String[] args) {
TestBean bean = new TestBean(STRING_VALUE);
if (!STRING_VALUE.equals(bean.getString()))
throw new Error("unexpected string property: " + bean.getString());
boolean string = false;
boolean integer = false;
for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(bean.getClass())) {
String name = pd.getName();
System.out.println(" - " + name);
if (name.equals(STRING_PROPERTY)) {
// This tests createPropertyEditor such that the PropertyEditor
// returned will have the bean as the source object.
Class type = pd.getPropertyEditorClass();
if (!StringEditor.class.equals(type))
throw new Error("unexpected property editor type: " + type);
PropertyEditor editor = pd.createPropertyEditor(bean);
if (editor == null)
throw new Error("property editor cannot be created");
if (STRING_VALUE != editor.getValue())
throw new Error("unexpected value: " + editor.getValue());
Object source = ((PropertyEditorSupport) editor).getSource();
if (source != bean)
throw new Error("unexpected source: " + source);
string = true;
}
if (name.equals(INTEGER_PROPERTY)) {
// This tests createPropertyEditor such that the PropertyEditor
// returned will be just a new instance
Class type = pd.getPropertyEditorClass();
if (!IntegerEditor.class.equals(type))
throw new Error("unexpected property editor type: " + type);
PropertyEditor editor = pd.createPropertyEditor(bean);
if (editor == null)
throw new Error("property editor cannot be created");
if (INTEGER_VALUE != editor.getValue())
throw new Error("unexpected value: " + editor.getValue());
Object source = ((PropertyEditorSupport) editor).getSource();
if (source != editor)
throw new Error("unexpected source: " + source);
integer = true;
}
}
if (!string)
throw new Error("string property is not tested");
if (!integer)
throw new Error("integer property is not tested");
}
use of java.beans.PropertyEditor in project lucene-solr by apache.
the class ParseContextConfig method getValueFromString.
private Object getValueFromString(Class<?> targetType, String text) {
final PropertyEditor editor = PropertyEditorManager.findEditor(targetType);
if (editor == null) {
throw new IllegalArgumentException("Cannot set properties of type " + targetType.getName());
}
editor.setAsText(text);
return editor.getValue();
}
use of java.beans.PropertyEditor in project sling by apache.
the class JspRuntimeLibrary method getValueFromBeanInfoPropertyEditor.
//*********************************************************************
// PropertyEditor Support
public static Object getValueFromBeanInfoPropertyEditor(Class attrClass, String attrName, String attrValue, Class propertyEditorClass) throws JasperException {
try {
PropertyEditor pe = (PropertyEditor) propertyEditorClass.newInstance();
pe.setAsText(attrValue);
return pe.getValue();
} catch (Exception ex) {
throw new JasperException(Localizer.getMessage("jsp.error.beans.property.conversion", attrValue, attrClass.getName(), attrName, ex.getMessage()));
}
}
use of java.beans.PropertyEditor in project geronimo-xbean by apache.
the class PropertyEditors method findEditor.
/**
* Locate a property editor for qiven class of object.
*
* @param type The target object class of the property.
* @return The resolved editor, if any. Returns null if a suitable editor
* could not be located.
*/
private static PropertyEditor findEditor(Type type) {
if (type == null)
throw new NullPointerException("type is null");
Class clazz = toClass(type);
// try to locate this directly from the editor manager first.
PropertyEditor editor = PropertyEditorManager.findEditor(clazz);
// we're outta here if we got one.
if (editor != null) {
return editor;
}
// resolvable
if (clazz.isArray() && !clazz.getComponentType().isArray()) {
// do a recursive lookup on the base type
editor = findEditor(clazz.getComponentType());
// wrapper this in an array adaptor for real use
if (editor != null) {
return new ArrayConverter(clazz, editor);
}
}
// nothing found
return null;
}
Aggregations