Example usage for org.springframework.beans.propertyeditors ClassEditor ClassEditor

List of usage examples for org.springframework.beans.propertyeditors ClassEditor ClassEditor

Introduction

In this page you can find the example usage for org.springframework.beans.propertyeditors ClassEditor ClassEditor.

Prototype

public ClassEditor() 

Source Link

Document

Create a default ClassEditor, using the thread context ClassLoader.

Usage

From source file:org.jspringbot.keyword.expression.engine.function.StaticMethodUtils.java

public static Method getMethod(Class clazz, String methodSignature) {
    Matcher matcher = METHOD_SIGNATURE_PATTERN.matcher(methodSignature);

    if (matcher.find()) {
        String methodName = matcher.group(2);
        String parameterTypes = matcher.group(3);

        List<Class> types = new ArrayList<Class>();
        for (String parameterType : StringUtils.split(parameterTypes, ',')) {
            ClassEditor editor = new ClassEditor();
            editor.setAsText(parameterType);
            types.add((Class) editor.getValue());
        }//from ww  w . j av  a 2  s . c om

        return MethodUtils.getAccessibleMethod(clazz, methodName, types.toArray(new Class[types.size()]));
    }

    throw new IllegalStateException(String.format("Invalid method signature '%s' found.", methodSignature));
}

From source file:org.jspringbot.keyword.expression.engine.function.SupportedFunctionsManager.java

private void register(Function function) {
    ClassEditor editor = new ClassEditor();
    editor.setAsText(function.getFunctionClass());

    Class clazz = (Class) editor.getValue();
    Method method = StaticMethodUtils.getMethod(clazz, function.getFunctionSignature());

    functionMapper.setFunction(function.getPrefix(), function.getName(), method);
}

From source file:org.nextframework.controller.ExtendedBeanWrapper.java

/**
 * Register default editors in this class, for restricted environments.
 * We're not using the JRE's PropertyEditorManager to avoid potential
 * SecurityExceptions when running in a SecurityManager.
 * <p>Registers a <code>CustomNumberEditor</code> for all primitive number types,
 * their corresponding wrapper types, <code>BigInteger</code> and <code>BigDecimal</code>.
 *///from w w  w.  j  a  v  a2 s. co m
