use of org.directwebremoting.convert.PlainProperty in project ma-core-public by infiniteautomation.
the class H3BeanConverter method getPropertyMapFromObject.
/*
* (non-Javadoc)
*
* @see
* org.directwebremoting.convert.BeanConverter#getPropertyMapFromObject(
* java.lang.Object, boolean, boolean)
*/
public Map getPropertyMapFromObject(Object example, boolean readRequired, boolean writeRequired) throws MarshallException {
Class clazz = getClass(example);
try {
BeanInfo info = Introspector.getBeanInfo(clazz);
PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
Map properties = new HashMap();
for (int i = 0; i < descriptors.length; i++) {
PropertyDescriptor descriptor = descriptors[i];
String name = descriptor.getName();
// We don't marshall getClass()
if (name.equals("class")) {
continue;
}
// And this is something added by hibernate
if (name.equals("hibernateLazyInitializer")) {
continue;
}
// Access rules mean we might not want to do this one
if (!isAllowedByIncludeExcludeRules(name)) {
continue;
}
if (readRequired && descriptor.getReadMethod() == null) {
continue;
}
if (writeRequired && descriptor.getWriteMethod() == null) {
continue;
}
if (!assumeSession) {
// We don't marshall un-initialized properties for
// Hibernate3
String propertyName = descriptor.getName();
Method method = findGetter(example, propertyName);
if (method == null) {
log.warn("Failed to find property: " + propertyName);
properties.put(name, new PlainProperty(propertyName, null));
continue;
}
if (!Hibernate.isPropertyInitialized(example, propertyName)) {
properties.put(name, new PlainProperty(propertyName, null));
continue;
}
// This might be a lazy-collection so we need to double
// check
Object retval = method.invoke(example, new Object[] {});
if (!Hibernate.isInitialized(retval)) {
properties.put(name, new PlainProperty(propertyName, null));
continue;
}
}
properties.put(name, new H3PropertyDescriptorProperty(descriptor));
}
return properties;
} catch (Exception ex) {
throw new MarshallException(clazz, ex);
}
}
Aggregations