Example usage for org.apache.commons.lang ClassUtils primitiveToWrapper

List of usage examples for org.apache.commons.lang ClassUtils primitiveToWrapper

Introduction

In this page you can find the example usage for org.apache.commons.lang ClassUtils primitiveToWrapper.

Prototype

public static Class<?> primitiveToWrapper(Class<?> cls) 

Source Link

Document

Converts the specified primitive Class object to its corresponding wrapper Class object.

NOTE: From v2.2, this method handles Void.TYPE, returning Void.TYPE.

Usage

From source file:com.goncalomb.bukkit.bkglib.reflect.NBTTypes.java

private static void registerNew(String tagClassName)
        throws SecurityException, NoSuchMethodException, NoSuchFieldException {
    NBTTypes handler = new NBTTypes(tagClassName);
    _innerTypeMap.put((handler._dataType.isPrimitive() ? ClassUtils.primitiveToWrapper(handler._dataType)
            : handler._dataType), handler);
    _outerTypeMap.put(handler._class, handler);
}

From source file:com.haulmont.cuba.core.config.type.TypeFactory.java

/**
 * Get a TypeFactory instance appropriate for the return type of the
 * specified configuration interface method.
 *
 * @param configInterface The configuration interface.
 * @param method          The method.//from w w  w  .j av a  2 s.  com
 * @return An appropriate TypeFactory.
 * @throws IllegalArgumentException If the type is not supported.
 */
public static TypeFactory getInstance(Class<?> configInterface, Method method) {
    Class<?> returnType = method.getReturnType();
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }
    Factory factory = ConfigUtil.getAnnotation(configInterface, method, Factory.class, true);
    if (factory != null) {
        try {
            if ("".equals(factory.method())) {
                return factory.factory().newInstance();
            } else {
                String methodName = factory.method();
                Method factoryMethod = returnType.getMethod(methodName, String.class);
                if (!isAcceptableMethod(returnType, factoryMethod)) {
                    throw new IllegalArgumentException("Invalid factory method: " + factoryMethod);
                }
                return new StaticTypeFactory(factoryMethod);
            }
        } catch (NoSuchMethodException | InstantiationException | IllegalAccessException e) {
            throw new RuntimeException("Unable to instantiate an type factory", e);
        }
    } else {
        if (Entity.class.isAssignableFrom(returnType)) {
            return AppBeans.get(ENTITY_FACTORY_BEAN_NAME, TypeFactory.class);
        } else {
            if (EnumClass.class.isAssignableFrom(returnType)) {
                EnumStore mode = ConfigUtil.getAnnotation(configInterface, method, EnumStore.class, true);
                if (mode != null && EnumStoreMode.ID == mode.value()) {
                    @SuppressWarnings("unchecked")
                    Class<EnumClass> enumeration = (Class<EnumClass>) returnType;
                    Class<?> idType = ConfigUtil.getEnumIdType(enumeration);
                    TypeFactory idFactory = getInferred(idType);
                    try {
                        Method fromIdMethod = returnType.getMethod("fromId", idType);
                        if (!isAcceptableMethod(returnType, fromIdMethod) || idFactory == null) {
                            throw new IllegalArgumentException(
                                    "Cannot use method as factory method: " + method);
                        }
                        return new EnumClassFactory(idFactory, fromIdMethod);
                    } catch (NoSuchMethodException e) {
                        throw new IllegalArgumentException(
                                "fromId method is not found for " + enumeration.getName());
                    }
                }
            }
            TypeFactory factoryT = getInferred(returnType);
            if (factoryT == null) {
                throw new IllegalArgumentException("Unsupported return type for " + method);
            }
            return factoryT;
        }
    }
}

From source file:net.paoding.rose.jade.statement.JdbcStatement.java

public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters,
        Querier querier) {/*from ww  w  . j  a v a  2 s .  com*/
    this.metaData = statementMetaData;
    this.interpreters = (interpreters == null) ? new Interpreter[0] : interpreters;
    this.querier = querier;
    this.sqlType = sqlType;
    if (sqlType == SQLType.WRITE) {
        Method method = statementMetaData.getMethod();
        Class<?>[] types = method.getParameterTypes();
        Class<?> returnType = method.getReturnType();
        if (returnType.isPrimitive()) {
            returnType = ClassUtils.primitiveToWrapper(returnType);
        }
        if (types.length > 0 && List.class.isAssignableFrom(types[0])) {
            this.batchUpdate = true;
            if (returnType != void.class && returnType != int[].class && returnType != Integer[].class
                    && returnType != Integer.class) {
                throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName()
                        + "#" + method.getName() + "-->" + returnType);
            }
        } else {
            this.batchUpdate = false;
            if (Number.class.isAssignableFrom(returnType)) {
                throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName()
                        + "#" + method.getName() + "-->" + returnType);
            }
        }
    } else {
        this.batchUpdate = false;
    }
}

From source file:com.laxser.blitz.lama.provider.jdbc.PreparedStatementCallbackReturnId.java

