use of java.beans.BeanInfo in project groovy-core by groovy.
the class TestSupport method getDescriptor.
protected PropertyDescriptor getDescriptor(Object bean, String property) throws Exception {
BeanInfo info = Introspector.getBeanInfo(bean.getClass());
PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor.getName().equals(property)) {
return descriptor;
}
}
fail("Could not find property: " + property + " on bean: " + bean);
return null;
}
use of java.beans.BeanInfo in project spring-cloud-connectors by spring-cloud.
the class ServiceConnectorCreatorRegistry method getServiceProperties.
private Properties getServiceProperties(String keyLead, ServiceInfo serviceInfo) {
Properties cloudProperties = new Properties();
try {
BeanInfo beanInfo = Introspector.getBeanInfo(serviceInfo.getClass());
PropertyDescriptor[] propDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor propDescriptor : propDescriptors) {
ServiceProperty propAnnotation = propDescriptor.getReadMethod().getAnnotation(ServiceProperty.class);
String key = keyLead;
if (propAnnotation != null) {
if (!propAnnotation.category().isEmpty()) {
key = key + "." + propAnnotation.category();
}
if (!propAnnotation.name().isEmpty()) {
key = key + "." + propAnnotation.name();
} else {
key = key + "." + propDescriptor.getName().toLowerCase();
}
Object value = propDescriptor.getReadMethod().invoke(serviceInfo);
if (value != null) {
cloudProperties.put(key, value);
}
}
}
} catch (Exception e) {
throw new CloudException(e);
}
return cloudProperties;
}
use of java.beans.BeanInfo in project Mycat-Server by MyCATApache.
the class ParameterMapping method getDescriptors.
/**
* 用于导出clazz这个JavaBean的所有属性的PropertyDescriptor
* @param clazz
* @return
*/
private static PropertyDescriptor[] getDescriptors(Class<?> clazz) {
// PropertyDescriptor类表示JavaBean类通过存储器导出一个属性
PropertyDescriptor[] pds;
List<PropertyDescriptor> list;
PropertyDescriptor[] pds2 = descriptors.get(clazz);
// 该clazz是否第一次加载
if (null == pds2) {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
pds = beanInfo.getPropertyDescriptors();
list = new ArrayList<PropertyDescriptor>();
// 加载每一个类型不为空的property
for (int i = 0; i < pds.length; i++) {
if (null != pds[i].getPropertyType()) {
list.add(pds[i]);
}
}
pds2 = new PropertyDescriptor[list.size()];
list.toArray(pds2);
} catch (IntrospectionException ie) {
LOGGER.error("ParameterMappingError", ie);
pds2 = new PropertyDescriptor[0];
}
}
descriptors.put(clazz, pds2);
return (pds2);
}
use of java.beans.BeanInfo in project powermock by powermock.
the class ConfigurationMapper method map.
public void map(final Properties properties) {
try {
BeanInfo info = Introspector.getBeanInfo(configurationClass, Object.class);
PropertyDescriptor[] propertyDescriptors = info.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
if (propertyDescriptor.getWriteMethod() != null) {
mapProperty(propertyDescriptor, properties);
}
}
} catch (Exception e) {
throw new PowerMockInternalException(e);
}
}
use of java.beans.BeanInfo in project groovy by apache.
the class TestSupport method getDescriptor.
protected PropertyDescriptor getDescriptor(Object bean, String property) throws Exception {
BeanInfo info = Introspector.getBeanInfo(bean.getClass());
PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor.getName().equals(property)) {
return descriptor;
}
}
fail("Could not find property: " + property + " on bean: " + bean);
return null;
}
Aggregations