Search in sources :

Example 1 with PropertyEditorException

use of org.apache.xbean.propertyeditor.PropertyEditorException in project tomee by apache.

the class ActiveMQ5Factory method createPersistenceAdapter.

private static PersistenceAdapter createPersistenceAdapter(final String clazz, final String prefix, final Map<String, String> params) throws IllegalAccessException, InvocationTargetException, ClassNotFoundException, InstantiationException {
    Class<?> aClass = Thread.currentThread().getContextClassLoader().loadClass(clazz);
    final PersistenceAdapter persistenceAdapter = PersistenceAdapter.class.cast(aClass.newInstance());
    while (aClass != null) {
        for (final Method m : aClass.getDeclaredMethods()) {
            if (m.getName().startsWith("set") && m.getParameterTypes().length == 1 && Modifier.isPublic(m.getModifiers())) {
                final String key = prefix + "." + m.getName().substring(3).toLowerCase(Locale.ENGLISH);
                final Object field = params.remove(key);
                if (field != null) {
                    try {
                        final Object toSet = PropertyEditors.getValue(m.getParameterTypes()[0], field.toString());
                        m.invoke(persistenceAdapter, toSet);
                    } catch (final PropertyEditorException cantConvertException) {
                        throw new IllegalArgumentException("can't convert " + field + " for " + m.getName(), cantConvertException);
                    }
                }
            }
        }
        aClass = aClass.getSuperclass();
    }
    return persistenceAdapter;
}
Also used : PropertyEditorException(org.apache.xbean.propertyeditor.PropertyEditorException) Method(java.lang.reflect.Method) MemoryPersistenceAdapter(org.apache.activemq.store.memory.MemoryPersistenceAdapter) JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter)

Aggregations

Method (java.lang.reflect.Method)1 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)1 JDBCPersistenceAdapter (org.apache.activemq.store.jdbc.JDBCPersistenceAdapter)1 MemoryPersistenceAdapter (org.apache.activemq.store.memory.MemoryPersistenceAdapter)1 PropertyEditorException (org.apache.xbean.propertyeditor.PropertyEditorException)1