processedTypeMap.put(object.getClass(), newType);
try {
newType.populateMetaData(this.configurator, this.processedTypeMap);
newType.generateSchema(this.configurator, this.schemaMap);
} catch (MetaDataPopulateException e) {
new XmlSerializingException("Problem in processing new type", e);
} catch (SchemaGenerationException e) {
new XmlSerializingException("Problem in processing new type", e);
}
}
type = (Type) processedTypeMap.get(object.getClass());
writeTypeAttribute(writer, type.getXmlType().getQname(), namespacePrefix);
}
if (type.getXmlType().isSimpleType()) {
// this is a know type for us
// get the string represenation of this object using converter util class.
if (!type.getJavaClass().equals(Object.class)) {
writer.writeCharacters(getSimpleTypeStringValue(type, object));
}
} else {
// this is a complex type
try {
AttributeField attributeField;
Method getterMethod;
Object attributeFieldValue;
QName attributeQName;
for (Iterator iter = type.getAllAttributeFields().iterator(); iter.hasNext();) {
attributeField = (AttributeField) iter.next();
getterMethod = attributeField.getGetterMethod();
attributeFieldValue = getterMethod.invoke(object, new Object[]{});
attributeQName = new QName(attributeField.getNamespace(), attributeField.getName());
// calls to write attribute. for attributes we can have only simple types
if (attributeFieldValue != null) {
writeAttribute(writer,
getSimpleTypeStringValue(attributeField.getType(), attributeFieldValue),
attributeQName,
namespacePrefix);
} else if (attributeField.isRequried()) {
throw new XmlSerializingException("Attribute value for attribute "
+ attributeField.getName() + " is required");
}
}
// write the element fields
ElementField elementField;
Object elementFieldValue;
for (Iterator iter = type.getAllElementFields().iterator(); iter.hasNext();) {
elementField = (ElementField) iter.next();
getterMethod = elementField.getGetterMethod();
elementFieldValue = getterMethod.invoke(object, new Object[]{});
serializeElementField(elementFieldValue,
elementField,
writer,
namespacePrefix);
}
} catch (IllegalAccessException e) {
throw new XmlSerializingException("problem with method inovocation " + type.getName());
} catch (InvocationTargetException e) {
throw new XmlSerializingException("problem with method inovocation " + type.getName());
}
}
}
writer.writeEndElement();