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:de.openknowledge.cdi.common.property.PropertiesLoader.java

/**
 * Creates an object, assuming the object has a constructor that takes a {@link String} argument.
 * The type of the object is determined from the type of the specified injection point.
 * The value for the constructor argument of type {@link String} is taken from the {@link Property}
 * specified at the injection point.//from   w w w.ja  v a 2  s.c o m
 * 
 * @param injectionPoint the injection point to get the type and the property from
 * @return the value which's type depends on the type of the injection point
 */
@Produces
@Property(name = "any")
public Object produceProperty(InjectionPoint injectionPoint) {
    Class<?> type = toClass(injectionPoint.getType());
    return newInstance(injectionPoint, getPropertyValue(injectionPoint, type),
            ClassUtils.primitiveToWrapper(type));
}

From source file:br.gov.frameworkdemoiselle.internal.implementation.ConfigurationPrimitiveOrWrapperValueExtractor.java

@Override
@SuppressWarnings("unchecked")
public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception {
    Object value;/*from   ww  w. j  a  va  2 s  .  c  o  m*/

    try {
        value = new DataConfiguration(configuration).get(ClassUtils.primitiveToWrapper(field.getType()),
                prefix + key);

    } catch (ConversionException cause) {
        throw cause;
    }

    return value;
}

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

public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters,
        Querier querier) {/*from  w  w w. j a  v  a2 s.  c  om*/
    this.metaData = statementMetaData;
    AfterInvocation afterInvocationAnnotation = metaData.getMethod().getAnnotation(AfterInvocation.class);
    if (afterInvocationAnnotation != null) {
        try {
            this.afterInvocationCallback = afterInvocationAnnotation.value().newInstance();
        } catch (InstantiationException e) {
            throw new IllegalArgumentException(e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException(e);
        }
    } else {
        this.afterInvocationCallback = nullAfterInvocationCallback;
    }
    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 = statementMetaData.getReturnType();
        if (returnType.isPrimitive()) {
            returnType = ClassUtils.primitiveToWrapper(returnType);
        }

        //change by guozijian 2016-2-09-29
        //?SQL???
        //???updateinsert???
        SQL sqlAnnotation = method.getAnnotation(SQL.class);
        if (types.length > 0 && List.class.isAssignableFrom(types[0]) && (sqlAnnotation == null // @SQL
                || StringUtils.isBlank(sqlAnnotation.value()))) // SQL
        {
            //TODO ?List?????
            //if (types.length > 0 && List.class.isAssignableFrom(types[0])) {
            this.batchUpdate = true;
            if (metaData.getMethod().getAnnotation(ReturnGeneratedKeys.class) != null) {
                // ????@ReturnGeneratedKeys
                throw new InvalidDataAccessApiUsageException(
                        "batch update method cannot return generated keys: " + method);
            }
            if (returnType != void.class && returnType != int[].class //
                    && returnType != Integer.class && returnType != Boolean.class) {
                throw new InvalidDataAccessApiUsageException(
                        "error return type, only support type of {void,boolean,int,int[]}: " + method);
            }
        } else {
            this.batchUpdate = false;
            if (metaData.getMethod().getAnnotation(ReturnGeneratedKeys.class) != null) {
                metaData.getReturnGeneratedKeys().checkMethodReturnType(metaData.getReturnType(), metaData);
            } else if (returnType != void.class && returnType != Boolean.class && returnType != Integer.class) {
                throw new InvalidDataAccessApiUsageException(
                        "error return type, only support type of {void,boolean,int}:" + method);
            }
        }
    } else {
        this.batchUpdate = false;
    }
    this.logPrefix = "\n @method:" + this.metaData;
}

From source file:com.wantscart.jade.core.RowMapperFactoryImpl.java