protected void registerDefaultEditors() {
    // Simple editors, without parameterization capabilities.
    // The JDK does not contain a default editor for any of these target types.
    this.defaultEditors.put(byte[].class, new ByteArrayPropertyEditor());
    this.defaultEditors.put(Class.class, new ClassEditor());
    this.defaultEditors.put(File.class, new FileEditor());
    this.defaultEditors.put(InputStream.class, new InputStreamEditor());
    this.defaultEditors.put(Locale.class, new LocaleEditor());
    this.defaultEditors.put(Properties.class, new PropertiesEditor());
    this.defaultEditors.put(Resource[].class, new ResourceArrayPropertyEditor());
    this.defaultEditors.put(String[].class, new StringArrayPropertyEditor());
    this.defaultEditors.put(URL.class, new URLEditor());

    // Default instances of collection editors.
    // Can be overridden by registering custom instances of those as custom editors.
    this.defaultEditors.put(Collection.class, new CustomCollectionEditor(Collection.class));
    this.defaultEditors.put(Set.class, new CustomCollectionEditor(Set.class));
    this.defaultEditors.put(SortedSet.class, new CustomCollectionEditor(SortedSet.class));
    this.defaultEditors.put(List.class, new CustomCollectionEditor(List.class));

    // Default instances of character and boolean editors.
    // Can be overridden by registering custom instances of those as custom editors.
    PropertyEditor characterEditor = new CharacterEditor(true);
    PropertyEditor booleanEditor = new CustomBooleanEditor(true);

    // The JDK does not contain a default editor for char!
    this.defaultEditors.put(char.class, characterEditor);
    this.defaultEditors.put(Character.class, characterEditor);

    // Spring's CustomBooleanEditor accepts more flag values than the JDK's default editor.
    this.defaultEditors.put(boolean.class, booleanEditor);
    this.defaultEditors.put(Boolean.class, booleanEditor);

    // The JDK does not contain default editors for number wrapper types!
    // Override JDK primitive number editors with our own CustomNumberEditor.
    PropertyEditor byteEditor = new CustomNumberEditor(Byte.class, true);
    PropertyEditor shortEditor = new CustomNumberEditor(Short.class, true);
    PropertyEditor integerEditor = new CustomNumberEditor(Integer.class, true);
    PropertyEditor longEditor = new CustomNumberEditor(Long.class, true);
    PropertyEditor floatEditor = new CustomNumberEditor(Float.class, true);
    PropertyEditor doubleEditor = new CustomNumberEditor(Double.class, true);

    this.defaultEditors.put(byte.class, byteEditor);
    this.defaultEditors.put(Byte.class, byteEditor);

    this.defaultEditors.put(short.class, shortEditor);
    this.defaultEditors.put(Short.class, shortEditor);

    this.defaultEditors.put(int.class, integerEditor);
    this.defaultEditors.put(Integer.class, integerEditor);

    this.defaultEditors.put(long.class, longEditor);
    this.defaultEditors.put(Long.class, longEditor);

    this.defaultEditors.put(float.class, floatEditor);
    this.defaultEditors.put(Float.class, floatEditor);

    this.defaultEditors.put(double.class, doubleEditor);
    this.defaultEditors.put(Double.class, doubleEditor);

    this.defaultEditors.put(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, false));
    this.defaultEditors.put(BigInteger.class, new CustomNumberEditor(BigInteger.class, false));

    //============================================================================================

    // Date, Time, Hora e Timestamp.

    boolean allowEmpty = true;

    registerCustomEditor(Calendar.class, new CalendarEditor(simpleDateFormat, allowEmpty));
    registerCustomEditor(Date.class, new CustomDateEditor(simpleDateFormat, allowEmpty));
    registerCustomEditor(java.sql.Date.class, new CustomSqlDateEditor(simpleDateFormat, allowEmpty));
    registerCustomEditor(Time.class, new TimePropertyEditor());
    registerCustomEditor(SimpleTime.class, new SimpleTimePropertyEditor());
    registerCustomEditor(Timestamp.class, new TimestampPropertyEditor());

    // Tipos personalizados.
    registerCustomEditor(Cpf.class, new CpfPropertyEditor());
    registerCustomEditor(Cnpj.class, new CnpjPropertyEditor());
    registerCustomEditor(InscricaoEstadual.class, new InscricaoEstadualPropertyEditor());
    registerCustomEditor(Money.class, new MoneyPropertyEditor());
    registerCustomEditor(Cep.class, new CepPropertyEditor());
    registerCustomEditor(PhoneBrazil.class, new PhoneBrazilPropertyEditor());
    registerCustomEditor(Phone.class, new PhonePropertyEditor());
}

From source file:org.springframework.beans.factory.support.DependencyInjectionAspectSupport.java

/**
 * Resolve this FQN/* www  . ja  va 2 s  .c  o m*/
 * @param className name of the class to resolve
 * @return the Class
 */
private Class classNameStringToClass(String className) {
    ClassEditor ce = new ClassEditor();
    ce.setAsText(className);
    return (Class) ce.getValue();
}

From source file:org.springframework.richclient.application.support.DefaultPropertyEditorRegistry.java

/**
 * Adds a property editor to the registry extracting the object class,
 * property name and property editor class from the properties
 * "objectClass", "propertyName" and "propertyEditorClass".
 * //w  ww .ja  va  2  s . c o  m
 * @param properties
 *            the properties
 */
public void setPropertyEditor(Properties properties) {
    ClassEditor classEditor = new ClassEditor();

    Class objectClass = null;
    String propertyName = null;
    Class propertyEditorClass = null;

    if (properties.get("objectClass") != null) {
        classEditor.setAsText((String) properties.get("objectClass"));
        objectClass = (Class) classEditor.getValue();
    }
    propertyName = (String) properties.get("propertyName");
    if (properties.get("propertyEditorClass") != null) {
        classEditor.setAsText((String) properties.get("propertyEditorClass"));
        propertyEditorClass = (Class) classEditor.getValue();
    } else {
        throw new IllegalArgumentException("propertyEditorClass is required");
    }

    if (propertyName != null) {
        setPropertyEditor(objectClass, propertyName, propertyEditorClass);
    } else if (objectClass != null) {
        setPropertyEditor(objectClass, propertyEditorClass);
    } else {
        throw new IllegalArgumentException("objectClass and/or propertyName are required");
    }
}