Example usage for java.beans PropertyDescriptor PropertyDescriptor

List of usage examples for java.beans PropertyDescriptor PropertyDescriptor

Introduction

In this page you can find the example usage for java.beans PropertyDescriptor PropertyDescriptor.

Prototype

public PropertyDescriptor(String propertyName, Method readMethod, Method writeMethod)
        throws IntrospectionException 

Source Link

Document

This constructor takes the name of a simple property, and Method objects for reading and writing the property.

Usage

From source file:org.apache.activemq.artemis.utils.uri.FluentPropertyBeanIntrospectorWithIgnores.java

private PropertyDescriptor createFluentPropertyDescritor(Method m, String propertyName)
        throws IntrospectionException {
    return new PropertyDescriptor(propertyName(m), null, m);
}

From source file:org.psnively.scala.beans.ScalaBeanInfo.java

private static void addScalaSetter(Map<String, PropertyDescriptor> propertyDescriptors, Method writeMethod) {
    String propertyName = writeMethod.getName().substring(0,
            writeMethod.getName().length() - SCALA_SETTER_SUFFIX.length());

    PropertyDescriptor pd = propertyDescriptors.get(propertyName);
    if (pd != null && pd.getWriteMethod() == null) {
        try {//from   www .  j av a 2 s  .c om
            pd.setWriteMethod(writeMethod);
        } catch (IntrospectionException ex) {
            logger.debug("Could not add write method [" + writeMethod + "] for " + "property [" + propertyName
                    + "]: " + ex.getMessage());
        }
    } else if (pd == null) {
        try {
            pd = new PropertyDescriptor(propertyName, null, writeMethod);
            propertyDescriptors.put(propertyName, pd);
        } catch (IntrospectionException ex) {
            logger.debug("Could not create new PropertyDescriptor for " + "writeMethod [" + writeMethod
                    + "] property [" + propertyName + "]: " + ex.getMessage());
        }
    }
}

From source file:com.github.dozermapper.core.util.ReflectionUtils.java

/**
 * There are some nasty bugs for introspection with generics. This method addresses those nasty bugs and tries to find proper methods if available
 * http://bugs.sun.com/view_bug.do?bug_id=6788525
 * http://bugs.sun.com/view_bug.do?bug_id=6528714
 *
 * @param clazz      type to work on/*www .  j  ava 2 s . c o m*/
 * @param descriptor property pair (get/set) information
 * @return descriptor
 */
private static PropertyDescriptor fixGenericDescriptor(Class<?> clazz, PropertyDescriptor descriptor) {
    Method readMethod = descriptor.getReadMethod();

    if (readMethod != null && (readMethod.isBridge() || readMethod.isSynthetic())) {
        String propertyName = descriptor.getName();
        //capitalize the first letter of the string;
        String baseName = Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
        String setMethodName = "set" + baseName;
        String getMethodName = "get" + baseName;
        Method getMethod = findPreferablyNonSyntheticMethod(getMethodName, clazz);
        Method setMethod = findPreferablyNonSyntheticMethod(setMethodName, clazz);
        try {
            return new PropertyDescriptor(propertyName, getMethod, setMethod);
        } catch (IntrospectionException e) {
            //move on
        }
    }
    return descriptor;
}

From source file:org.psnively.scala.beans.ScalaBeanInfo.java

private static void addScalaGetter(Map<String, PropertyDescriptor> propertyDescriptors, Method readMethod) {
    String propertyName = readMethod.getName();

    PropertyDescriptor pd = propertyDescriptors.get(propertyName);
    if (pd != null && pd.getReadMethod() == null) {
        try {/*from   w w w  .j  a v  a 2  s  . c  om*/
            pd.setReadMethod(readMethod);
        } catch (IntrospectionException ex) {
            logger.debug("Could not add read method [" + readMethod + "] for " + "property [" + propertyName
                    + "]: " + ex.getMessage());
        }
    } else if (pd == null) {
        try {
            pd = new PropertyDescriptor(propertyName, readMethod, null);
            propertyDescriptors.put(propertyName, pd);
        } catch (IntrospectionException ex) {
            logger.debug("Could not create new PropertyDescriptor for " + "readMethod [" + readMethod
                    + "] property [" + propertyName + "]: " + ex.getMessage());
        }
    }
}

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

public void introspect(HttpServletRequest request) throws IntrospectionException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException, InstantiationException {
    Class<?> cls = null;/*from   ww  w  . ja v a  2  s  .  c o m*/

    if ("pluginConfig".equals(focus)) {
        cls = pluginConfig.getClass();
        this.breadCrumbs.clear();
        this.breadCrumbs.add("Setup");

        if (isProjectPlugin()) {
            this.breadCrumbs.add("Projects");
            this.breadCrumbs.add(projectName);
            this.breadCrumbs.add(this.pluginConfig.getPluginName());
        } else {
            this.breadCrumbs.add("Plugins");
            this.breadCrumbs.add(this.pluginConfig.getPluginName());
        }
    } else {
        cls = PropertyUtils.getPropertyType(this, focus);
        if (cls.isArray()) {
            cls = cls.getComponentType();
        }
    }

    final String prefix = focus + ".";
    final PropertyDescriptor[] pds;

    if (PluginConfigDto.class.isAssignableFrom(cls)) {
        final PluginConfigDto pluginConfig = (PluginConfigDto) getFocusObject();
        final List<PropertyDescriptor> tmp = pluginConfig.getPropertyDescriptors(request.getLocale());
        pds = tmp.toArray(new PropertyDescriptor[tmp.size()]);

        if (pluginConfig instanceof PluginProfileDto) {
            ((PluginProfileDto) pluginConfig).checkPoint();
        }
    } else {
        final BeanInfo beanInfo = Introspector.getBeanInfo(cls);
        Introspector.flushFromCaches(cls);
        pds = beanInfo.getPropertyDescriptors();
    }

    if (isNested()) {
        for (PropertyDescriptor pd : propertyDescriptors) {
            if (focus.startsWith(pd.getName())) {
                breadCrumbs.add(pd.getDisplayName());
            }
        }
    }

    types.clear();
    choices.clear();
    propertyDescriptors.clear();
    hiddenPasswords.clear();

    for (PropertyDescriptor pd : pds) {
        final String name = prefix + pd.getName();
        final PropertyDescriptor cp = new PropertyDescriptor(pd.getName(), pd.getReadMethod(),
                pd.getWriteMethod());
        cp.setShortDescription(pd.getShortDescription());
        cp.setDisplayName(pd.getDisplayName());
        cp.setName(name);
        propertyDescriptors.add(cp);
        types.put(name, getTypeAndPrepare(name, pd));
    }

    putBreadCrumbsInRequest(request);
}