@Override
public RowMapper getRowMapper(Modifier modifier) {
    RowHandler rowHandler = modifier.getAnnotation(RowHandler.class);
    if (rowHandler != null) {
        if (rowHandler.rowMapper() != RowHandler.ByDefault.class) {
            try {
                RowMapper rowMapper = rowHandler.rowMapper().newInstance();
                if (logger.isInfoEnabled()) {
                    logger.info("using rowMapper " + rowMapper + " for " + modifier);
                }/*from   w ww.  j a  v a  2 s  . c o  m*/

                return rowMapper;
            } catch (Exception ex) {
                throw new BeanInstantiationException(rowHandler.rowMapper(), ex.getMessage(), ex);
            }
        }
    }
    //

    Class<?> returnClassType = modifier.getReturnType();
    Class<?> rowType = getRowType(modifier);

    // BUGFIX: SingleColumnRowMapper ?  Primitive Type 
    if (rowType.isPrimitive()) {
        rowType = ClassUtils.primitiveToWrapper(rowType);
    }

    // ?  RowMapper
    RowMapper rowMapper;

    // ?(?2Map)
    if (TypeUtils.isColumnType(rowType)) {
        if (returnClassType == Map.class) {
            rowMapper = new MapEntryColumnRowMapper(modifier, rowType);
        } else {
            rowMapper = new SingleColumnRowMapper(rowType);
        }
    }
    // Bean??????
    else {
        if (rowType == Map.class) {
            rowMapper = new ColumnMapRowMapper();
        } else if (rowType.isArray()) {
            rowMapper = new ArrayRowMapper(rowType);
        } else if ((rowType == List.class) || (rowType == Collection.class)) {
            rowMapper = new ListRowMapper(modifier);
        } else if (rowType == Set.class) {
            rowMapper = new SetRowMapper(modifier);
        } else {
            boolean checkColumns = (rowHandler == null) ? false : rowHandler.checkColumns();
            boolean checkProperties = (rowHandler == null) ? false : rowHandler.checkProperties();
            String key = rowType.getName() + "[checkColumns=" + checkColumns + "&checkProperties="
                    + checkProperties + "]";
            rowMapper = rowMappers.get(key);
            if (rowMapper == null) {
                rowMapper = new BeanPropertyRowMapper(rowType, checkColumns, checkProperties); // jade's BeanPropertyRowMapper here
                rowMappers.put(key, rowMapper);
            }
        }
        // DAOMaprowMapper?Map.Entry
        if (returnClassType == Map.class) {
            rowMapper = new MapEntryRowMapper(modifier, rowMapper);
        }
    }

    if (logger.isInfoEnabled()) {
        logger.info("using rowMapper " + rowMapper + " for " + modifier);
    }

    return rowMapper;
}

From source file:io.cloudslang.lang.entities.bindings.values.PyObjectValueProxyFactory.java

@SuppressWarnings("unchecked")
private static Object getParamDefaultValue(PyObject pyObject, Class<?> parameterType) throws Exception {
    if (parameterType.equals(PyType.class)) {
        return pyObject.getType();
    } else if (parameterType.isPrimitive()) {
        return ClassUtils.primitiveToWrapper(parameterType).getConstructor(String.class).newInstance("0");
    } else if (Number.class.isAssignableFrom(parameterType) || String.class.isAssignableFrom(parameterType)) {
        return parameterType.getConstructor(String.class).newInstance("0");
    } else {//from   w w w . j  a va2  s  . c om
        return null;
    }
}

From source file:net.paoding.rose.jade.rowmapper.DefaultRowMapperFactory.java

@Override
public RowMapper getRowMapper(StatementMetaData modifier) {
    RowHandler rowHandler = modifier.getAnnotation(RowHandler.class);
    if (rowHandler != null) {
        if (rowHandler.rowMapper() != RowHandler.ByDefault.class) {
            try {
                RowMapper rowMapper = rowHandler.rowMapper().newInstance();
                if (logger.isInfoEnabled()) {
                    logger.info("using rowMapper " + rowMapper + " for " + modifier);
                }/*from w ww .  jav  a2  s  . c  om*/

                return rowMapper;
            } catch (Exception ex) {
                throw new BeanInstantiationException(rowHandler.rowMapper(), ex.getMessage(), ex);
            }
        }
    }
    //

    Class<?> returnClassType = modifier.getMethod().getReturnType();
    Class<?> rowType = getRowType(modifier);

    // BUGFIX: SingleColumnRowMapper ?  Primitive Type 
    if (rowType.isPrimitive()) {
        rowType = ClassUtils.primitiveToWrapper(rowType);
    }

    // ?  RowMapper
    RowMapper rowMapper;

    // ?(?2Map)
    if (TypeUtils.isColumnType(rowType)) {
        if (returnClassType == Map.class) {
            rowMapper = new MapEntryColumnRowMapper(modifier, rowType);
        } else {
            rowMapper = new SingleColumnRowMapper(rowType);
        }
    }
    // Bean??????
    else {
        if (rowType == Map.class) {
            rowMapper = new ColumnMapRowMapper();
        } else if (rowType.isArray()) {
            rowMapper = new ArrayRowMapper(rowType);
        } else if ((rowType == List.class) || (rowType == Collection.class)) {
            rowMapper = new ListRowMapper(modifier);
        } else if (rowType == Set.class) {
            rowMapper = new SetRowMapper(modifier);
        } else {
            boolean checkColumns = (rowHandler == null) ? true : rowHandler.checkColumns();
            boolean checkProperties = (rowHandler == null) ? false : rowHandler.checkProperties();
            String key = rowType.getName() + "[checkColumns=" + checkColumns + "&checkProperties="
                    + checkProperties + "]";
            rowMapper = rowMappers.get(key);
            if (rowMapper == null) {
                rowMapper = new BeanPropertyRowMapper(rowType, checkColumns, checkProperties); // jade's BeanPropertyRowMapper here
                rowMappers.put(key, rowMapper);
            }
        }
        // DAOMaprowMapper?Map.Entry
        if (returnClassType == Map.class) {
            rowMapper = new MapEntryRowMapper(modifier, rowMapper);
        }
    }

    if (logger.isInfoEnabled()) {
        logger.info("using rowMapper " + rowMapper + " for " + modifier);
    }

    return rowMapper;
}

