.getDeclaredFields()) {
String getter = "get"
+ field.getName().substring(0, 1)
.toUpperCase()
+ field.getName().substring(1);
Property prop = ((Metadata) getMetadata())
.getProperty(entity, field.getName());
if (prop != null) {
writeProperty(writer, entity, prop, getter,
nullAttrs);
}
}
}
private void writeProperty(XmlWriter writer, Object entity,
Property prop, String getter,
AttributesImpl nullAttrs) throws SAXException {
for (Method method : entity.getClass()
.getDeclaredMethods()) {
if (method.getReturnType() != null
&& getter.equals(method.getName())
&& method.getParameterTypes().length == 0) {
Object value = null;
try {
value = method.invoke(entity,
(Object[]) null);
} catch (Exception e) {
}
if (value != null) {
writer.startElement(
WCF_DATASERVICES_NAMESPACE,
prop.getName());
if (prop instanceof ComplexProperty) {
write(writer, value, nullAttrs);
} else {
writer.characters(TypeUtils.toEdm(
value, prop.getType()));
}
writer.endElement(
WCF_DATASERVICES_NAMESPACE,
prop.getName());
} else {
if (prop.isNullable()) {
writer.emptyElement(
WCF_DATASERVICES_NAMESPACE,
prop.getName(), prop.getName(),
nullAttrs);
} else {
getLogger().warning(
"The following property has a null value but is not marked as nullable: "
+ prop.getName());
writer.emptyElement(
WCF_DATASERVICES_NAMESPACE,
prop.getName());
}
}
break;
}
}