use of java.beans.BeanInfo in project geronimo-xbean by apache.
the class XBeanNamespaceHandler method getPropertyDescriptor.
/**
* Looks up the property decriptor for the given class and property name
*/
protected PropertyDescriptor getPropertyDescriptor(String className, String localName) {
BeanInfo beanInfo = qnameHelper.getBeanInfo(className);
if (beanInfo != null) {
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < descriptors.length; i++) {
PropertyDescriptor descriptor = descriptors[i];
String name = descriptor.getName();
if (name.equals(localName)) {
return descriptor;
}
}
}
return null;
}
use of java.beans.BeanInfo in project geronimo-xbean by apache.
the class XBeanQNameHelper method coerceNamespaceAwarePropertyValues.
/**
* Any namespace aware property values (such as QNames) need to be coerced
* while we still have access to the XML Element from which its value comes -
* so lets do that now before we trash the DOM and just have the bean
* definition.
*/
public void coerceNamespaceAwarePropertyValues(BeanDefinition definition, Element element) {
if (definition instanceof AbstractBeanDefinition && isQnameIsOnClassPath()) {
AbstractBeanDefinition bd = (AbstractBeanDefinition) definition;
// lets check for any QName types
BeanInfo beanInfo = getBeanInfo(bd.getBeanClassName());
if (beanInfo != null) {
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < descriptors.length; i++) {
QNameReflectionHelper.coerceNamespaceAwarePropertyValues(bd, element, descriptors, i);
}
}
}
}
use of java.beans.BeanInfo in project jaffa-framework by jaffa-projects.
the class JmsQueueAdmin method createMessageGraph.
/**
* Molds the input JMS Message into a MessageGraph.
*/
private static MessageGraph createMessageGraph(Message message, String queueName, PropertyFilter pf) throws JMSException, IntrospectionException {
MessageGraph graph = new MessageGraph();
graph.setQueueMetaData(createQueueMetaData(queueName, pf));
if (pf.isFieldIncluded("type"))
graph.setType(queueName);
if (pf.isFieldIncluded("messageId"))
graph.setMessageId(message.getJMSMessageID());
if (pf.isFieldIncluded("priority"))
graph.setPriority(new Long(message.getJMSPriority()));
if (pf.isFieldIncluded("createdOn"))
graph.setCreatedOn(message.getJMSTimestamp() != 0 ? new DateTime(message.getJMSTimestamp()) : null);
if (pf.isFieldIncluded("createdBy"))
graph.setCreatedBy(message.getStringProperty(JmsBrowser.HEADER_USER_ID));
if (pf.isFieldIncluded("errorMessage"))
graph.setErrorMessage(message.getStringProperty(JmsBrowser.HEADER_ERROR_DETAILS));
if (pf.isFieldIncluded("payload") && message instanceof TextMessage)
graph.setPayload(((TextMessage) message).getText());
if (pf.isFieldIncluded("hasAdminAccess"))
graph.setHasAdminAccess(JmsBrowser.hasAdminMessageAccess(queueName));
if (pf.isFieldIncluded("applicationFields") || pf.isFieldIncluded("technicalFields")) {
// Generate a Map of header elements, keyed by the name of each header element
// Names beginning with JMS and jaffa_ will be treated as techincal, while the rest will be assumed to be application-specific
Map<String, MessageField> applicationFields = new LinkedHashMap<String, MessageField>();
Map<String, MessageField> technicalFields = new TreeMap<String, MessageField>();
for (Enumeration e = message.getPropertyNames(); e.hasMoreElements(); ) {
String name = (String) e.nextElement();
String value = Formatter.format(message.getObjectProperty(name));
MessageField messageField = new MessageField();
messageField.setName(name);
messageField.setValue(value);
if (name.startsWith("JMS") || name.startsWith("jaffa_"))
technicalFields.put(name, messageField);
else
applicationFields.put(name, messageField);
}
// Treat all the JMS* properties of the Message as technical
if (pf.isFieldIncluded("technicalFields")) {
BeanInfo beanInfo = Introspector.getBeanInfo(Message.class);
if (beanInfo != null) {
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
if (pds != null) {
for (PropertyDescriptor pd : pds) {
if (pd.getReadMethod() != null && !pd.getPropertyType().isArray()) {
String name = pd.getName();
try {
Object value = pd.getReadMethod().invoke(message);
MessageField messageField = new MessageField();
messageField.setName(name);
messageField.setValue(Formatter.format(value));
technicalFields.put(name, messageField);
} catch (Exception e) {
if (log.isDebugEnabled())
log.debug("Exception thrown while reading Message property: " + name, e);
}
}
}
}
}
if (!technicalFields.isEmpty())
graph.setTechnicalFields(technicalFields.values().toArray(new MessageField[technicalFields.size()]));
}
// Add labels to the application-fields from the configuration-file
if (pf.isFieldIncluded("applicationFields")) {
QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName);
if (queueInfo != null && queueInfo.getDisplayParam() != null) {
for (DisplayParam displayParam : queueInfo.getDisplayParam()) {
if (displayParam.getLabel() != null && applicationFields.containsKey(displayParam.getName()))
applicationFields.get(displayParam.getName()).setLabel(MessageHelper.replaceTokens(displayParam.getLabel()));
}
}
if (!applicationFields.isEmpty())
graph.setApplicationFields(applicationFields.values().toArray(new MessageField[applicationFields.size()]));
}
}
return graph;
}
use of java.beans.BeanInfo in project jaffa-framework by jaffa-projects.
the class TransformerUtils method printGraph.
/**
* Same as printGraph(Object source), except the objectStack lists all the parent
* objects its printed, and if this is one of them, it stops. This allows detection
* of possible infinite recusion.
*
* @param source Javabean who's contents should be printed
* @param objectStack List of objects already traversed
* @return multi-line string of this beans properties and their values
*/
public static String printGraph(Object source, List objectStack) {
if (source == null)
return null;
// Prevent infinite object recursion
if (objectStack != null)
if (objectStack.contains(source))
return "Object Already Used. " + source.getClass().getName() + '@' + source.hashCode();
else
objectStack.add(source);
else {
objectStack = new ArrayList();
objectStack.add(source);
}
StringBuffer out = new StringBuffer();
out.append(source.getClass().getName());
out.append("\n");
try {
BeanInfo sInfo = Introspector.getBeanInfo(source.getClass());
PropertyDescriptor[] sDescriptors = sInfo.getPropertyDescriptors();
if (sDescriptors != null && sDescriptors.length != 0)
for (int i = 0; i < sDescriptors.length; i++) {
PropertyDescriptor sDesc = sDescriptors[i];
Method sm = sDesc.getReadMethod();
if (sm != null && sDesc.getWriteMethod() != null) {
if (!sm.isAccessible())
sm.setAccessible(true);
Object sValue = sm.invoke(source, (Object[]) null);
out.append(" ");
out.append(sDesc.getName());
if (source instanceof GraphDataObject) {
if (((GraphDataObject) source).hasChanged(sDesc.getName()))
out.append('*');
}
out.append('=');
if (sValue == null)
out.append("<--NULL-->\n");
else if (sm.getReturnType().isArray() && !sm.getReturnType().getComponentType().isPrimitive()) {
StringBuffer out2 = new StringBuffer();
out2.append("Array of ");
out2.append(sm.getReturnType().getComponentType().getName());
out2.append("\n");
// Loop through array
Object[] a = (Object[]) sValue;
for (int j = 0; j < a.length; j++) {
out2.append('[');
out2.append(j);
out2.append("] ");
if (a[j] == null)
out2.append("<--NULL-->");
else if (GraphDataObject.class.isAssignableFrom(a[j].getClass()))
out2.append(((GraphDataObject) a[j]).toString(objectStack));
else
// out2.append(StringHelper.linePad(a[j].toString(), 4, " ",true));
out2.append(a[j].toString());
}
out.append(StringHelper.linePad(out2.toString(), 4, " ", true));
} else {
if (GraphDataObject.class.isAssignableFrom(sValue.getClass()))
out.append(StringHelper.linePad(((GraphDataObject) sValue).toString(objectStack), 4, " ", true));
else {
out.append(StringHelper.linePad(sValue.toString(), 4, " ", true));
out.append("\n");
}
}
}
}
} catch (IllegalAccessException e) {
TransformException me = new TransformException(TransformException.ACCESS_ERROR, "???", e.getMessage());
log.error(me.getLocalizedMessage(), e);
// throw me;
} catch (InvocationTargetException e) {
TransformException me = new TransformException(TransformException.INVOCATION_ERROR, "???", e);
log.error(me.getLocalizedMessage(), me.getCause());
// throw me;
} catch (IntrospectionException e) {
TransformException me = new TransformException(TransformException.INTROSPECT_ERROR, "???", e.getMessage());
log.error(me.getLocalizedMessage(), e);
// throw me;
}
return out.toString();
}
use of java.beans.BeanInfo in project yamcs-studio by yamcs.
the class DefaultWidgetIntrospector method getBeanInfo.
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
Introspector.flushFromCaches(beanClass);
BeanInfo bi = Introspector.getBeanInfo(beanClass);
BeanDescriptor bd = bi.getBeanDescriptor();
MethodDescriptor[] mds = bi.getMethodDescriptors();
EventSetDescriptor[] esds = bi.getEventSetDescriptors();
PropertyDescriptor[] pds = bi.getPropertyDescriptors();
List<PropertyDescriptor> filteredPDList = new ArrayList<PropertyDescriptor>();
List<String> nonPropList = Arrays.asList(getNonProperties());
for (PropertyDescriptor pd : pds) {
if (!nonPropList.contains(pd.getName()) && pd.getWriteMethod() != null && pd.getReadMethod() != null)
filteredPDList.add(pd);
}
int defaultEvent = bi.getDefaultEventIndex();
int defaultProperty = bi.getDefaultPropertyIndex();
return new GenericBeanInfo(bd, esds, defaultEvent, filteredPDList.toArray(new PropertyDescriptor[filteredPDList.size()]), defaultProperty, mds, null);
}
Aggregations