use of java.beans.BeanInfo in project jmeter-plugins by undera.
the class RedisDataSet method setProperty.
/**
* Override the setProperty method in order to convert
* the original String calcMode property.
* This used the locale-dependent display value, so caused
* problems when the language was changed.
* Note that the calcMode StringProperty is replaced with an IntegerProperty
* so the conversion only needs to happen once.
*/
@Override
public void setProperty(JMeterProperty property) {
if (property instanceof StringProperty) {
final String pn = property.getName();
if (pn.equals("getMode")) {
final Object objectValue = property.getObjectValue();
try {
final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass());
final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor().getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE);
for (Enum<GetMode> e : GetMode.values()) {
final String propName = e.toString();
if (objectValue.equals(rb.getObject(propName))) {
final int tmpMode = e.ordinal();
if (log.isDebugEnabled()) {
log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode + " using Locale: " + rb.getLocale());
}
super.setProperty(pn, tmpMode);
return;
}
}
log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale());
} catch (IntrospectionException e) {
log.error("Could not find BeanInfo", e);
}
} else if (pn.equals("whenExhaustedAction")) {
final Object objectValue = property.getObjectValue();
try {
final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass());
final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor().getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE);
for (Enum<WhenExhaustedAction> e : WhenExhaustedAction.values()) {
final String propName = e.toString();
if (objectValue.equals(rb.getObject(propName))) {
final int tmpMode = e.ordinal();
if (log.isDebugEnabled()) {
log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode + " using Locale: " + rb.getLocale());
}
super.setProperty(pn, tmpMode);
return;
}
}
log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale());
} catch (IntrospectionException e) {
log.error("Could not find BeanInfo", e);
}
}
}
super.setProperty(property);
}
use of java.beans.BeanInfo in project javautils by jiadongpo.
the class BeanFactory method add.
public static void add(Class clazz) throws IntrospectionException, ClassNotFoundException {
String className = clazz.getName();
if (!ValidUtil.isValid(BEAN_SIMPLE_PROPERTIES.get(className))) {
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
PropertyDescriptor[] proDescrtptors = beanInfo.getPropertyDescriptors();
if (proDescrtptors != null && proDescrtptors.length > 0) {
Map<String, BeanStruct> simpleProperties = new Hashtable<>();
Map<String, BeanStruct> simplePropertiesIgnore = new Hashtable<>();
for (PropertyDescriptor propDesc : proDescrtptors) {
String fieldName = propDesc.getName();
if (!"class".equals(fieldName)) {
Object type = propDesc.getPropertyType();
Method readMethod = propDesc.getReadMethod();
Method writeMethod = propDesc.getWriteMethod();
boolean isDeclared = isDeclaredField(className, fieldName);
simpleProperties.put(fieldName, new BeanStruct(fieldName, type, readMethod, writeMethod, isDeclared));
simplePropertiesIgnore.put(fieldName.toLowerCase(), new BeanStruct(fieldName, type, readMethod, writeMethod, isDeclared));
}
}
BEAN_SIMPLE_PROPERTIES.put(className, simpleProperties);
BEAN_SIMPLE_PROPERTIESIGNORE.put(className, simplePropertiesIgnore);
}
}
}
use of java.beans.BeanInfo in project dble by actiontech.
the class ParameterMapping method getDescriptors.
/**
* @param clazz
* @return
*/
private static PropertyDescriptor[] getDescriptors(Class<?> clazz) {
PropertyDescriptor[] pds;
List<PropertyDescriptor> list;
PropertyDescriptor[] pds2 = DESCRIPTORS.get(clazz);
// clazz init for first time?
if (null == pds2) {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
pds = beanInfo.getPropertyDescriptors();
list = new ArrayList<>();
// add property it type is not null
for (PropertyDescriptor pd : pds) {
if (null != pd.getPropertyType()) {
list.add(pd);
}
}
pds2 = new PropertyDescriptor[list.size()];
list.toArray(pds2);
} catch (IntrospectionException ie) {
LOGGER.info("ParameterMappingError", ie);
pds2 = new PropertyDescriptor[0];
}
}
DESCRIPTORS.put(clazz, pds2);
return (pds2);
}
use of java.beans.BeanInfo in project dble by actiontech.
the class ObjectUtil method copyProperties.
public static void copyProperties(Object fromObj, Object toObj) {
Class<?> fromClass = fromObj.getClass();
Class<?> toClass = toObj.getClass();
try {
BeanInfo fromBean = Introspector.getBeanInfo(fromClass);
BeanInfo toBean = Introspector.getBeanInfo(toClass);
PropertyDescriptor[] toPd = toBean.getPropertyDescriptors();
List<PropertyDescriptor> fromPd = Arrays.asList(fromBean.getPropertyDescriptors());
for (PropertyDescriptor propertyDescriptor : toPd) {
propertyDescriptor.getDisplayName();
PropertyDescriptor pd = fromPd.get(fromPd.indexOf(propertyDescriptor));
if (pd.getDisplayName().equals(propertyDescriptor.getDisplayName()) && !pd.getDisplayName().equals("class") && propertyDescriptor.getWriteMethod() != null) {
propertyDescriptor.getWriteMethod().invoke(toObj, pd.getReadMethod().invoke(fromObj, null));
}
}
} catch (IntrospectionException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
throw new RuntimeException(e);
}
}
use of java.beans.BeanInfo in project core by weld.
the class JsonObjects method createContextualInstanceJson.
static String createContextualInstanceJson(Bean<?> bean, Object contextualInstance, Probe probe) {
try {
JsonObjectBuilder builder = createSimpleBeanJson(bean, probe);
builder.add(SCOPE, simplifiedScope(bean.getScope()));
builder.add(CONTEXT_ID, Components.getInspectableScopeId(bean.getScope()));
builder.add(CLASS, contextualInstance.getClass().getName());
builder.add(HASH, contextualInstance.hashCode());
builder.add(AS_STRING, Strings.abbreviate(contextualInstance.toString(), CONTEXTUAL_INSTANCE_TO_STRING_LIMIT));
JsonArrayBuilder propertiesBuilder = Json.arrayBuilder();
Class<?> definingClass = contextualInstance.getClass();
if (ProxyObject.class.isAssignableFrom(definingClass)) {
definingClass = definingClass.getSuperclass();
}
BeanInfo bi = java.beans.Introspector.getBeanInfo(definingClass);
PropertyDescriptor[] properties = bi.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : properties) {
Method readMethod = propertyDescriptor.getReadMethod();
if (readMethod == null) {
continue;
}
Object value;
try {
value = readMethod.invoke(contextualInstance);
} catch (IllegalAccessException e) {
value = toString(e);
} catch (IllegalArgumentException e) {
value = toString(e);
} catch (InvocationTargetException e) {
value = toString(e);
}
propertiesBuilder.add(Json.objectBuilder().add(NAME, propertyDescriptor.getDisplayName()).add(VALUE, value != null ? Strings.abbreviate(value.toString(), CONTEXTUAL_INSTANCE_PROPERTY_VALUE_LIMIT) : "null"));
}
builder.add(PROPERTIES, propertiesBuilder);
return builder.build();
} catch (IntrospectionException e) {
ProbeLogger.LOG.introspectionProblem(bean, e);
return null;
}
}
Aggregations