Package org.apache.commons.beanutils

Examples of org.apache.commons.beanutils.BeanUtilsBean


     */
    public void testBeanUtilsSetProperty_CustomConvertStringToArray_WithColonValue() throws Exception{
        ArrayConverter converter = new ArrayConverter(String[].class, new StringConverter());
        converter.setAllowedChars(new char[] {'.', '-', ':'});

        BeanUtilsBean utils = new BeanUtilsBean();
        utils.getConvertUtils().register(converter, String[].class);

        SimplePojoData simplePojo = new SimplePojoData();
        utils.setProperty(simplePojo, "jcrMixinTypes", "mix:rereferencible,mix:simple");
        showArray("Custom WithColonValue", simplePojo.getJcrMixinTypes());
        assertEquals("array size", 2, simplePojo.getJcrMixinTypes().length);
        assertEquals("mix:rereferencible", simplePojo.getJcrMixinTypes()[0]);
        assertEquals("mix:simple", simplePojo.getJcrMixinTypes()[1]);
    }
View Full Code Here


   * @return
   * @throws InvocationTargetException
   * @throws IllegalAccessException
   */
  public static Object buildEntity(BaseBO baseBO, Object obj) throws IllegalAccessException, InvocationTargetException {
    final BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();
   
    beanUtilsBean.getConvertUtils().register(new CalendarConverter( null), Calendar.class);
    beanUtilsBean.getConvertUtils().register(new IntegerConverter( null), Integer.class);
    beanUtilsBean.getConvertUtils().register(new LongConverter(null), Long.class);
   
    beanUtilsBean.copyProperties(obj, baseBO);
   
    return obj;
  }
View Full Code Here

   * @return
   * @throws InvocationTargetException
   * @throws IllegalAccessException
   */
  public static BaseBO buildBO(Object obj, BaseBO baseBO) throws IllegalAccessException, InvocationTargetException {
    final BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();
   
    beanUtilsBean.getConvertUtils().register(new CalendarConverter( null), Calendar.class);
    beanUtilsBean.getConvertUtils().register(new IntegerConverter( null), Integer.class);
    beanUtilsBean.getConvertUtils().register(new LongConverter(null), Long.class);
   
    beanUtilsBean.copyProperties(baseBO, obj);
   
    return baseBO;
  }
View Full Code Here

        cub.register(new IntegerArrayConverter(), Integer[].class);

        // BigDecimal, BigInteger, Class, Date, String, Time, TimeStamp
        // do not use defaults in the default configuration of ConvertUtilsBean

        return new BeanUtilsBean(cub, new PropertyUtilsBean());
    }
View Full Code Here

    public final void configure(Configuration aConfiguration)
        throws CheckstyleException
    {
        mConfiguration = aConfiguration;

        BeanUtilsBean beanUtils = createBeanUtilsBean();

        // TODO: debug log messages
        final String[] attributes = aConfiguration.getAttributeNames();

        for (int i = 0; i < attributes.length; i++) {
            final String key = attributes[i];
            final String value = aConfiguration.getAttribute(key);

            try {
                // BeanUtilsBean.copyProperties silently ignores missing setters
                // for key, so we have to go through great lengths here to
                // figure out if the bean property really exists.
                final PropertyDescriptor pd =
                    PropertyUtils.getPropertyDescriptor(this, key);
                if (pd == null || pd.getWriteMethod() == null) {
                    throw new CheckstyleException(
                        "Property '" + key + "' in module "
                        + aConfiguration.getName()
                        + " does not exist, please check the documentation");
                }

                // finally we can set the bean property
                beanUtils.copyProperty(this, key, value);
            }
            catch (InvocationTargetException e) {
                throw new CheckstyleException(
                    "Cannot set property '" + key + "' in module "
                    + aConfiguration.getName() + " to '" + value
View Full Code Here

     * @see Contextualizable
     */
    public final void contextualize(Context aContext)
        throws CheckstyleException
    {
        BeanUtilsBean beanUtils = createBeanUtilsBean();

        // TODO: debug log messages
        final String[] attributes = aContext.getAttributeNames();

        for (int i = 0; i < attributes.length; i++) {
            final String key = attributes[i];
            final Object value = aContext.get(key);

            try {
                beanUtils.copyProperty(this, key, value);
            }
            catch (InvocationTargetException e) {
                // TODO: log.debug("The bean " + this.getClass()
                // + " is not interested in " + value)
                throw new CheckstyleException("cannot set property "
View Full Code Here

TOP

Related Classes of org.apache.commons.beanutils.BeanUtilsBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.