Example usage for java.beans PropertyDescriptor setName

List of usage examples for java.beans PropertyDescriptor setName

Introduction

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

Prototype

public void setName(String name) 

Source Link

Document

Sets the programmatic name of this feature.

Usage

From source file:com.wavemaker.json.type.reflect.WMPropertyUtilsBean.java

@Override
public PropertyDescriptor[] getPropertyDescriptors(Class klass) {
    PropertyDescriptor[] pds = super.getPropertyDescriptors(klass);

    for (PropertyDescriptor pd : pds) {
        String name = pd.getName();
        Field fld = null;//from   w w  w. ja v a2s.  c o m
        try {
            fld = klass.getDeclaredField(name);
        } catch (NoSuchFieldException ex) {
        }

        if (fld != null) {
            continue;
        }

        String shifted = name.substring(0, 1).toUpperCase();

        String newName = shifted + name.substring(1);

        fld = null;
        try {
            fld = klass.getDeclaredField(newName);
        } catch (NoSuchFieldException ex) {
        }

        if (fld != null) {
            pd.setName(newName);
        }
    }

    return pds;
}

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;/*  ww w. j a  v a2s  . 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.eclipse.wb.internal.core.utils.reflect.ReflectionUtils.java

/**
 * @return the {@link PropertyDescriptor}'s for given {@link Class}.
 *//*from   w  ww.  jav a2  s . c o  m*/
public static List<PropertyDescriptor> getPropertyDescriptors(BeanInfo beanInfo, Class<?> componentClass)
        throws Exception {
    // check cache
    {
        List<PropertyDescriptor> descriptors = m_propertyDescriptorsCache.get(componentClass);
        if (descriptors != null) {
            return descriptors;
        }
    }
    // prepare descriptions
    List<PropertyDescriptor> descriptors = Lists.newArrayList();
    // if there is BeanInfo, try to use it
    if (beanInfo != null) {
        Collections.addAll(descriptors, beanInfo.getPropertyDescriptors());
        // remove indexed properties
        for (Iterator<PropertyDescriptor> I = descriptors.iterator(); I.hasNext();) {
            PropertyDescriptor descriptor = I.next();
            if (descriptor instanceof IndexedPropertyDescriptor) {
                I.remove();
            }
        }
    }
    // prepare getters/setters
    Map<String, Method> propertyToGetter = Maps.newTreeMap();
    Map<String, Method> propertyToSetter = Maps.newTreeMap();
    // append existing getters/setters
    for (PropertyDescriptor propertyDescriptor : descriptors) {
        Method readMethod = getReadMethod(propertyDescriptor);
        Method writeMethod = getWriteMethod(propertyDescriptor);
        if (readMethod != null) {
            String propertyName = getQualifiedPropertyName(readMethod);
            propertyToGetter.put(propertyName, readMethod);
            propertyDescriptor.setName(propertyName);
        }
        if (writeMethod != null) {
            String propertyName = getQualifiedPropertyName(writeMethod);
            propertyToSetter.put(propertyName, writeMethod);
            propertyDescriptor.setName(propertyName);
        }
    }
    // append missing methods (most probably protected)
    Set<String> newPropertyNames = Sets.newTreeSet();
    appendPropertyComponents(componentClass, newPropertyNames, propertyToGetter, propertyToSetter);
    // create PropertyDescriptor's for new getters/setters
    for (String propertyName : newPropertyNames) {
        addPropertyDescriptor(descriptors, propertyName, propertyToGetter, propertyToSetter);
    }
    useSimplePropertyNamesWherePossible(descriptors);
    makeMethodsAccessible(descriptors);
    // OK, final result
    m_propertyDescriptorsCache.put(componentClass, descriptors);
    return descriptors;
}

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

private static void useSimplePropertyNamesWherePossible(List<PropertyDescriptor> descriptors) {
    // prepare map: simple name -> qualified names
    Multimap<String, String> simplePropertyNames = HashMultimap.create();
    for (PropertyDescriptor propertyDescriptor : descriptors) {
        String qualifiedPropertyName = propertyDescriptor.getName();
        String simplePropertyName = getSimplePropertyName(qualifiedPropertyName);
        simplePropertyNames.put(simplePropertyName, qualifiedPropertyName);
    }/*from w w w  .j  ava  2s. c om*/
    // if simple name is unique, use it
    for (PropertyDescriptor propertyDescriptor : descriptors) {
        String qualifiedPropertyName = propertyDescriptor.getName();
        String simplePropertyName = getSimplePropertyName(qualifiedPropertyName);
        if (simplePropertyNames.get(simplePropertyName).size() == 1) {
            propertyDescriptor.setName(simplePropertyName);
        }
    }
}