/** * 查找类型转换器 {@link PropertyEditor} * * @param type 需要转换的目标类型 * @return {@link PropertyEditor} */ public static PropertyEditor findEditor(Class<?> type) { return PropertyEditorManager.findEditor(type); }
/** * 查找类型转换器 {@link PropertyEditor} * * @param type 需要转换的目标类型 * @return {@link PropertyEditor} */ public static PropertyEditor findEditor(Class<?> type) { return PropertyEditorManager.findEditor(type); }
PropertyEditor editor = PropertyEditorManager.findEditor(clazz); if (editor != null) { editor.setAsText((String) value);
/** Get a property editor for individual elements in this property. * @return the property editor for elements */ public PropertyEditor getIndexedPropertyEditor() { return java.beans.PropertyEditorManager.findEditor(elementType); }
import java.beans.PropertyEditor; import java.beans.PropertyEditorManager; @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String returnValue = ... return convert(method.getReturnType(), returnValue); } private Object convert(Class<?> targetType, String text) { PropertyEditor editor = PropertyEditorManager.findEditor(targetType); editor.setAsText(text); return editor.getValue(); }
private PropertyEditor getPropertyEditorValue(Class<?> cls) { if (editorMap == null) { editorMap = new HashMap<Class<?>, PropertyEditor>(); } PropertyEditor editor = editorMap.get(cls); if (editor == null) { editor = PropertyEditorManager.findEditor(cls); addEditorToMap(cls, editor); } return editor; }
/** Get a property editor for this property. * The default implementation tries to use {@link java.beans.PropertyEditorManager}. * @return the property editor, or <CODE>null</CODE> if there is no editor */ public PropertyEditor getPropertyEditor() { if (type == null) { return null; } PropertyEditor result = null; if (edRef != null) { result = edRef.get(); } if (result == null) { result = java.beans.PropertyEditorManager.findEditor(type); if (result != null && ( result.getClass().getName().equals("sun.beans.editors.EnumEditor") // NOI18N || result.getClass().getName().equals("com.sun.beans.editors.EnumEditor") // NOI18N )) { result = null; } edRef = new SoftReference<PropertyEditor>(result); } return result; }
protected Object coerceStringToType(String value, Class<?> type) { PropertyEditor editor = PropertyEditorManager.findEditor(type); if (editor == null) { if ("".equals(value)) { return null; } throw new ELException(LocalMessages.get("error.coerce.type", String.class, type)); } else { if ("".equals(value)) { try { editor.setAsText(value); } catch (IllegalArgumentException e) { return null; } } else { try { editor.setAsText(value); } catch (IllegalArgumentException e) { throw new ELException(LocalMessages.get("error.coerce.value", value, type)); } } return editor.getValue(); } }
protected Object coerceStringToType(String value, Class<?> type) { PropertyEditor editor = PropertyEditorManager.findEditor(type); if (editor == null) { if ("".equals(value)) { return null; } throw new ELException(LocalMessages.get("error.coerce.type", String.class, type)); } else { if ("".equals(value)) { try { editor.setAsText(value); } catch (IllegalArgumentException e) { return null; } } else { try { editor.setAsText(value); } catch (IllegalArgumentException e) { throw new ELException(LocalMessages.get("error.coerce.value", value, type)); } } return editor.getValue(); } }
private void initEditor() { try { Object val = getValue(); Class cls = val == null ? getValueClass() : val.getClass(); cellEditor = editorMap.get(cls); if (cellEditor != null) { return; } if (cls.isEnum()) { JComboBox comboBox = new JComboBox(cls.getEnumConstants()); cellEditor = new DefaultCellEditor(comboBox); return; } for (Class class1 : assignableClasses) { if (class1.isAssignableFrom(cls)) { cellEditor = editorMap.get(class1); return; } } editor = java.beans.PropertyEditorManager.findEditor(cls); if (editor != null && editor.supportsCustomEditor()) { cellEditor = new PropertyEditorAdapter(editor, this); return; } System.out.println("Warning no editor found for property '" + name + "' with class " + cls); } catch (Exception e) { e.printStackTrace(); } }
private static boolean isSettableType(final Class clazz) { if (PropertyEditorManager.findEditor(clazz) != null) { return true; } if (clazz == URI.class) { return true; } if (clazz == Boolean.class) { return true; } return false; }
/** * Locate a value editor for a given target type. * * @param type The class of the object to be edited. * @return An editor for the given type or null if none was found. */ public static PropertyEditor findEditor(final Class<?> type) { return PropertyEditorManager.findEditor(type); }
private static boolean isSettableType(Class clazz) { if (PropertyEditorManager.findEditor(clazz) != null) { return true; } if (clazz == URI.class) { return true; } return false; }
private static boolean isSettableType(Class clazz) { if (PropertyEditorManager.findEditor(clazz) != null) { return true; } if (clazz == URI.class) { return true; } return false; }
private static Object convert(Object value, Class type) throws URISyntaxException { PropertyEditor editor = PropertyEditorManager.findEditor(type); if (editor != null) { editor.setAsText(value.toString()); return editor.getValue(); } if (type == URI.class) { return new URI(value.toString()); } return null; }
private static boolean hasPropertyEditor(String type) { Class theClass; try { theClass = loadClass(type); // lets see if we can find a property editor for this type PropertyEditor editor = PropertyEditorManager.findEditor(theClass); return editor != null; } catch (Throwable e) { System.out.println("Warning, could not load class: " + type + ": " + e); return false; } }
private PropertyEditor getPropertyEditorValue(Class<?> cls) { if (editorMap == null) { editorMap = new HashMap<Class<?>, PropertyEditor>(); } PropertyEditor editor = editorMap.get(cls); if (editor == null) { editor = PropertyEditorManager.findEditor(cls); addEditorToMap(cls, editor); } return editor; }
public Object toObjectImpl(final String text) throws PropertyEditorException { final PropertyEditor editor = PropertyEditorManager.findEditor(getType()); editor.setAsText(text); try { return editor.getValue(); } catch (final Exception e) { throw new PropertyEditorException("Error while converting \"" + text + "\" to a " + getType().getSimpleName() + " using the property editor " + editor.getClass().getSimpleName(), e); } } }
private static String convertToString(final Object value, final Class type) throws URISyntaxException { final PropertyEditor editor = PropertyEditorManager.findEditor(type); if (editor != null) { editor.setValue(value); return editor.getAsText(); } if (type == URI.class) { return ((URI) value).toString(); } return null; }
private static String convertToString(Object value, Class type) throws URISyntaxException { PropertyEditor editor = PropertyEditorManager.findEditor(type); if (editor != null) { editor.setValue(value); return editor.getAsText(); } if (type == URI.class) { return ((URI)value).toString(); } return null; }