Package org.apache.commons.beanutils

Examples of org.apache.commons.beanutils.BeanUtilsBean


    // Configure a bean util that throws exceptions during type conversion
    //
    ConvertUtilsBean convertUtil = new ConvertUtilsBean();
    convertUtil.register( true, true, 0 );

    typeConvertingBeanUtil = new BeanUtilsBean( convertUtil );
    setDefaultCallback( new EagerFailingCallback() );
  }
View Full Code Here


        cub.register(new RelaxedStringArrayConverter(), String[].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;

        final BeanUtilsBean beanUtils = createBeanUtilsBean();

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

        for (final String key : attributes) {
            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 (final 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
    {
        final BeanUtilsBean beanUtils = createBeanUtilsBean();

        // TODO: debug log messages
        final Collection<String> attributes = aContext.getAttributeNames();

        for (final String key : attributes) {
            final Object value = aContext.get(key);

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

        // Clear WrapDynaClass cache
        WrapDynaClass.clear();

        // replace the existing BeanUtilsBean instance for the current class loader with a new, clean instance
        BeanUtilsBean.setInstance(new BeanUtilsBean());

        // replace the existing LocaleBeanUtilsBean instance for the current class loader with a new, clean instance
        LocaleBeanUtilsBean.setInstance(new LocaleBeanUtilsBean());
    }
View Full Code Here

     */
    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

    private BeanUtilsBean instance;
    private DummyBean testBean;

    @Override
    protected void setUp() throws Exception {
        instance = new BeanUtilsBean();
        testBean = new DummyBean();
    }
View Full Code Here

    public void testDigester()
        throws IOException, SAXException
    {
        PropertyUtilsBean propertyUtils = new MyPropertyUtilsBean();
        ConvertUtilsBean convertUtils = new ConvertUtilsBean();
        BeanUtilsBean beanUtils = new BeanUtilsBean( convertUtils, propertyUtils );
        BeanUtilsBean.setInstance( beanUtils );

        final String xml = "<myclass flag='true' />";
        final Digester digester = new Digester();
        digester.addObjectCreate( "myclass", MyClass.class );
View Full Code Here

        if (isPrimitiveOrString(fromBean)) {
            return fromBean;
        }

        BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();

        if (isCollectionType(fromBean.getClass())) {
            toBean = (T) createNewCollection(fromBean.getClass(), fromBean);
            return toBean;
        }

        List<String> ignoreList = Lists.newArrayList(ignoreProperties);

        Map<String, Object> propertiesMap =
                beanUtilsBean.getPropertyUtils().describe(fromBean);

        for (Map.Entry<String, Object> entry : propertiesMap.entrySet()) {
            String property = entry.getKey();
            Object value = entry.getValue();

            if (!shouldCopy(beanUtilsBean.getPropertyUtils(), toBean, property,
                    ignoreList)) {
                continue;
            }

            if (value != null && isJPACopyProperty(fromBean, property)) {
View Full Code Here

          } else {
            // instance is null for anonymous class, use default type
          }
        } catch (NoSuchFieldException e1) {
            try {
                BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();
                PropertyUtilsBean propertyUtils = beanUtilsBean.getPropertyUtils();
                return propertyUtils.getPropertyType(instance, propertyName);                   
            } catch (Exception e2) {
                // nothing
            }
        } catch (Exception e) {
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.