List of usage examples for java.beans BeanInfo getPropertyDescriptors
PropertyDescriptor[] getPropertyDescriptors();
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 va2s.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:de.escalon.hypermedia.spring.de.escalon.hypermedia.spring.jackson.LinkListSerializer.java
private void recurseSupportedProperties(JsonGenerator jgen, String currentVocab, Class<?> beanType, ActionDescriptor actionDescriptor, ActionInputParameter actionInputParameter, Object currentCallValue) throws IntrospectionException, IOException { // TODO support Option provider by other method args? final BeanInfo beanInfo = Introspector.getBeanInfo(beanType); final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); // TODO collection and map for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { final Method writeMethod = propertyDescriptor.getWriteMethod(); if (writeMethod == null) { continue; }//from ww w . ja v a 2 s . co m final Class<?> propertyType = propertyDescriptor.getPropertyType(); // TODO: the property name must be a valid URI - need to check context for terms? String propertyName = getWritableExposedPropertyOrPropertyName(propertyDescriptor); if (DataType.isScalar(propertyType)) { final Property property = new Property(beanType, propertyDescriptor.getReadMethod(), propertyDescriptor.getWriteMethod(), propertyDescriptor.getName()); Object propertyValue = getPropertyValue(currentCallValue, propertyDescriptor); ActionInputParameter propertySetterInputParameter = new ActionInputParameter( new MethodParameter(propertyDescriptor.getWriteMethod(), 0), propertyValue); final Object[] possiblePropertyValues = actionInputParameter.getPossibleValues(property, actionDescriptor); writeSupportedProperty(jgen, currentVocab, propertySetterInputParameter, propertyName, property, possiblePropertyValues); } else { jgen.writeStartObject(); jgen.writeStringField("hydra:property", propertyName); // TODO: is the property required -> for bean props we need the Access annotation to express that jgen.writeObjectFieldStart(getPropertyOrClassNameInVocab(currentVocab, "rangeIncludes", JacksonHydraSerializer.HTTP_SCHEMA_ORG, "schema:")); Expose expose = AnnotationUtils.getAnnotation(propertyType, Expose.class); String subClass; if (expose != null) { subClass = expose.value(); } else { subClass = propertyType.getSimpleName(); } jgen.writeStringField(getPropertyOrClassNameInVocab(currentVocab, "subClassOf", "http://www.w3.org/2000/01/rdf-schema#", "rdfs:"), subClass); jgen.writeArrayFieldStart("hydra:supportedProperty"); Object propertyValue = getPropertyValue(currentCallValue, propertyDescriptor); recurseSupportedProperties(jgen, currentVocab, propertyType, actionDescriptor, actionInputParameter, propertyValue); jgen.writeEndArray(); jgen.writeEndObject(); jgen.writeEndObject(); } } }
From source file:net.jolm.JolmLdapTemplate.java
private AndFilter getAndFilterFromExample(LdapEntity example, boolean wildcardFilters, boolean logFilter) { try {/*from w w w. j av a2 s .c o m*/ AndFilter filter = new AndFilter(); BeanInfo info = Introspector.getBeanInfo(example.getClass()); for (PropertyDescriptor pd : info.getPropertyDescriptors()) { if (isAttributeApplicableInFilter(pd)) { Object value = pd.getReadMethod().invoke(example); if (value != null) { if (value.getClass().isArray()) { Object[] valueArray = (Object[]) value; for (Object o : valueArray) { addAndFilter(filter, pd, o, wildcardFilters); } } else { if (StringUtils.isNotEmpty(value.toString())) { addAndFilter(filter, pd, value, wildcardFilters); } } } } } if (logFilter && log.isDebugEnabled()) { log.debug("Finding " + example.getClass().getSimpleName() + "(s) using filter: " + filter.encode()); } return filter; } catch (Exception e) { throw new RuntimeException("Unable to create the filter from ldap entity:" + example, e); } }
From source file:com.icsshs.datatransfer.database.impl.QueryBeanProcessor.java
/** * Returns a PropertyDescriptor[] for the given Class. * * @param c The Class to retrieve PropertyDescriptors for. * @return A PropertyDescriptor[] describing the Class. * @throws SQLException if introspection failed. *///from w ww.ja va 2 s .c o m private PropertyDescriptor[] propertyDescriptors(Class<?> c) throws SQLException { // Introspector caches BeanInfo classes for better performance BeanInfo beanInfo = null; try { beanInfo = Introspector.getBeanInfo(c); } catch (IntrospectionException e) { throw new SQLException("Bean introspection failed: " + e.getMessage()); } return beanInfo.getPropertyDescriptors(); }
From source file:org.codehaus.enunciate.modules.xfire_client.EnunciatedClientOperationBinding.java
/** * Loads the property descriptors for the ordered properties of the specified class. * * @param wrapperClass The wrapper class. * @return The ordered property descriptors. *//*from ww w .jav a 2s.c om*/ protected PropertyDescriptor[] loadOrderedProperties(Class wrapperClass) throws XFireFault { String[] propOrder = annotations.getPropertyOrder(wrapperClass); if (propOrder == null) { throw new XFireFault( "Unable use use " + wrapperClass.getName() + " as a wrapper class: no propOrder specified.", XFireFault.RECEIVER); } BeanInfo responseBeanInfo; try { responseBeanInfo = Introspector.getBeanInfo(wrapperClass, Object.class); } catch (IntrospectionException e) { throw new XFireFault("Unable to introspect " + wrapperClass.getName(), e, XFireFault.RECEIVER); } return PropertyUtil.sortProperties(wrapperClass, responseBeanInfo.getPropertyDescriptors(), propOrder); }
From source file:net.jolm.JolmLdapTemplate.java
private List<? extends LdapEntity> filterAttributes(List<LdapEntity> entities, String[] attributes) { if (entities == null || entities.size() == 0) { return entities; }//from www. j av a 2 s . com List<String> attributesAsList = Arrays.asList(attributes); for (LdapEntity entity : entities) { BeanInfo beanInfo; try { beanInfo = Introspector.getBeanInfo(entity.getClass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor pd : propertyDescriptors) { if (isAttributeFiltered(pd.getName(), attributesAsList)) { Method writeMethod = pd.getWriteMethod(); writeMethod.invoke(entity, new Object[] { null }); } } } catch (Exception e) { //Should never happen throw new RuntimeException(e); } } return entities; }
From source file:com.github.erchu.beancp.commons.NameBasedMapConvention.java
private List<BindingSide> getMatchingPropertyByName(final BeanInfo sourceBeanInfo, final String atDestinationName, final MemberAccessType destinationMemberAccessType) { Optional<PropertyDescriptor> exactMatchResult = Arrays.stream(sourceBeanInfo.getPropertyDescriptors()) .filter(i -> i.getName().equalsIgnoreCase(atDestinationName)).findFirst(); if (exactMatchResult.isPresent()) { List<BindingSide> result = new LinkedList<>(); result.add(new PropertyBindingSide(exactMatchResult.get())); return result; }//from w ww .jav a 2 s . com if (_flateningEnabled) { Optional<PropertyDescriptor> partiallyMatchResult = Arrays .stream(sourceBeanInfo.getPropertyDescriptors()) .filter(i -> StringUtils.startsWithIgnoreCase(atDestinationName, i.getName())) .sorted((x, y) -> y.getName().length() - x.getName().length()).findFirst(); if (partiallyMatchResult.isPresent()) { BindingSide firstBinding = new PropertyBindingSide(partiallyMatchResult.get()); Class innerPropertyClass = firstBinding.getValueClass(); return getInnerMatchingSourceMemberByName(innerPropertyClass, atDestinationName, firstBinding, destinationMemberAccessType); } else { return null; } } return null; }
From source file:com.opensymphony.xwork2.ognl.OgnlUtil.java
/** * Get's the java beans property descriptors for the given class. * * @param clazz the source object.// w w w . ja v a 2s . com * @return property descriptors. * @throws IntrospectionException is thrown if an exception occurs during introspection. */ public PropertyDescriptor[] getPropertyDescriptors(Class clazz) throws IntrospectionException { BeanInfo beanInfo = getBeanInfo(clazz); return beanInfo.getPropertyDescriptors(); }
From source file:com.opensymphony.xwork2.ognl.OgnlUtil.java
/** * Get's the java beans property descriptors for the given source. * * @param source the source object./*from www.java 2 s. co m*/ * @return property descriptors. * @throws IntrospectionException is thrown if an exception occurs during introspection. */ public PropertyDescriptor[] getPropertyDescriptors(Object source) throws IntrospectionException { BeanInfo beanInfo = getBeanInfo(source); return beanInfo.getPropertyDescriptors(); }