List of usage examples for java.beans BeanInfo getPropertyDescriptors
PropertyDescriptor[] getPropertyDescriptors();
From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlUrlRewriteRulesExporter.java
private Element createElement(Document document, String name, Object bean) throws IntrospectionException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { Element element = document.createElement(name); BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass(), Object.class); for (PropertyDescriptor propInfo : beanInfo.getPropertyDescriptors()) { String propName = propInfo.getName(); if (propInfo.getReadMethod() != null && String.class.isAssignableFrom(propInfo.getPropertyType())) { String propValue = BeanUtils.getProperty(bean, propName); if (propValue != null && !propValue.isEmpty()) { // Doing it the hard way to avoid having the &'s in the query string escaped at & Attr attr = document.createAttribute(propName); attr.setValue(propValue); element.setAttributeNode(attr); //element.setAttribute( propName, propValue ); }/*w w w. j av a 2 s. c o m*/ } } return element; }
From source file:org.jcurl.core.api.PropertyChangeSupport.java
/** * Creates a new instance of SafePropertyChangeSupport. * /*from ww w . j ava2s. c om*/ * @param producer * This is the object that is producing the property change * events. * @throws RuntimeException * If there is an introspection problem. */ public PropertyChangeSupport(final Object producer) { try { final BeanInfo info = Introspector.getBeanInfo(producer.getClass()); for (final PropertyDescriptor element : info.getPropertyDescriptors()) listenerMap.put(element.getName(), new WeakHashSet<PropertyChangeListener>()); listenerMap.put(ALL_PROPERTIES, new WeakHashSet<PropertyChangeListener>()); this.producer = producer; } catch (final IntrospectionException ex) { throw new RuntimeException(ex); } }
From source file:com.bstek.dorado.config.ExpressionMethodInterceptor.java
protected void discoverInterceptingMethods(Class<?> clazz) throws Exception { interceptingReadMethods = new HashMap<Method, ReadMethodDescriptor>(); interceptingWriteMethods = new HashMap<Method, Method>(); Map<Method, ReadMethodDescriptor> getterMethods = interceptingReadMethods; Map<Method, Method> setterMethods = interceptingWriteMethods; Map<String, Expression> expressionProperties = getExpressionProperties(); BeanInfo beanInfo = Introspector.getBeanInfo(clazz); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String property = propertyDescriptor.getName(); if (expressionProperties.containsKey(property)) { Method readMethod = propertyDescriptor.getReadMethod(); Method writeMethod = propertyDescriptor.getWriteMethod(); if (readMethod != null) { if (readMethod.getDeclaringClass() != clazz) { readMethod = clazz.getMethod(readMethod.getName(), readMethod.getParameterTypes()); }/*from w w w .j a va 2 s. c om*/ getterMethods.put(readMethod, new ReadMethodDescriptor(property, null)); } if (writeMethod != null) { if (writeMethod.getDeclaringClass() != clazz) { writeMethod = clazz.getMethod(writeMethod.getName(), writeMethod.getParameterTypes()); } setterMethods.put(writeMethod, readMethod); } } } }
From source file:org.onebusaway.siri.core.filters.ElementPathModuleDeliveryFilter.java
/** * We support lazy initialization of the {@link PropertyDescriptor} * descriptors necessary to read the and write to our object tree. Why? * //from w ww . j a v a 2 s.c o m * We can't do introspection ahead of time because we support iteration over * Collection types. Specifically, if a path expression navigates over a * collection, we'll iterate over the values of the collection, applying the * next level of property path to the collection value, as opposed to the * collection object itself. Because we can't introspect the element type of a * Collection from the parent class, we have to wait to do introspection at * runtime on the values of the Collection itself. * * @param value * @param depth * @return */ private PropertyDescriptor getPropertyDescriptorForDepth(Object value, int depth) { PropertyDescriptor property = _properties[depth]; if (property == null) { synchronized (this) { if (property == null) { String propertyName = _propertyNames[depth]; try { BeanInfo beanInfo = Introspector.getBeanInfo(value.getClass()); for (PropertyDescriptor propertyDesc : beanInfo.getPropertyDescriptors()) { if (propertyDesc.getName().equals(propertyName)) { property = propertyDesc; break; } } } catch (Throwable ex) { throw new SiriException("error in introspection of class " + value.getClass() + " and property \"" + propertyName + "\""); } if (property == null) { throw new SiriException( "class " + value.getClass() + " does not have property \"" + propertyName + "\""); } PropertyDescriptor[] properties = new PropertyDescriptor[_properties.length]; System.arraycopy(_properties, 0, properties, 0, properties.length); properties[depth] = property; _properties = properties; } } } return property; }
From source file:org.androidtransfuse.processor.ManifestManager.java
private <T extends Mergeable> void updateMergeTags(Class<T> clazz, T mergeable) throws MergerException { try {/*from ww w. ja va 2 s. c o m*/ mergeable.setGenerated(true); BeanInfo beanInfo = Introspector.getBeanInfo(clazz); for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) { Method readMethod = propertyDescriptor.getReadMethod(); Method writeMethod = propertyDescriptor.getWriteMethod(); Merge mergeAnnotation = findAnnotation(Merge.class, writeMethod, readMethod); Object property = PropertyUtils.getProperty(mergeable, propertyDescriptor.getName()); if (mergeAnnotation != null && property != null) { mergeable.addMergeTag(mergeAnnotation.value()); } } } catch (IntrospectionException e) { throw new MergerException(e); } catch (InvocationTargetException e) { throw new MergerException(e); } catch (NoSuchMethodException e) { throw new MergerException(e); } catch (IllegalAccessException e) { throw new MergerException(e); } }
From source file:org.apache.jcs.config.PropertySetter.java
/** * Uses JavaBeans {@link Introspector}to computer setters of object to be * configured.//from w w w . j a v a2s . c o m */ protected void introspect() { try { BeanInfo bi = Introspector.getBeanInfo(obj.getClass()); props = bi.getPropertyDescriptors(); } catch (IntrospectionException ex) { log.error("Failed to introspect " + obj + ": " + ex.getMessage()); props = new PropertyDescriptor[0]; } }
From source file:org.rhq.plugins.platform.PlatformComponent.java
private Object getObjectProperty(Object object, String name) { try {//from ww w . j a va 2 s . c o m BeanInfo info = Introspector.getBeanInfo(object.getClass()); for (PropertyDescriptor pd : info.getPropertyDescriptors()) { if (pd.getName().equals(name)) { return pd.getReadMethod().invoke(object); } } } catch (Exception skip) { if (log.isDebugEnabled()) log.debug(skip); } return Double.NaN; }
From source file:name.livitski.tools.persista.AbstractDAO.java
protected Map<String, PropertyDescriptor> introspectProperties() { if (null == entityProps) try {/* ww w .ja v a 2 s .c o m*/ final BeanInfo beanInfo = Introspector.getBeanInfo(entityClass); final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); entityProps = new HashMap<String, PropertyDescriptor>(propertyDescriptors.length, 1f); for (final PropertyDescriptor pd : propertyDescriptors) { entityProps.put(pd.getName(), pd); } } catch (IntrospectionException e) { throw new UnsupportedOperationException("Introspection failed for entity " + entityClass, e); } return entityProps; }
From source file:org.pentaho.reporting.engine.classic.core.modules.parser.ext.factory.base.BeanObjectDescription.java
private void readBeanDescription(final Class className, final boolean init) { try {/*from ww w .j a va 2s. c o m*/ this.properties = new HashMap(); final BeanInfo bi = Introspector.getBeanInfo(className); final PropertyDescriptor[] propertyDescriptors = bi.getPropertyDescriptors(); for (int i = 0; i < propertyDescriptors.length; i++) { final PropertyDescriptor propertyDescriptor = propertyDescriptors[i]; final Method readMethod = propertyDescriptor.getReadMethod(); final Method writeMethod = propertyDescriptor.getWriteMethod(); if (isValidMethod(readMethod, 0) && isValidMethod(writeMethod, 1)) { final String name = propertyDescriptor.getName(); this.properties.put(name, propertyDescriptor); if (init) { super.setParameterDefinition(name, propertyDescriptor.getPropertyType()); } } } } catch (IntrospectionException e) { BeanObjectDescription.logger.error("Unable to build bean description", e); } }
From source file:com.emc.ecs.sync.config.ConfigWrapper.java
public ConfigWrapper(Class<C> targetClass) { try {/*from w ww . ja v a 2 s . co m*/ this.targetClass = targetClass; if (targetClass.isAnnotationPresent(StorageConfig.class)) this.uriPrefix = targetClass.getAnnotation(StorageConfig.class).uriPrefix(); if (targetClass.isAnnotationPresent(FilterConfig.class)) this.cliName = targetClass.getAnnotation(FilterConfig.class).cliName(); if (targetClass.isAnnotationPresent(Label.class)) this.label = targetClass.getAnnotation(Label.class).value(); if (targetClass.isAnnotationPresent(Documentation.class)) this.documentation = targetClass.getAnnotation(Documentation.class).value(); BeanInfo beanInfo = Introspector.getBeanInfo(targetClass); for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { if (descriptor.getReadMethod().isAnnotationPresent(Option.class)) { propertyMap.put(descriptor.getName(), new ConfigPropertyWrapper(descriptor)); } } for (MethodDescriptor descriptor : beanInfo.getMethodDescriptors()) { Method method = descriptor.getMethod(); if (method.isAnnotationPresent(UriParser.class)) { if (method.getReturnType().equals(Void.TYPE) && method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(String.class)) { uriParser = method; } else { log.warn("illegal signature for @UriParser method {}.{}", targetClass.getSimpleName(), method.getName()); } } else if (method.isAnnotationPresent(UriGenerator.class)) { if (method.getReturnType().equals(String.class) && method.getParameterTypes().length == 0) { uriGenerator = method; } else { log.warn("illegal signature for @UriGenerator method {}.{}", targetClass.getSimpleName(), method.getName()); } } } if (propertyMap.isEmpty()) log.info("no @Option annotations found in {}", targetClass.getSimpleName()); } catch (IntrospectionException e) { throw new RuntimeException(e); } }