private void writeProperty( StreamWriter writer, EntityMetadata entityMetadata, EntityProperty property) { String elementText = entityMetadata.getPropertyValueAsString(property); writer.startElement(new QName(d, property.getName(), "d")); EdmType type = MetadataOData4j.termValueToEdmType( entityMetadata.getTermValue(property.getFullyQualifiedName(), TermValueType.TERM_NAME)); boolean isNullable = entityMetadata.isPropertyNullable(property.getFullyQualifiedName()); // Append Type Attribute if (!type.equals(EdmSimpleType.STRING)) { writer.writeAttribute(new QName(m, "type", "m"), type.getFullyQualifiedTypeName()); } // Append Null attribute if (isNullable && (elementText.isEmpty()) && !type.equals(EdmSimpleType.STRING)) { writer.writeAttribute(new QName(m, "null", "m"), "true"); } // Write the property text if (type.equals(EdmSimpleType.DATETIME) && !elementText.isEmpty()) { // Write dates in UTC format SimpleDateFormat formatUTC = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); formatUTC.setTimeZone(TimeZone.getTimeZone("UTC")); writer.writeElementText(formatUTC.format((Date) property.getValue())); } else if (elementText != null) { writer.writeElementText(elementText); } writer.endElement(); }
private String getAbsoluteId( String baseUri, String entitySetName, Entity entity, EntityMetadata entityMetadata) { String absId = ""; for (String key : entityMetadata.getIdFields()) { EntityProperty prop = entity.getProperties().getProperty(entityMetadata.getSimplePropertyName(key)); if (prop != null) { absId += absId.isEmpty() ? (!baseUri.endsWith("/") ? baseUri + "/" : baseUri) + entitySetName : ","; if (entityMetadata.isPropertyNumber(prop.getFullyQualifiedName())) { absId += "(" + entityMetadata.getPropertyValueAsString(prop) + ")"; } else { absId += "('" + entityMetadata.getPropertyValueAsString(prop) + "')"; } } } return absId; }