if (field != null) {
if (!field.isElement()) {
continue;
}
ElementDesc element = (ElementDesc)field;
// If we're SOAP encoded, just use the local part,
// not the namespace. Otherwise use the whole
// QName.
if (isEncoded) {
qname = new QName(element.getXmlName().getLocalPart());
} else {
qname = element.getXmlName();
}
isOmittable = element.isMinOccursZero();
isNillable = element.isNillable();
xmlType = element.getXmlType();
}
}
if (qname == null) {
qname = new QName(isEncoded ? "" : name.getNamespaceURI(),
propName);
}
if (xmlType == null) {
// look up the type QName using the class
xmlType = context.getQNameForClass(javaType);
}
// Read the value from the property
if(propertyDescriptor[i].isReadable()) {
if (!propertyDescriptor[i].isIndexed()) {
// Normal case: serialize the value
Object propValue =
propertyDescriptor[i].get(value);
if (propValue == null) {
// an element cannot be null if nillable property is set to
// "false" and the element cannot be omitted
if (!isNillable && !isOmittable) {
if (Number.class.isAssignableFrom(javaType)) {
// If we have a null and it's a number, though,
// we might turn it into the appropriate kind of 0.
// TODO : Should be caching these constructors?
try {
Constructor constructor =
javaType.getConstructor(
SimpleDeserializer.STRING_CLASS);
propValue = constructor.newInstance(ZERO_ARGS);
} catch (Exception e) {
// If anything goes wrong here, oh well we tried.
}
}
if (propValue == null) {
throw new IOException(
Messages.getMessage(
"nullNonNillableElement",
propName));
}
}
// if meta data says minOccurs=0, then we can skip
// it if its value is null and we aren't doing SOAP
// encoding.
if (isOmittable && !isEncoded) {
continue;
}
}
context.serialize(qname,
null,
propValue,
xmlType);
} else {
// Collection of properties: serialize each one
int j=0;
while(j >= 0) {
Object propValue = null;
try {
propValue =
propertyDescriptor[i].get(value, j);
j++;
} catch (Exception e) {
j = -1;
}
if (j >= 0) {
context.serialize(qname, null,
propValue, xmlType);
}
}
}
}
}
BeanPropertyDescriptor anyDesc = typeDesc == null ? null :
typeDesc.getAnyDesc();
if (anyDesc != null) {
// If we have "extra" content here, it'll be an array
// of MessageElements. Serialize each one.
Object anyVal = anyDesc.get(value);
if (anyVal != null && anyVal instanceof MessageElement[]) {
MessageElement [] anyContent = (MessageElement[])anyVal;
for (int i = 0; i < anyContent.length; i++) {
MessageElement element = anyContent[i];
element.output(context);
}
}
}
} catch (InvocationTargetException ite) {
Throwable target = ite.getTargetException();