public void copyProperties()

in src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java [216:285]


    public void copyProperties(final Object dest, final Object orig)
            throws IllegalAccessException, InvocationTargetException,
            // TODO BEFORE 2.0
            // MISMATCH between implementation and Javadoc.
        NoSuchMethodException {
        if (dest == null) {
            throw new IllegalArgumentException("No destination bean specified");
        }
        if (orig == null) {
            throw new IllegalArgumentException("No origin bean specified");
        }

        if (orig instanceof DynaBean) {
            final DynaProperty[] origDescriptors = ((DynaBean) orig).getDynaClass().getDynaProperties();
            for (final DynaProperty origDescriptor : origDescriptors) {
                final String name = origDescriptor.getName();
                if (isReadable(orig, name) && isWriteable(dest, name)) {
                    try {
                        final Object value = ((DynaBean) orig).get(name);
                        if (dest instanceof DynaBean) {
                            ((DynaBean) dest).set(name, value);
                        } else {
                            setSimpleProperty(dest, name, value);
                        }
                    } catch (final NoSuchMethodException e) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Error writing to '" + name + "' on class '" + dest.getClass() + "'", e);
                        }
                    }
                }
            }
        } else if (orig instanceof Map) {
            for (final Map.Entry<?, ?> entry : ((Map<?, ?>) orig).entrySet()) {
                final String name = (String) entry.getKey();
                if (isWriteable(dest, name)) {
                    try {
                        if (dest instanceof DynaBean) {
                            ((DynaBean) dest).set(name, entry.getValue());
                        } else {
                            setSimpleProperty(dest, name, entry.getValue());
                        }
                    } catch (final NoSuchMethodException e) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Error writing to '" + name + "' on class '" + dest.getClass() + "'", e);
                        }
                    }
                }
            }
        } else /* if (orig is a standard JavaBean) */ {
            final PropertyDescriptor[] origDescriptors = getPropertyDescriptors(orig);
            for (final PropertyDescriptor origDescriptor : origDescriptors) {
                final String name = origDescriptor.getName();
                if (isReadable(orig, name) && isWriteable(dest, name)) {
                    try {
                        final Object value = getSimpleProperty(orig, name);
                        if (dest instanceof DynaBean) {
                            ((DynaBean) dest).set(name, value);
                        } else {
                            setSimpleProperty(dest, name, value);
                        }
                    } catch (final NoSuchMethodException e) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Error writing to '" + name + "' on class '" + dest.getClass() + "'", e);
                        }
                    }
                }
            }
        }

    }