// Path: src/main/java/org/azeckoski/reflectutils/ClassFields.java
// public static enum FieldsFilter {
//     /**
//      * all complete (read and write) fields,
//      * getters and setters included
//      */
//     COMPLETE, 
//     /**
//      * (default)
//      * all readable fields (may not be writeable),
//      * includes transient and virtual (getter only) fields
//      */
//     READABLE, 
//     /**
//      * all writeable fields (may not be readable),
//      * public and setters
//      */
//     WRITEABLE, 
//     /**
//      * all accessible serializable fields or getters (skips transients)
//      */
//     SERIALIZABLE,
//     /**
//      * all accessible serializable fields (skips transient fields),
//      * no virtual fields (getters only)
//      */
//     SERIALIZABLE_FIELDS,
//     /**
//      * all fields including ones that are virtual (read or write only)
//      */
//     ALL
// }
// 
// Path: src/main/java/org/azeckoski/reflectutils/exceptions/FieldnameNotFoundException.java
// public class FieldnameNotFoundException extends RuntimeException {
// 
//    public String fieldName;
// 
//    public FieldnameNotFoundException(String fieldName) {
//       this(fieldName, null);
//    }
// 
//    public FieldnameNotFoundException(String fieldName, Throwable cause) {
//       this("Could not find fieldName ("+fieldName+") on object", fieldName, cause);
//    }
// 
//    public FieldnameNotFoundException(String message, String fieldName, Throwable cause) {
//       super(message, cause);
//       this.fieldName = fieldName;
//    }
// 
// }


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.azeckoski.reflectutils.ClassFields.FieldsFilter;
import org.azeckoski.reflectutils.exceptions.FieldnameNotFoundException;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaClass;
import org.apache.commons.beanutils.DynaProperty;
/**
 * $Id: DynaBeanAdapter.java 2 2008-10-01 10:04:26Z azeckoski $
 * $URL: http://reflectutils.googlecode.com/svn/trunk/src/main/java/org/azeckoski/reflectutils/beanutils/DynaBeanAdapter.java $
 * DynaBeanAdapter.java - genericdao - Sep 20, 2008 10:08:01 AM - azeckoski
 **************************************************************************
 * Copyright (c) 2008 Aaron Zeckoski
 * Licensed under the Apache License, Version 2.0
 * 
 * A copy of the Apache License has been included in this 
 * distribution and is available at: http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * Aaron Zeckoski (azeckoski @ gmail.com) (aaronz @ vt.edu) (aaron @ caret.cam.ac.uk)
 */

package org.azeckoski.reflectutils.beanutils;





/**
 * This allows dynabeans to work with the field utils,
 * should only be loaded by reflection if the DynaBean class can be found
 * 
 * @author Aaron Zeckoski (azeckoski @ gmail.com)
 */
public class DynaBeanAdapter implements FieldAdapter {

    public boolean isAdaptableObject(Object obj) {
        boolean adaptable = false;
        if (obj instanceof DynaBean) {
            adaptable = true;
        }
        return adaptable;
    }

    public boolean isAdaptableClass(Class<?> beanClass) {
        boolean adaptable = false;
        if (DynaBean.class.isAssignableFrom(beanClass)) {
            adaptable = true;
        }
        return adaptable;
    }

    /* (non-Javadoc)
     * @see org.azeckoski.reflectutils.beanutils.FieldAdapter#getFieldType(java.lang.Object, java.lang.String)
     */
    public Class<?> getFieldType(Object obj, String name) {
        DynaClass dynaClass = ((DynaBean) obj).getDynaClass();
        DynaProperty dynaProperty = dynaClass.getDynaProperty(name);
        if (dynaProperty == null) {
            throw new FieldnameNotFoundException("DynaBean: Could not find this fieldName ("+name+") on the target object: " + obj, name, null);
        }
        return dynaProperty.getType();
    }

