Example usage for org.apache.commons.beanutils.converters AbstractConverter AbstractConverter

List of usage examples for org.apache.commons.beanutils.converters AbstractConverter AbstractConverter

Introduction

In this page you can find the example usage for org.apache.commons.beanutils.converters AbstractConverter AbstractConverter.

Prototype

public AbstractConverter() 

Source Link

Document

Construct a Converter that throws a ConversionException if an error occurs.

Usage

From source file:es.uvigo.ei.sing.gc.GeneCommitteeLifeCycle.java

@Override
public void contextInitialized(ServletContextEvent event) {
    System.setProperty("sing.data", "disk");
    System.setProperty("sing.data.stringbytes", "124");

    final File usersDir = Configuration.getInstance().getUsersDirectory();
    final File guestsDir = Configuration.getInstance().getGuestsDirectory();
    final File tmpDir = Configuration.getInstance().getTmpDirectory();

    if (!usersDir.isDirectory())
        if (usersDir.mkdirs())
            System.out.println("usersDir");
        else//  ww w.j  a  v  a2  s. co  m
            System.err.println("UsersDir: " + usersDir);
    if (!guestsDir.isDirectory())
        if (guestsDir.mkdirs())
            System.out.println("guestsDir");
        else
            System.err.println("GuestsDir: " + guestsDir);
    if (!tmpDir.isDirectory())
        if (tmpDir.mkdirs())
            System.out.println("tmpDir");
        else
            System.err.println("TmpDir: " + tmpDir);

    ConvertUtils.register(new AbstractConverter() {
        @Override
        protected Class<ReplicationMode> getDefaultType() {
            return ReplicationMode.class;
        }

        @Override
        @SuppressWarnings("rawtypes")
        protected Object convertToType(Class type, Object value) throws Throwable {
            if (value instanceof String) {
                return ReplicationMode.valueOf((String) value);
            } else {
                throw new IllegalArgumentException("value must be a String");
            }
        }
    }, ReplicationMode.class);

    this.deleteGuestUsers();
}

From source file:org.debux.webmotion.test.ConverterListener.java

@Override
public void onStart(Mapping mapping, ServerContext context) {
    context.addConverter(new AbstractConverter() {
        @Override/*from w w w .j a  va  2s .c o  m*/
        protected Object convertToType(Class type, Object value) throws Throwable {
            String json = (String) value;
            JsonParser parser = new JsonParser();
            return parser.parse(json);
        }

        @Override
        protected Class getDefaultType() {
            return JsonElement.class;
        }
    }, JsonElement.class);
}