return desc;
}
private static void fillInTypeDesc(TypeDesc desc, Class beanClass)
throws Exception {
TypeMappingRegistry tmr = new TypeMappingRegistry();
desc.setJavaClass(beanClass);
BeanInfo beanInfo = Introspector.getBeanInfo(beanClass);
PropertyDescriptor [] propDescs = beanInfo.getPropertyDescriptors();
for (int i = 0; i < propDescs.length; i++) {
PropertyDescriptor propDesc = propDescs[i];
String name = propDesc.getName();
if (name.equals("class"))
continue;
BeanPropertyDescriptor beanDesc = new BeanPropertyDescriptor();
beanDesc.setReadMethod(propDesc.getReadMethod());
beanDesc.setWriteMethod(propDesc.getWriteMethod());
ElementDesc elDesc = desc.getElementDesc(name);
boolean addDesc = true; // Should we add this (new) element?
if (elDesc == null) {
elDesc = new ElementDesc();
elDesc.setFieldName(name);
} else {
addDesc = false; // Already present, so don't add it again
}
Class type;
boolean isCollection = false;
if (propDesc instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor iProp =
(IndexedPropertyDescriptor)propDesc;
beanDesc.setIndexedReadMethod(iProp.getIndexedReadMethod());
beanDesc.setIndexedWriteMethod(iProp.getIndexedWriteMethod());
type = iProp.getIndexedPropertyType();
elDesc.setIndexedAccessor(beanDesc);
isCollection = true;
} else {
type = propDesc.getPropertyType();
// TODO : check if this is a supported collection type
}
if (isCollection && elDesc.getMaxOccurs() == 0)
elDesc.setMaxOccurs(-1);
elDesc.setAccessor(beanDesc);
if (elDesc.getQName() == null) {
elDesc.setQName(new QName(name));
}
if (elDesc.getDeserializerFactory() == null) {
DeserializerFactory dser = tmr.getDeserializerFactory(type);
elDesc.setDeserializerFactory(dser);
}
if (elDesc.getRawSerializer() == null) {
Serializer ser = tmr.getSerializer(type);
elDesc.setSerializer(ser);
}
if (addDesc)
desc.addField(elDesc);