    /* (non-Javadoc)
     * @see org.azeckoski.reflectutils.beanutils.FieldAdapter#getFieldValues(java.lang.Object, org.azeckoski.reflectutils.ClassFields.FieldsFilter)
     */
// Path: src/main/java/org/azeckoski/reflectutils/ClassFields.java
// public static enum FieldsFilter {
//     /**
//      * all complete (read and write) fields,
//      * getters and setters included
//      */
//     COMPLETE, 
//     /**
//      * (default)
//      * all readable fields (may not be writeable),
//      * includes transient and virtual (getter only) fields
//      */
//     READABLE, 
//     /**
//      * all writeable fields (may not be readable),
//      * public and setters
//      */
//     WRITEABLE, 
//     /**
//      * all accessible serializable fields or getters (skips transients)
//      */
//     SERIALIZABLE,
//     /**
//      * all accessible serializable fields (skips transient fields),
//      * no virtual fields (getters only)
//      */
//     SERIALIZABLE_FIELDS,
//     /**
//      * all fields including ones that are virtual (read or write only)
//      */
//     ALL
// }
// 
// Path: src/main/java/org/azeckoski/reflectutils/exceptions/FieldnameNotFoundException.java
// public class FieldnameNotFoundException extends RuntimeException {
// 
//    public String fieldName;
// 
//    public FieldnameNotFoundException(String fieldName) {
//       this(fieldName, null);
//    }
// 
//    public FieldnameNotFoundException(String fieldName, Throwable cause) {
//       this("Could not find fieldName ("+fieldName+") on object", fieldName, cause);
//    }
// 
//    public FieldnameNotFoundException(String message, String fieldName, Throwable cause) {
//       super(message, cause);
//       this.fieldName = fieldName;
//    }
// 
// }


// Path: src/main/java/org/azeckoski/reflectutils/beanutils/DynaBeanAdapter.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.azeckoski.reflectutils.ClassFields.FieldsFilter;
import org.azeckoski.reflectutils.exceptions.FieldnameNotFoundException;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaClass;
import org.apache.commons.beanutils.DynaProperty;

/**
 * $Id: DynaBeanAdapter.java 2 2008-10-01 10:04:26Z azeckoski $
 * $URL: http://reflectutils.googlecode.com/svn/trunk/src/main/java/org/azeckoski/reflectutils/beanutils/DynaBeanAdapter.java $
 * DynaBeanAdapter.java - genericdao - Sep 20, 2008 10:08:01 AM - azeckoski
 **************************************************************************
 * Copyright (c) 2008 Aaron Zeckoski
 * Licensed under the Apache License, Version 2.0
 * 
 * A copy of the Apache License has been included in this 
 * distribution and is available at: http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * Aaron Zeckoski (azeckoski @ gmail.com) (aaronz @ vt.edu) (aaron @ caret.cam.ac.uk)
 */

package org.azeckoski.reflectutils.beanutils;





/**
 * This allows dynabeans to work with the field utils,
 * should only be loaded by reflection if the DynaBean class can be found
 * 
 * @author Aaron Zeckoski (azeckoski @ gmail.com)
 */
public class DynaBeanAdapter implements FieldAdapter {

    public boolean isAdaptableObject(Object obj) {
        boolean adaptable = false;
        if (obj instanceof DynaBean) {
            adaptable = true;
        }
        return adaptable;
    }

    public boolean isAdaptableClass(Class<?> beanClass) {
        boolean adaptable = false;
        if (DynaBean.class.isAssignableFrom(beanClass)) {
            adaptable = true;
        }
        return adaptable;
    }

    /* (non-Javadoc)
     * @see org.azeckoski.reflectutils.beanutils.FieldAdapter#getFieldType(java.lang.Object, java.lang.String)
     */
    public Class<?> getFieldType(Object obj, String name) {
        DynaClass dynaClass = ((DynaBean) obj).getDynaClass();
        DynaProperty dynaProperty = dynaClass.getDynaProperty(name);
        if (dynaProperty == null) {
            throw new FieldnameNotFoundException("DynaBean: Could not find this fieldName ("+name+") on the target object: " + obj, name, null);
        }
        return dynaProperty.getType();
    }

    /* (non-Javadoc)
     * @see org.azeckoski.reflectutils.beanutils.FieldAdapter#getFieldValues(java.lang.Object, org.azeckoski.reflectutils.ClassFields.FieldsFilter)
     */
    public Map<String, Object> getFieldValues(Object obj, FieldsFilter filter) {