public PreparedStatementCallbackReturnId(PreparedStatementSetter setter, Class<?> returnType) {
    this.setter = setter;
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }/*from  ww  w.j  a  v  a2s . c  o m*/
    this.returnType = returnType;
    Class<?> idType = returnType;
    if (returnType.isArray()) {
        idType = returnType.getComponentType();
    }
    this.idType = idType;
    if (idType.isPrimitive()) {
        idType = ClassUtils.primitiveToWrapper(idType);
    }
    this.wrappedIdType = idType;
    this.mapper = new SingleColumnRowMapper(idType);
    if (wrappedIdType != Integer.class && wrappedIdType != Long.class) {
        throw new IllegalArgumentException(
                "wrong return type(int/long type or its array type only): " + returnType);
    }
}

From source file:com.wantscart.jade.provider.jdbc.PreparedStatementCallbackReturnId.java

public PreparedStatementCallbackReturnId(PreparedStatementSetter setter, Class<?> returnType) {
    this.setter = setter;
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }/*from   w  w w. j av  a2  s. co m*/
    this.returnType = returnType;
    Class<?> idType = returnType;
    if (returnType.isArray()) {
        idType = returnType.getComponentType();
    }
    this.idType = idType;
    if (idType.isPrimitive()) {
        idType = ClassUtils.primitiveToWrapper(idType);
    }
    this.wrappedIdType = idType;
    this.mapper = new SingleColumnRowMapper(idType);
    if (wrappedIdType != Integer.class && wrappedIdType != Long.class && wrappedIdType != Number.class) {
        throw new IllegalArgumentException(
                "wrong return type(int/long type or its array type only): " + returnType);
    }
}

From source file:com.sinosoft.one.data.jade.statement.JdbcStatement.java

public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters,
        Querier querier) {//from   ww w. j a v a2  s .  c  o  m
    this.metaData = statementMetaData;
    this.interpreters = (interpreters == null) ? new Interpreter[0] : interpreters;
    this.querier = querier;
    this.sqlType = sqlType;
    if (sqlType == SQLType.WRITE) {
        Method method = statementMetaData.getMethod();
        Class<?>[] types = method.getParameterTypes();
        Class<?> returnType = method.getReturnType();
        if (returnType.isPrimitive()) {
            returnType = ClassUtils.primitiveToWrapper(returnType);
        }
        if (types.length > 0 && List.class.isAssignableFrom(types[0])) {
            this.batchUpdate = true;
            if (returnType != void.class && returnType != int[].class && returnType != Integer[].class
                    && returnType != Integer.class) {
                throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName()
                        + "#" + method.getName() + "-->" + returnType);
            }
        } else {
            this.batchUpdate = false;
            if (returnType != void.class && returnType != Boolean.class
                    && !Number.class.isAssignableFrom(returnType)) {
                throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName()
                        + "#" + method.getName() + "-->" + returnType);
            }
        }
    } else {
        this.batchUpdate = false;
    }
}

From source file:com.gzj.tulip.jade.statement.UpdateQuerier.java

public UpdateQuerier(DataAccessFactory dataAccessFactory, StatementMetaData metaData) {
    this.dataAccessFactory = dataAccessFactory;
    // ?//  w  w  w .  j ava 2 s .  c  o  m
    Class<?> returnType = metaData.getReturnType();
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }
    this.returnType = returnType;
    this.returnGeneratedKeys = metaData.getReturnGeneratedKeys();
}

From source file:net.paoding.rose.jade.statement.UpdateQuerier.java

public UpdateQuerier(DataAccessFactory dataAccessProvider, StatementMetaData metaData) {
    this.dataAccessProvider = dataAccessProvider;
    Method method = metaData.getMethod();
    // ?/*from   w  ww . j  a  v a 2 s .  co  m*/
    Class<?> returnType = method.getReturnType();
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }
    this.returnType = returnType;
    if (returnType != void.class && (method.isAnnotationPresent(ReturnGeneratedKeys.class))) {
        returnGeneratedKeys = true;
    } else {
        returnGeneratedKeys = false;
    }
}

From source file:br.com.renatoccosta.regexrenamer.view.ElementParametersTableModel.java

public Class<?> getCellClass(int rowIndex, int columnIndex) {
    if (columnIndex == 1) {
        //column values
        return ClassUtils.primitiveToWrapper(params[rowIndex].getField().getType());
    } else {/* ww w  .java 2  s.c o  m*/
        //column titles
        return String.class;
    }
}

From source file:com.sinosoft.one.data.jade.statement.UpdateQuerier.java

public UpdateQuerier(EntityManager em, StatementMetaData metaData) {
    this.em = em;
    Method method = metaData.getMethod();
    // ?/*from w  w  w . j  a  va  2s.  c om*/
    Class<?> returnType = method.getReturnType();
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }
    this.returnType = returnType;
    if (returnType == Identity.class
            || (returnType != void.class && (method.isAnnotationPresent(ReturnGeneratedKeys.class)))) {
        returnGeneratedKeys = true;
    } else {
        returnGeneratedKeys = false;
    }
}