if (log.isTraceEnabled()) {
log.trace("Creating descriptor for property: name="
+ name + " type=" + type);
}
NodeDescriptor nodeDescriptor = null;
Method readMethod = propertyDescriptor.getReadMethod();
Method writeMethod = propertyDescriptor.getWriteMethod();
if ( readMethod == null ) {
if (log.isTraceEnabled()) {
log.trace( "No read method for property: name="
+ name + " type=" + type);
}
return null;
}
if ( log.isTraceEnabled() ) {
log.trace( "Read method=" + readMethod.getName() );
}
// choose response from property type
// XXX: ignore class property ??
if ( Class.class.equals( type ) && "class".equals( name ) ) {
log.trace( "Ignoring class property" );
return null;
}
if ( isPrimitiveType( type ) ) {
if (log.isTraceEnabled()) {
log.trace( "Primitive type: " + name);
}
if ( useAttributesForPrimitives ) {
if (log.isTraceEnabled()) {
log.trace( "Adding property as attribute: " + name );
}
nodeDescriptor = new AttributeDescriptor();
} else {
if (log.isTraceEnabled()) {
log.trace( "Adding property as element: " + name );
}
nodeDescriptor = new ElementDescriptor(true);
}
nodeDescriptor.setTextExpression( new MethodExpression( readMethod ) );
if ( writeMethod != null ) {
nodeDescriptor.setUpdater( new MethodUpdater( writeMethod ) );
}
} else if ( isLoopType( type ) ) {
if (log.isTraceEnabled()) {
log.trace("Loop type: " + name);
log.trace("Wrap in collections? " + introspector.isWrapCollectionsInElement());
}
ElementDescriptor loopDescriptor = new ElementDescriptor();
loopDescriptor.setContextExpression(
new IteratorExpression( new MethodExpression( readMethod ) )
);
loopDescriptor.setWrapCollectionsInElement(
introspector.isWrapCollectionsInElement());
// XXX: need to support some kind of 'add' or handle arrays, Lists or indexed properties
//loopDescriptor.setUpdater( new MethodUpdater( writeMethod ) );
if ( Map.class.isAssignableFrom( type ) ) {
loopDescriptor.setQualifiedName( "entry" );
// add elements for reading
loopDescriptor.addElementDescriptor( new ElementDescriptor( "key" ) );
loopDescriptor.addElementDescriptor( new ElementDescriptor( "value" ) );
}
ElementDescriptor elementDescriptor = new ElementDescriptor();
elementDescriptor.setWrapCollectionsInElement(
introspector.isWrapCollectionsInElement());
elementDescriptor.setElementDescriptors( new ElementDescriptor[] { loopDescriptor } );
nodeDescriptor = elementDescriptor;
} else {
if (log.isTraceEnabled()) {
log.trace( "Standard property: " + name);
}
ElementDescriptor elementDescriptor = new ElementDescriptor();
elementDescriptor.setContextExpression( new MethodExpression( readMethod ) );
if ( writeMethod != null ) {
elementDescriptor.setUpdater( new MethodUpdater( writeMethod ) );
}
nodeDescriptor = elementDescriptor;
}
if (nodeDescriptor instanceof AttributeDescriptor) {
// we want to use the attributemapper only when it is an attribute..
nodeDescriptor.setLocalName(
introspector.getAttributeNameMapper().mapTypeToElementName( name ) );
} else {
nodeDescriptor.setLocalName(
introspector.getElementNameMapper().mapTypeToElementName( name ) );
}
nodeDescriptor.setPropertyName( propertyDescriptor.getName() );
nodeDescriptor.setPropertyType( type );
// XXX: associate more bean information with the descriptor?
//nodeDescriptor.setDisplayName( propertyDescriptor.getDisplayName() );
//nodeDescriptor.setShortDescription( propertyDescriptor.getShortDescription() );