From source file:com.sinosoft.one.data.jade.rowmapper.DefaultRowMapperFactory.java

public RowMapper getRowMapper(StatementMetaData modifier) {
    RowHandler rowHandler = modifier.getAnnotation(RowHandler.class);
    if (rowHandler != null) {
        if (rowHandler.rowMapper() != RowHandler.ByDefault.class) {
            try {
                RowMapper rowMapper = rowHandler.rowMapper().newInstance();
                if (logger.isInfoEnabled()) {
                    logger.info("using rowMapper " + rowMapper + " for " + modifier);
                }//from  ww w  .  j a  va 2  s  . co  m

                return rowMapper;
            } catch (Exception ex) {
                throw new BeanInstantiationException(rowHandler.rowMapper(), ex.getMessage(), ex);
            }
        }
    }
    //

    Class<?> returnClassType = modifier.getMethod().getReturnType();
    Class<?> rowType = getRowType(modifier);

    // BUGFIX: SingleColumnRowMapper ?  Primitive Type 
    if (rowType.isPrimitive()) {
        rowType = ClassUtils.primitiveToWrapper(rowType);
    }

    // ?  RowMapper
    RowMapper rowMapper;

    // ?(?2Map)
    if (TypeUtils.isColumnType(rowType)) {
        if (returnClassType == Map.class) {
            rowMapper = new MapEntryColumnRowMapper(modifier, rowType);
        } else {
            rowMapper = new SingleColumnRowMapper(rowType);
        }
    }
    // Bean??????
    else {
        if (rowType == Map.class) {
            rowMapper = new ColumnMapRowMapper();
        } else if (rowType.isArray()) {
            rowMapper = new ArrayRowMapper(rowType);
        } else if ((rowType == List.class) || (rowType == Collection.class)) {
            rowMapper = new ListRowMapper(modifier);
        } else if (rowType == Set.class) {
            rowMapper = new SetRowMapper(modifier);
        } else {
            boolean checkColumns = (rowHandler == null) ? false : rowHandler.checkColumns();
            boolean checkProperties = (rowHandler == null) ? false : rowHandler.checkProperties();
            String key = rowType.getName() + "[checkColumns=" + checkColumns + "&checkProperties="
                    + checkProperties + "]";
            rowMapper = rowMappers.get(key);
            if (rowMapper == null) {
                rowMapper = new BeanPropertyRowMapper(rowType, checkColumns, checkProperties); // jade's BeanPropertyRowMapper here
                rowMappers.put(key, rowMapper);
            }
        }
        // DAOMaprowMapper?Map.Entry
        if (returnClassType == Map.class) {
            rowMapper = new MapEntryRowMapper(modifier, rowMapper);
        }
    }

    if (logger.isInfoEnabled()) {
        logger.info("using rowMapper " + rowMapper + " for " + modifier);
    }

    return rowMapper;
}

From source file:com.laxser.blitz.lama.core.RowMapperFactoryImpl.java

