Example usage for org.apache.commons.beanutils PropertyUtils setProperty

List of usage examples for org.apache.commons.beanutils PropertyUtils setProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils setProperty.

Prototype

public static void setProperty(Object bean, String name, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

For more details see PropertyUtilsBean.

Usage

From source file:net.sourceforge.vulcan.web.struts.forms.PluginConfigForm.java

private void restorePasswordIfNecessary(String propertyName) {
    try {//w w w  .  j  av  a  2  s .c o  m
        final String submittedPassword = (String) PropertyUtils.getProperty(this, propertyName);
        if (HIDDEN_PASSWORD_VALUE.equals(submittedPassword)) {
            PropertyUtils.setProperty(this, propertyName, hiddenPasswords.get(propertyName));
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        log.error("Exception accessing configuration data", e);
    }
}

From source file:nl.nn.adapterframework.jms.JmsRealm.java

/**
 * copies matching properties to any other class
 *///w  ww . j  a va2  s  .  c o m
public void copyRealm(Object destination) {
    String logPrefixDest = destination.getClass().getName() + " ";
    if (destination instanceof INamedObject) {
        INamedObject namedDestination = (INamedObject) destination;
        logPrefixDest += "[" + namedDestination.getName() + "] ";
    }
    try {
        BeanMap thisBeanMap = new BeanMap(this);
        BeanMap destinationBeanMap = new BeanMap(destination);
        Iterator<String> iterator = thisBeanMap.keyIterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            Object value = thisBeanMap.get(key);
            if (value != null && !key.equals("class") && destinationBeanMap.containsKey(key)) {
                PropertyUtils.setProperty(destination, key, value);
            }
        }
    } catch (Exception e) {
        log.error(logPrefixDest + "unable to copy properties of JmsRealm", e);
    }
    log.info(logPrefixDest + "loaded properties from jmsRealm [" + toString() + "]");
}

From source file:nl.strohalm.cyclos.utils.binding.MapBean.java

public void remove(final String name, final String key) {
    final Object value = this.get(name);
    if (value != null) {
        if (value instanceof DynaBean) {
            ((DynaBean) value).set(key, null);
        } else {//w  ww .j a  v a  2  s  .  c o m
            try {
                PropertyUtils.setProperty(value, key, null);
            } catch (final Exception e) {
                // Keep on
            }
        }
    }
}

From source file:nl.strohalm.cyclos.utils.binding.MapBean.java

public void set(final String name, final String key, final Object value) {
    final Object bean = this.get(name);
    if (bean != null) {
        if (bean instanceof DynaBean) {
            ((DynaBean) bean).set(key, value);
        } else {/*from   w  ww  . ja  va  2s .  co m*/
            try {
                PropertyUtils.setProperty(bean, key, value);
            } catch (final Exception e) {
                // Keep on
            }
        }
    }
}

From source file:nl.strohalm.cyclos.utils.PropertyHelper.java

/**
 * Sets a property value by reflection, handling nested nulls
 *///from  ww w .ja  v a2  s .co  m
public static void set(final Object object, final String property, final Object value) {
    if (object == null) {
        return;
    }
    try {
        PropertyUtils.setProperty(object, property, value);
    } catch (final NullValueInNestedPathException e) {
        // Ignore... we just had a null
    } catch (final Exception e) {
        throw new PropertyException(object, property, e);
    }
}

From source file:nl.tue.bimserver.citygml.CityGmlSerializer.java

private <T extends AbstractCityObject> T buildBoundarySurface(IfcProduct ifcProduct, T cityObject)
        throws SerializerException {
    setName(cityObject.getName(), ifcProduct.getName());
    setGlobalId(cityObject, ifcProduct);

    MultiSurface multiSurface = gml.createMultiSurface();

    {/*from w  w  w.j ava 2  s . c  o  m*/
        CompositeSurface compositeSurface = gml.createCompositeSurface();
        setGeometry(compositeSurface, ifcProduct);
        materialManager.assign(compositeSurface, ifcProduct);
        multiSurface.addSurfaceMember(gml.createSurfaceProperty(compositeSurface));
    }

    LinkedList<IfcObjectDefinition> decompose = new LinkedList<IfcObjectDefinition>(
            Collections.singletonList(ifcProduct));
    while (!decompose.isEmpty()) {
        for (IfcRelDecomposes ifcRelDecomposes : decompose.removeFirst().getIsDecomposedBy()) {
            for (IfcObjectDefinition ifcObjectDef : ifcRelDecomposes.getRelatedObjects()) {
                CompositeSurface compositeSurface = gml.createCompositeSurface();
                setGeometry(compositeSurface, ifcObjectDef);
                materialManager.assign(compositeSurface, ifcObjectDef);
                multiSurface.addSurfaceMember(gml.createSurfaceProperty(compositeSurface));
                decompose.add(ifcObjectDef);
            }
        }
    }

    MultiSurfaceProperty multiSurfaceProperty = gml.createMultiSurfaceProperty(multiSurface);
    try {
        if (PropertyUtils.isWriteable(cityObject, "lod4MultiSurface")) {
            PropertyUtils.setProperty(cityObject, "lod4MultiSurface", multiSurfaceProperty);
        } else {
            PropertyUtils.setProperty(cityObject, "lod4Geometry", multiSurfaceProperty);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return cityObject;
}

From source file:no.abmu.finances.domain.DomainTestHelper.java

public static Object populateBean(Object obj)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(obj);

    for (int i = 0; i < propertyDescriptors.length; i++) {
        PropertyDescriptor propertyDescriptor = propertyDescriptors[i];

        if (propertyDescriptor.getName().equals("id")) {
            continue;
        }//from  w w  w  .j a va2  s.c om
        if (P_TYPES.contains(propertyDescriptor.getPropertyType())
                && propertyDescriptor.getWriteMethod() != null) {

            Object obje;
            obje = ConvertUtils.convert(
                    String.valueOf((int) (System.currentTimeMillis() + (int) (Math.random() * 100d))),
                    propertyDescriptor.getPropertyType());
            PropertyUtils.setProperty(obj, propertyDescriptor.getName(), obje);
        }
    }
    return obj;
}

From source file:no.abmu.test.domainmodels.DomainTestHelper.java

public static Object populateBean(Object obj)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(obj);

    for (int i = 0; i < propertyDescriptors.length; i++) {
        PropertyDescriptor propertyDescriptor = propertyDescriptors[i];

        if (propertyDescriptor.getName().equals("id")) {
            continue;
        } else if (propertyDescriptor.getName().equals("valueAsString")) {
            continue;
        } else if (P_TYPES.contains(propertyDescriptor.getPropertyType())
                && propertyDescriptor.getWriteMethod() != null) {

            Object obje;/*from   w w  w  . jav  a  2 s .co  m*/
            //                obje=ConvertUtils.convert(String.valueOf(System.currentTimeMillis()
            //                +(long)(Math.random()*100d)),propertyDescriptor.getPropertyType());
            obje = ConvertUtils.convert(
                    String.valueOf((int) (System.currentTimeMillis() + (int) (Math.random() * 100d))),
                    propertyDescriptor.getPropertyType());
            PropertyUtils.setProperty(obj, propertyDescriptor.getName(), obje);
        }
    }
    return obj;
}

From source file:no.abmu.test.utilh3.DomainTestHelper.java

public static Object populateBean(Object obj)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(obj);

    for (int i = 0; i < propertyDescriptors.length; i++) {
        PropertyDescriptor propertyDescriptor = propertyDescriptors[i];

        if (propertyDescriptor.getName().equals("id")) {
            continue;
        } else if (propertyDescriptor.getName().equals("valueAsString")) {
            continue;
        } else if (P_TYPES.contains(propertyDescriptor.getPropertyType())
                && propertyDescriptor.getWriteMethod() != null) {
            Object obje;/*w  w w .  jav  a2 s  .c  om*/
            //                obje=ConvertUtils.convert(String.valueOf(System.currentTimeMillis()
            //                +(long)(Math.random()*100d)),propertyDescriptor.getPropertyType());
            obje = ConvertUtils.convert(
                    String.valueOf((int) (System.currentTimeMillis() + (int) (Math.random() * 100d))),
                    propertyDescriptor.getPropertyType());
            PropertyUtils.setProperty(obj, propertyDescriptor.getName(), obje);
        }
    }
    return obj;
}