From source file:org.getobjects.foundation.kvc.KVCWrapper.java

public PropertyDescriptor[] getPropertyDescriptors(Class _class) throws Exception {
    /**/*  w  w w. jav  a 2  s  .  c o  m*/
     * Our idea of KVC differs from what the Bean API proposes. Instead of
     * having get<name> and set<name> methods, we expect <name> and 
     * set<name> methods.
     * 
     * HH: changed to allow for getXYZ style accessors.
     */

    Map<String, Method> settersMap = new HashMap<String, Method>();
    Map<String, Method> gettersMap = new HashMap<String, Method>();

    Method methods[] = getPublicDeclaredMethods(_class);

    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        if (method == null)
            continue;

        String name = method.getName();
        int nameLen = name.length();
        int paraCount = method.getParameterTypes().length;

        if (name.startsWith("set")) {
            if (method.getReturnType() != Void.TYPE)
                continue;
            if (paraCount != 1)
                continue;
            if (nameLen == 3)
                continue;

            char[] chars = name.substring(3).toCharArray();
            chars[0] = Character.toLowerCase(chars[0]);
            String decapsedName = new String(chars);

            if (logger.isDebugEnabled()) {
                logger.debug("Recording setter method [" + method + "] for name \"" + decapsedName + "\"");
            }
            settersMap.put(decapsedName, method);
        } else {
            /* register as a getter */
            if (method.getReturnType() == Void.TYPE)
                continue;
            if (paraCount > 0)
                continue;

            if (name.startsWith("get")) {
                char[] chars = name.substring(3).toCharArray();
                chars[0] = Character.toLowerCase(chars[0]);
                name = new String(chars);
            }

            if (logger.isDebugEnabled()) {
                logger.debug("Recording getter method [" + method + "] for name \"" + name + "\"");
            }
            gettersMap.put(name, method);
        }

    }

    Set<PropertyDescriptor> pds = new HashSet<PropertyDescriptor>();

    /* merge all names from getters and setters */
    Set<String> names = new HashSet<String>(gettersMap.keySet());
    names.addAll(settersMap.keySet());

    for (String name : names) {
        Method getter = gettersMap.get(name);
        Method setter = settersMap.get(name);
        if (getter == null && setter == null)
            continue;

        /* this is JavaBeans stuff */
        PropertyDescriptor descriptor = new PropertyDescriptor(name, getter, setter);
        pds.add(descriptor);
    }
    return pds.toArray(new PropertyDescriptor[0]);
}

From source file:com.twinsoft.convertigo.beans.core.MySimpleBeanInfo.java

protected PropertyDescriptor getPropertyDescriptor(String name) throws IntrospectionException {
    checkAdditionalProperties();//from  w w w  . jav a 2  s . co  m
    for (int i = 0; i < properties.length; i++) {
        PropertyDescriptor property = properties[i];
        if (name.equals(property.getName())) {
            PropertyDescriptor clone = new PropertyDescriptor(name, property.getReadMethod(),
                    property.getWriteMethod());
            clone.setDisplayName(property.getDisplayName());
            clone.setShortDescription(property.getShortDescription());
            clone.setPropertyEditorClass(property.getPropertyEditorClass());
            clone.setBound(property.isBound());
            clone.setConstrained(property.isConstrained());
            clone.setExpert(property.isExpert());
            clone.setHidden(property.isHidden());
            clone.setPreferred(property.isPreferred());
            for (String attributeName : Collections.list(property.attributeNames())) {
                clone.setValue(attributeName, property.getValue(attributeName));
            }
            return properties[i] = clone;
        }
    }
    return null;
}

From source file:org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils.java

private static void addPropertyDescriptor(List<PropertyDescriptor> descriptors, String qualifiedPropertyName,
        Map<String, Method> propertyToGetter, Map<String, Method> propertyToSetter) throws Exception {
    if (qualifiedPropertyName.startsWith("(")) {
        return;/*from   w ww .  j av a  2  s . c  o m*/
    }
    // prepare methods
    Method getMethod = propertyToGetter.get(qualifiedPropertyName);
    Method setMethod = propertyToSetter.get(qualifiedPropertyName);
    if (!isValidForJavaIBM(getMethod) || !isValidForJavaIBM(setMethod)) {
        return;
    }
    if (getMethod != null && getMethod.getReturnType() == Void.TYPE) {
        return;
    }
    // add property
    descriptors.add(new PropertyDescriptor(qualifiedPropertyName, getMethod, setMethod));
}