@Override
public RowMapper getRowMapper(Modifier modifier) {
    RowHandler rowHandler = modifier.getAnnotation(RowHandler.class);
    if (rowHandler != null) {
        if (rowHandler.rowMapper() != RowHandler.ByDefault.class) {
            try {
                RowMapper rowMapper = rowHandler.rowMapper().newInstance();
                if (logger.isInfoEnabled()) {
                    logger.info("using rowMapper " + rowMapper + " for " + modifier);
                }/*from   www .ja va  2 s .  c om*/

                return rowMapper;
            } catch (Exception ex) {
                throw new BeanInstantiationException(rowHandler.rowMapper(), ex.getMessage(), ex);
            }
        }
    }
    //

    Class<?> returnClassType = modifier.getReturnType();
    Class<?> rowType = getRowType(modifier);

    // BUGFIX: SingleColumnRowMapper ?  Primitive Type 
    if (rowType.isPrimitive()) {
        rowType = ClassUtils.primitiveToWrapper(rowType);
    }

    // ?  RowMapper
    RowMapper rowMapper;

    // ?(?2Map)
    if (TypeUtils.isColumnType(rowType)) {
        if (returnClassType == Map.class) {
            rowMapper = new MapEntryColumnRowMapper(modifier, rowType);
        } else {
            rowMapper = new SingleColumnRowMapper(rowType);
        }
    }
    // Bean??????
    else {
        if (rowType == Map.class) {
            rowMapper = new ColumnMapRowMapper();
        } else if (rowType.isArray()) {
            rowMapper = new ArrayRowMapper(rowType);
        } else if ((rowType == List.class) || (rowType == Collection.class)) {
            rowMapper = new ListRowMapper(modifier);
        } else if (rowType == Set.class) {
            rowMapper = new SetRowMapper(modifier);
        } else {
            boolean checkColumns = (rowHandler == null) ? true : rowHandler.checkColumns();
            boolean checkProperties = (rowHandler == null) ? false : rowHandler.checkProperties();
            String key = rowType.getName() + "[checkColumns=" + checkColumns + "&checkProperties="
                    + checkProperties + "]";
            rowMapper = rowMappers.get(key);
            if (rowMapper == null) {
                rowMapper = new BeanPropertyRowMapper(rowType, checkColumns, checkProperties); // jade's BeanPropertyRowMapper here
                rowMappers.put(key, rowMapper);
            }
        }
        // DAOMaprowMapper?Map.Entry
        if (returnClassType == Map.class) {
            rowMapper = new MapEntryRowMapper(modifier, rowMapper);
        }
    }

    if (logger.isInfoEnabled()) {
        logger.info("using rowMapper " + rowMapper + " for " + modifier);
    }

    return rowMapper;
}

From source file:com.gzj.tulip.jade.rowmapper.DefaultRowMapperFactory.java

@Override
public RowMapper getRowMapper(StatementMetaData smd) {
    RowHandler rowHandler = smd.getAnnotation(RowHandler.class);

    // ?  RowMapper
    RowMapper rowMapper = null;//from  w  w  w .ja  v a2  s  . com

    if (rowHandler != null) {
        if (rowHandler.rowMapper() != RowHandler.NotSettingRowMapper.class) {
            try {
                rowMapper = rowHandler.rowMapper().newInstance();
            } catch (Exception ex) {
                throw new BeanInstantiationException(rowHandler.rowMapper(), ex.getMessage(), ex);
            }
        } else if (rowHandler.rowMapperFactory() != RowHandler.NotSettingRowMapperFactory.class) {
            try {
                RowMapperFactory rowMapperFactory = rowHandler.rowMapperFactory().newInstance();
                rowMapper = rowMapperFactory.getRowMapper(smd);
            } catch (Exception ex) {
                throw new BeanInstantiationException(rowHandler.rowMapper(), ex.getMessage(), ex);
            }
        }
    }
    // 
    if (rowMapper == null) {
        //

        Class<?> returnClassType = smd.getMethod().getReturnType();
        Class<?> rowType = getRowType(smd);

        // BUGFIX: SingleColumnRowMapper ?  Primitive Type 
        if (rowType.isPrimitive()) {
            rowType = ClassUtils.primitiveToWrapper(rowType);
        }

        // ?(?2Map)
        if (TypeUtils.isColumnType(rowType)) {
            if (Map.class.isAssignableFrom(returnClassType)) {
                rowMapper = new MapEntryColumnRowMapper(smd, rowType);
            } else {
                rowMapper = new SingleColumnRowMapper(rowType);
            }
        }
        // Bean??????
        else {
            if (rowType == Map.class) {
                rowMapper = new ColumnMapRowMapper();
            } else if (rowType.isArray()) {
                rowMapper = new ArrayRowMapper(rowType);
            } else if ((rowType == List.class) || (rowType == Collection.class)) {
                rowMapper = new ListRowMapper(smd);
            } else if (rowType == Set.class) {
                rowMapper = new SetRowMapper(smd);
            } else {
                boolean checkColumns = (rowHandler == null) ? true : rowHandler.checkColumns();
                boolean checkProperties = (rowHandler == null) ? false : rowHandler.checkProperties();
                String key = rowType.getName() + "[checkColumns=" + checkColumns + "&checkProperties="
                        + checkProperties + "]";
                rowMapper = rowMappers.get(key);
                if (rowMapper == null) {
                    rowMapper = new BeanPropertyRowMapper(rowType, checkColumns, checkProperties); // jade's BeanPropertyRowMapper here
                    rowMappers.put(key, rowMapper);
                }
            }
            // DAOMaprowMapper?Map.Entry
            if (Map.class.isAssignableFrom(returnClassType)) {
                rowMapper = new MapEntryRowMapper(smd, rowMapper);
            }
        }
    }

    //

    if (rowMapper instanceof StatementAware) {
        ((StatementAware) rowMapper).setStatementMetaData(smd);
    }

    if (logger.isInfoEnabled()) {
        logger.info("using rowMapper " + rowMapper + " for " + smd);
    }

    return rowMapper;
}