From source file:nz.co.senanque.messaging.GenericEndpoint.java

private void unpackRoot(Element element, Object context) {
    ValidationSessionHolder validationSessonHolder = new ValidationSessionHolderImpl(getValidationEngine());
    validationSessonHolder.bind(context);
    try {//from w  ww  . j  av  a  2s . com
        @SuppressWarnings("unchecked")
        Iterator<Text> itr = (Iterator<Text>) element
                .getDescendants(new ContentFilter(ContentFilter.TEXT | ContentFilter.CDATA));
        while (itr.hasNext()) {
            Text text = itr.next();

            String name = getName(text);
            if (name.equals("id") || name.equals("version")) {
                continue;
            }
            try {
                Class<?> targetType = PropertyUtils.getPropertyType(context, name);
                Object value = ConvertUtils.convert(text.getValue(), targetType);
                PropertyUtils.setProperty(context, name, value);
                log.debug("name {} value {}", name, text.getValue());
            } catch (IllegalAccessException e) {
                // Ignore these and move on
                log.debug("{} {}", name, e.getMessage());
            } catch (InvocationTargetException e) {
                // Ignore these and move on
                log.debug("{} {}", name, e.getTargetException().toString());
            } catch (NoSuchMethodException e) {
                // Ignore these and move on
                log.debug("{} {}", name, e.getMessage());
            }
        }
    } finally {
        validationSessonHolder.close();
    }
}