private static Object newValue(final Class<?> type, final String value) { final PropertyEditor editor = PropertyEditorFinder.getInstance().find(type); if (editor == null) { SarLogger.ROOT_LOGGER.propertyNotFound(type); return null; } editor.setAsText(value); return editor.getValue(); }
/** * Returns instance of property finder. Instance is loaded as {@link java.util.ServiceLoader} service. * If no service is found, this method, this method will return <b>null</b>. * * @return Instance of PropertyEditorFinder. */ public static PropertyEditorFinder getInstance(ClassLoader classLoader) { PropertyEditorFinder result = _INSTANCE; if (result == null) { synchronized (_LOCK) { result = _INSTANCE; if (result == null) { init(classLoader); result = _INSTANCE; } } } return result; }
register(Byte.TYPE, ByteEditor.class); register(Short.TYPE, ShortEditor.class); register(Integer.TYPE, IntegerEditor.class); register(Long.TYPE, LongEditor.class); register(Boolean.TYPE, BooleanEditor.class); register(Float.TYPE, FloatEditor.class); register(Double.TYPE, DoubleEditor.class); register(Character.TYPE, CharacterEditor.class); register(Byte.class, ByteEditor.class); register(Short.class, ShortEditor.class); register(Integer.class, IntegerEditor.class); register(Long.class, LongEditor.class); register(Boolean.class, BooleanEditor.class); register(Float.class, FloatEditor.class); register(Double.class, DoubleEditor.class); register(Character.class, CharacterEditor.class); register(strArrayType, StringArrayEditor.class); Class<?> clsArrayType = Class[].class; register(clsArrayType, ClassArrayEditor.class); Class<?> intArrayType = int[].class; register(intArrayType, IntegerArrayEditor.class); Class<?> byteArrayType = byte[].class; register(byteArrayType, ByteArrayEditor.class); Class<?> booleanArrayType = boolean[].class; register(booleanArrayType, BooleanArrayEditor.class); Class<?> charArrayType = char[].class; register(charArrayType, CharacterArrayEditor.class);
public static PropertyEditorFinder getInstance() { return getInstance(PropertyEditorFinder.class.getClassLoader()); } }
/** * @param type */ public GenericArrayPropertyEditor(Class<T> initType) { super(initType); // quick checks if (!initType.isArray()) { throw new IllegalArgumentException("Type is not array! " + initType); } this.cellType = initType.getComponentType(); // generic interface. java.beans.PropertyEditor cellPropertyEditor = PropertyEditorFinder.getInstance().find(this.cellType); // jic if (cellPropertyEditor == null) { throw new IllegalArgumentException("No editor found for '" + this.cellType + "'"); } }
@Override public String getAsText() { Object reflectiveArray = getValue(); if (reflectiveArray == null) { return null; } // generic interface. java.beans.PropertyEditor cellPropertyEditor = PropertyEditorFinder.getInstance().find(this.cellType); int length = Array.getLength(reflectiveArray); String[] cellStringValues = new String[length]; for (int index = 0; index < length; index++) { Object cellValue = Array.get(reflectiveArray, index); cellPropertyEditor.setValue(cellValue); cellStringValues[index]=cellPropertyEditor.getAsText(); } return encode(cellStringValues); }
/** * Convert a string value into the true value for typeName using the PropertyEditor associated with typeName. * * @param text the string represention of the value. This is passed to the PropertyEditor.setAsText method. * @param typeName the fully qualified class name of the true value type * @return the PropertyEditor.getValue() result * @exception ClassNotFoundException thrown if the typeName class cannot be found * @exception IntrospectionException thrown if a PropertyEditor for typeName cannot be found */ public static Object convertValue(String text, String typeName) throws ClassNotFoundException, IntrospectionException { // see if it is a primitive type first Class<?> typeClass = getPrimitiveTypeForName(typeName); if (typeClass == null) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); typeClass = loader.loadClass(typeName); } PropertyEditor editor = PropertyEditorFinder.getInstance().find(typeClass); if (editor == null) { throw new IntrospectionException("No property editor for type=" + typeClass); } editor.setAsText(text); return editor.getValue(); }
@Override public void setAsText(String text) throws IllegalArgumentException { if (BeanUtils.isNull(text)) { this.setValue(null); return; } // generic interface. java.beans.PropertyEditor cellPropertyEditor = PropertyEditorFinder.getInstance().find(this.cellType); String[] cellStringValues = tokenize(text); Object reflectiveArray = Array.newInstance(this.cellType, cellStringValues.length); for (int index = 0; index < cellStringValues.length; index++) { cellPropertyEditor.setAsText(cellStringValues[index]); Object cellValue = cellPropertyEditor.getValue(); Array.set(reflectiveArray, index, cellValue); } this.setValue(reflectiveArray); }
if (setter != null) { Class<?> ptype = pd.getPropertyType(); PropertyEditor editor = PropertyEditorFinder.getInstance().find(ptype); if (editor == null) { if (trace)