in modules/adb/src/org/apache/axis2/databinding/utils/BeanUtil.java [123:410]
private static List<Object> getPropertyQnameList(Object beanObject,
Class<?> beanClass,
QName beanName,
TypeTable typeTable,
boolean qualified,
boolean processingDocLitBare) {
List<Object> propertyQnameValueList;
Class<?> supperClass = beanClass.getSuperclass();
if (!getQualifiedName(supperClass.getPackage()).startsWith("java.")) {
propertyQnameValueList = getPropertyQnameList(beanObject,
supperClass, beanName, typeTable, qualified, processingDocLitBare);
} else {
propertyQnameValueList = new ArrayList<Object>();
}
try {
QName elemntNameSpace = null;
if (typeTable != null && qualified) {
QName qNamefortheType = typeTable.getQNamefortheType(beanClass.getName());
if (qNamefortheType == null) {
qNamefortheType = typeTable.getQNamefortheType(beanClass.getPackage().getName());
}
if (qNamefortheType == null) {
throw new AxisFault("Mapping qname not fond for the package: " +
beanObject.getClass().getPackage().getName());
}
elemntNameSpace = new QName(qNamefortheType.getNamespaceURI(), "elementName", qNamefortheType.getPrefix());
}
AxisService axisService = null;
if (MessageContext.getCurrentMessageContext() != null) {
axisService = MessageContext.getCurrentMessageContext().getAxisService();
}
BeanExcludeInfo beanExcludeInfo = null;
if (axisService != null && axisService.getExcludeInfo() != null) {
beanExcludeInfo = axisService.getExcludeInfo().getBeanExcludeInfoForClass(beanClass.getName());
}
BeanInfo beanInfo = getBeanInfo(beanClass, beanClass.getSuperclass());
PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor property : properties) {
String propertyName = property.getName();
Class<?> ptype = property.getPropertyType();
if (propertyName.equals("class") ||
beanExcludeInfo != null && beanExcludeInfo.isExcludedProperty(propertyName) || ptype == null) {
continue;
}
Method readMethod = property.getReadMethod();
if (readMethod == null) {
Class propertyType = property.getPropertyType();
if (propertyType == java.lang.Boolean.class) {
Method writeMethod = property.getWriteMethod();
if (writeMethod != null) {
String tmpWriteMethodName = writeMethod.getName();
PropertyDescriptor tmpPropDesc =
new PropertyDescriptor(property.getName(),
beanObject.getClass(),
"is" + tmpWriteMethodName.substring(3),
tmpWriteMethodName);
readMethod = tmpPropDesc.getReadMethod();
}
}
}
Object value;
if (readMethod != null) {
readMethod.setAccessible(true);
value = readMethod.invoke(beanObject);
} else {
throw new AxisFault("Property '" + propertyName + "' in bean class '"
+ beanClass.getName() + "'is not readable.");
}
if (SimpleTypeMapper.isSimpleType(ptype)) {
addTypeQname(elemntNameSpace, propertyQnameValueList, property,
beanName, processingDocLitBare);
propertyQnameValueList.add(
value == null ? null : SimpleTypeMapper.getStringValue(value));
} else if(SimpleTypeMapper.isDomDocument(ptype)){
addTypeQname(elemntNameSpace, propertyQnameValueList, property,
beanName, processingDocLitBare);
OMFactory fac = OMAbstractFactory.getOMFactory();
propertyQnameValueList.add(convertDOMtoOM(fac, value));
} else if (ptype.isArray()) {
if (SimpleTypeMapper.isSimpleType(ptype.getComponentType())) {
if (value != null) {
if (Byte.TYPE.equals(ptype.getComponentType())) {
addTypeQname(elemntNameSpace, propertyQnameValueList,
property, beanName, processingDocLitBare);
propertyQnameValueList.add(Base64Utils.encode((byte[]) value));
} else {
int i1 = Array.getLength(value);
for (int j = 0; j < i1; j++) {
Object o = Array.get(value, j);
addTypeQname(elemntNameSpace, propertyQnameValueList,
property, beanName, processingDocLitBare);
propertyQnameValueList.add(o == null ? null :
SimpleTypeMapper.getStringValue(o));
}
}
} else {
addTypeQname(elemntNameSpace, propertyQnameValueList, property,
beanName, processingDocLitBare);
propertyQnameValueList.add(value);
}
} else {
if (value != null) {
for (Object o : (Object[]) value) {
addTypeQname(elemntNameSpace, propertyQnameValueList,
property, beanName, processingDocLitBare);
QName propertyQName = null;
if (elemntNameSpace != null) {
propertyQName = new QName(
elemntNameSpace.getNamespaceURI(),
propertyName,
elemntNameSpace.getPrefix());
} else {
propertyQName = new QName(propertyName);
}
if (SimpleTypeMapper
.isObjectArray(o.getClass())
|| SimpleTypeMapper
.isMultidimensionalObjectArray(o
.getClass())) {
/**
* If it is a Object[] we need to add instance type
* attributes to the response message.
* Copied from ADBXMLStreamReaderImpl.
* For inner Arrary Complex types we use the special local name array - "array"
*/
QName itemName;
if (qualified) {
itemName = new QName(elemntNameSpace.getNamespaceURI(),
Constants.INNER_ARRAY_COMPLEX_TYPE_NAME,
elemntNameSpace.getPrefix());
} else {
itemName = new QName(Constants.INNER_ARRAY_COMPLEX_TYPE_NAME);
}
propertyQnameValueList.add(getOMElement(propertyQName , (Object[]) o,
itemName, qualified, typeTable));
} else {
if(SimpleTypeMapper.isObjectArray(value.getClass())){
OMFactory fac = OMAbstractFactory.getOMFactory();
OMElement element = fac.createOMElement(propertyQName);
element.addChild(fac.createOMText(SimpleTypeMapper.getStringValue(o)));
addInstanceTypeAttribute(fac, element, o, typeTable);
propertyQnameValueList.add(element);
} else {
propertyQnameValueList.add(o);
}
}
}
} else {
addTypeQname(elemntNameSpace, propertyQnameValueList, property,
beanName, processingDocLitBare);
propertyQnameValueList.add(value);
}
}
} else if (SimpleTypeMapper.isCollection(ptype) && value != null) {
if (typeTable != null) {
OMFactory fac = OMAbstractFactory.getOMFactory();
QName qNamefortheType = null;
qNamefortheType = (QName) typeTable
.getComplexSchemaMap().get(getClassName(beanClass));
Type genericType = property.getReadMethod().getGenericReturnType();
OMElement collection = BeanUtil.getCollectionElement(
fac, genericType,
(Collection) value, propertyName,null,
qNamefortheType,typeTable,
qualified);
// addTypeQname(elemntNameSpace, propertyQnameValueList,
// property, beanName, processingDocLitBare);
Iterator childItr = collection.getChildren();
while(childItr.hasNext()){
addTypeQname(elemntNameSpace, propertyQnameValueList,
property, beanName, processingDocLitBare);
propertyQnameValueList.add(childItr.next());
}
} else {
Collection<?> objList = (Collection<?>) value;
if (objList != null && objList.size() > 0) {
//this was given error , when the array.size = 0
// and if the array contain simple type , then the ADBPullParser asked
// PullParser from That simpel type
for (Object o : objList) {
if (SimpleTypeMapper.isSimpleType(o)) {
addTypeQname(elemntNameSpace, propertyQnameValueList,
property, beanName, processingDocLitBare);
propertyQnameValueList.add(o);
} else {
addTypeQname(elemntNameSpace, propertyQnameValueList,
property, beanName, processingDocLitBare);
propertyQnameValueList.add(o);
}
}
} else {
addTypeQname(elemntNameSpace, propertyQnameValueList, property,
beanName, processingDocLitBare);
propertyQnameValueList.add(value);
}
}
} else if (SimpleTypeMapper.isMap(ptype) && value != null) {
OMFactory fac = OMAbstractFactory.getOMFactory();
QName qNamefortheType = (QName) typeTable
.getComplexSchemaMap().get(getClassName(beanClass));
OMNamespace ns = fac.createOMNamespace(
qNamefortheType.getNamespaceURI(),
qNamefortheType.getPrefix());
List<OMElement> mapEntries = getMapElement(fac,
ptype, (Map) value, typeTable, qualified);
OMElement map = fac.createOMElement(propertyName,
qNamefortheType.getNamespaceURI(),
qNamefortheType.getPrefix());
for (OMElement ele : mapEntries) {
map.addChild(ele);
}
addTypeQname(elemntNameSpace, propertyQnameValueList,
property, beanName, processingDocLitBare);
propertyQnameValueList.add(map);
} else if (SimpleTypeMapper.isEnum(ptype)){
addTypeQname(elemntNameSpace, propertyQnameValueList, property,
beanName, processingDocLitBare);
propertyQnameValueList.add(
value == null ? null : SimpleTypeMapper.getStringValue(value.toString()));
}else {
addTypeQname(elemntNameSpace, propertyQnameValueList, property,
beanName, processingDocLitBare);
if (Object.class.equals(ptype) && value != null) {
//this is required to match this element prefix as
//root element's prefix.
QName qNamefortheType = (QName) typeTable
.getComplexSchemaMap().get(
getClassName(beanClass));
OMFactory fac = OMAbstractFactory.getOMFactory();
QName elementName;
OMElement element;
if (elemntNameSpace != null) {
elementName = new QName(
elemntNameSpace.getNamespaceURI(),
property.getName(),
qNamefortheType.getPrefix());
} else {
elementName = new QName(property.getName());
}
if(SimpleTypeMapper.isSimpleType(value)){
element = fac.createOMElement(elementName);
element.addChild(fac.createOMText(SimpleTypeMapper
.getStringValue(value)));
}else{
XMLStreamReader xr = BeanUtil.getPullParser(value,
elementName, typeTable, qualified, false);
OMXMLParserWrapper stAXOMBuilder =
OMXMLBuilderFactory.createStAXOMBuilder(
OMAbstractFactory.getOMFactory(), new StreamWrapper(xr));
element = stAXOMBuilder.getDocumentElement();
}
addInstanceTypeAttribute(fac, element, value, typeTable);
propertyQnameValueList.add(element);
continue;
}
propertyQnameValueList.add(value);
}
}
return propertyQnameValueList;
} catch (java.io.IOException e) {
throw new RuntimeException(e);
} catch (java.beans.IntrospectionException e) {
throw new RuntimeException(e);
} catch (java.lang.reflect.InvocationTargetException e) {
throw new RuntimeException(e);
} catch (java.lang.IllegalAccessException e) {
throw new RuntimeException(e);
}
}