From source file:com.twinsoft.convertigo.engine.admin.services.database_objects.Set.java

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    Element root = document.getDocumentElement();
    Document post = null;/*  w  ww . j a  v  a2s  .  co m*/
    Element response = document.createElement("response");

    try {
        Map<String, DatabaseObject> map = com.twinsoft.convertigo.engine.admin.services.projects.Get
                .getDatabaseObjectByQName(request);

        xpath = new TwsCachedXPathAPI();
        post = XMLUtils.parseDOM(request.getInputStream());
        postElt = document.importNode(post.getFirstChild(), true);

        String objectQName = xpath.selectSingleNode(postElt, "./@qname").getNodeValue();
        DatabaseObject object = map.get(objectQName);

        //         String comment = getPropertyValue(object, "comment").toString();
        //         object.setComment(comment);

        if (object instanceof Project) {
            Project project = (Project) object;

            String objectNewName = getPropertyValue(object, "name").toString();

            Engine.theApp.databaseObjectsManager.renameProject(project, objectNewName);

            map.remove(objectQName);
            map.put(project.getQName(), project);
        }

        BeanInfo bi = CachedIntrospector.getBeanInfo(object.getClass());

        PropertyDescriptor[] propertyDescriptors = bi.getPropertyDescriptors();

        for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
            String propertyName = propertyDescriptor.getName();

            Method setter = propertyDescriptor.getWriteMethod();

            Class<?> propertyTypeClass = propertyDescriptor.getReadMethod().getReturnType();
            if (propertyTypeClass.isPrimitive()) {
                propertyTypeClass = ClassUtils.primitiveToWrapper(propertyTypeClass);
            }

            try {
                String propertyValue = getPropertyValue(object, propertyName).toString();

                Object oPropertyValue = createObject(propertyTypeClass, propertyValue);

                if (object.isCipheredProperty(propertyName)) {

                    Method getter = propertyDescriptor.getReadMethod();
                    String initialValue = (String) getter.invoke(object, (Object[]) null);

                    if (oPropertyValue.equals(initialValue)
                            || DatabaseObject.encryptPropertyValue(initialValue).equals(oPropertyValue)) {
                        oPropertyValue = initialValue;
                    } else {
                        object.hasChanged = true;
                    }
                }

                if (oPropertyValue != null) {
                    Object args[] = { oPropertyValue };
                    setter.invoke(object, args);
                }

            } catch (IllegalArgumentException e) {
            }
        }

        Engine.theApp.databaseObjectsManager.exportProject(object.getProject());
        response.setAttribute("state", "success");
        response.setAttribute("message", "Project have been successfully updated!");
    } catch (Exception e) {
        Engine.logAdmin.error("Error during saving the properties!\n" + e.getMessage());
        response.setAttribute("state", "error");
        response.setAttribute("message", "Error during saving the properties!");
        Element stackTrace = document.createElement("stackTrace");
        stackTrace.setTextContent(e.getMessage());
        root.appendChild(stackTrace);
    } finally {
        xpath.resetCache();
    }

    root.appendChild(response);
}