use of java.beans.IntrospectionException in project jmeter by apache.
the class CSVDataSet method setProperty.
/**
* Override the setProperty method in order to convert
* the original String shareMode property.
* This used the locale-dependent display value, so caused
* problems when the language was changed.
* If the "shareMode" value matches a resource value then it is converted
* into the resource key.
* To reduce the need to look up resources, we only attempt to
* convert values with spaces in them, as these are almost certainly
* not variables (and they are definitely not resource keys).
*/
@Override
public void setProperty(JMeterProperty property) {
if (property instanceof StringProperty) {
final String propName = property.getName();
if ("shareMode".equals(propName)) {
// The original name of the property
final String propValue = property.getStringValue();
if (propValue.contains(" ")) {
// variables are unlikely to contain spaces, so most likely a translation
try {
final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass());
final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor().getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE);
for (String resKey : CSVDataSetBeanInfo.getShareTags()) {
if (propValue.equals(rb.getString(resKey))) {
if (log.isDebugEnabled()) {
log.debug("Converted {}={} to {} using Locale: {}", propName, propValue, resKey, rb.getLocale());
}
// reset the value
((StringProperty) property).setValue(resKey);
super.setProperty(property);
return;
}
}
// This could perhaps be a variable name
log.warn("Could not translate {}={} using Locale: {}", propName, propValue, rb.getLocale());
} catch (IntrospectionException e) {
log.error("Could not find BeanInfo; cannot translate shareMode entries", e);
}
}
}
}
super.setProperty(property);
}
use of java.beans.IntrospectionException in project jmeter by apache.
the class ConstantThroughputTimer 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("calcMode")) {
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<Mode> e : Mode.values()) {
final String propName = e.toString();
if (objectValue.equals(rb.getObject(propName))) {
final int tmpMode = e.ordinal();
log.debug("Converted {}={} to mode={} using Locale: {}", pn, objectValue, tmpMode, rb.getLocale());
super.setProperty(pn, tmpMode);
return;
}
}
log.warn("Could not convert {}={} using Locale: {}", pn, objectValue, rb.getLocale());
} catch (IntrospectionException e) {
log.error("Could not find BeanInfo", e);
}
}
}
super.setProperty(property);
}
use of java.beans.IntrospectionException in project tomee by apache.
the class HeavyweightTypeInfoBuilder method mapFields.
/**
* Map the (nested) fields of a XML Schema Type to Java Beans properties or public fields of the specified Java Class.
*
* @param javaClass the java class to map
* @param xmlTypeInfo the xml schema for the type
* @param javaXmlTypeMapping the java to xml type mapping metadata
* @param typeInfo the JaxRpcTypeInfo for this type
* @throws OpenEJBException if the XML Schema Type can not be mapped to the Java Class
*/
private void mapFields(Class javaClass, XmlTypeInfo xmlTypeInfo, JavaXmlTypeMapping javaXmlTypeMapping, JaxRpcTypeInfo typeInfo) throws OpenEJBException {
// Skip arrays since they can't define a variable-mapping element
if (!javaClass.isArray()) {
// if there is a variable-mapping, log a warning
if (!javaXmlTypeMapping.getVariableMapping().isEmpty()) {
log.warn("Ignoring variable-mapping defined for class " + javaClass + " which is an array.");
}
return;
}
// Index Java bean properties by name
Map<String, Class> properties = new HashMap<String, Class>();
try {
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(javaClass).getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
properties.put(propertyDescriptor.getName(), propertyDescriptor.getPropertyType());
}
} catch (IntrospectionException e) {
throw new OpenEJBException("Class " + javaClass + " is not a valid javabean", e);
}
for (VariableMapping variableMapping : javaXmlTypeMapping.getVariableMapping()) {
String fieldName = variableMapping.getJavaVariableName();
if (variableMapping.getXmlAttributeName() != null) {
JaxRpcFieldInfo fieldInfo = new JaxRpcFieldInfo();
fieldInfo.name = fieldName;
// verify that the property exists on the java class
Class javaType = properties.get(fieldName);
if (javaType == null) {
throw new OpenEJBException("field name " + fieldName + " not found in " + properties);
}
String attributeLocalName = variableMapping.getXmlAttributeName();
QName xmlName = new QName("", attributeLocalName);
fieldInfo.xmlName = xmlName;
fieldInfo.xmlType = xmlTypeInfo.attributes.get(attributeLocalName);
if (fieldInfo.xmlType == null) {
throw new OpenEJBException("attribute " + xmlName + " not found in schema " + xmlTypeInfo.qname);
}
typeInfo.fields.add(fieldInfo);
} else {
JaxRpcFieldInfo fieldInfo = new JaxRpcFieldInfo();
fieldInfo.isElement = true;
fieldInfo.name = fieldName;
// verify that the property exists on the java class or there is a public field
Class javaType = properties.get(fieldName);
if (javaType == null) {
//see if it is a public field
try {
Field field = javaClass.getField(fieldName);
javaType = field.getType();
} catch (NoSuchFieldException e) {
throw new OpenEJBException("field name " + fieldName + " not found in " + properties, e);
}
}
QName xmlName = new QName("", variableMapping.getXmlElementName());
XmlElementInfo nestedElement = xmlTypeInfo.elements.get(xmlName);
if (nestedElement == null) {
String ns = xmlTypeInfo.qname.getNamespaceURI();
xmlName = new QName(ns, variableMapping.getXmlElementName());
nestedElement = xmlTypeInfo.elements.get(xmlName);
if (nestedElement == null) {
throw new OpenEJBException("element " + xmlName + " not found in schema " + xmlTypeInfo.qname);
}
}
fieldInfo.isNillable = nestedElement.nillable || hasEncoded;
fieldInfo.xmlName = xmlName;
// xml type
if (nestedElement.xmlType != null) {
fieldInfo.xmlType = nestedElement.xmlType;
} else {
QName anonymousName;
if (xmlTypeInfo.anonymous) {
anonymousName = new QName(xmlTypeInfo.qname.getNamespaceURI(), xmlTypeInfo.qname.getLocalPart() + ">" + nestedElement.qname.getLocalPart());
} else {
anonymousName = new QName(xmlTypeInfo.qname.getNamespaceURI(), ">" + xmlTypeInfo.qname.getLocalPart() + ">" + nestedElement.qname.getLocalPart());
}
fieldInfo.xmlType = anonymousName;
}
if (javaType.isArray()) {
fieldInfo.minOccurs = nestedElement.minOccurs;
fieldInfo.maxOccurs = nestedElement.maxOccurs;
}
typeInfo.fields.add(fieldInfo);
}
}
}
use of java.beans.IntrospectionException in project tomee by apache.
the class LightweightTypeInfoBuilder method mapFields.
private void mapFields(Class javaClass, XmlTypeInfo xmlTypeInfo, JaxRpcTypeInfo typeInfo) throws OpenEJBException {
// Map JavaBean property name to propertyType
Map<String, Class> propertyToClass = new HashMap<String, Class>();
try {
for (PropertyDescriptor descriptor : Introspector.getBeanInfo(javaClass).getPropertyDescriptors()) {
propertyToClass.put(descriptor.getName(), descriptor.getPropertyType());
}
} catch (IntrospectionException e) {
throw new OpenEJBException("Class " + javaClass + " is not a valid javabean", e);
}
// Map the elements nexted in the XML Schema Type
for (XmlElementInfo nestedElement : xmlTypeInfo.elements.values()) {
String fieldName = nestedElement.qname.getLocalPart();
Class javaType = propertyToClass.get(fieldName);
if (javaType == null) {
throw new OpenEJBException("Field " + fieldName + " is not defined by class " + javaClass.getName());
}
JaxRpcFieldInfo fieldInfo = new JaxRpcFieldInfo();
fieldInfo.name = fieldName;
fieldInfo.isNillable = nestedElement.nillable;
fieldInfo.xmlName = nestedElement.qname;
fieldInfo.xmlType = nestedElement.xmlType;
if (javaType.isArray()) {
fieldInfo.minOccurs = nestedElement.minOccurs;
fieldInfo.maxOccurs = nestedElement.maxOccurs;
}
typeInfo.fields.add(fieldInfo);
}
}
Aggregations