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(); }
/** * @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 + "'"); } }
/** * 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(); }
if (setter != null) { Class<?> ptype = pd.getPropertyType(); PropertyEditor editor = PropertyEditorFinder.getInstance().find(ptype); if (editor == null) { if (trace)
@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); }
@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); }