* @param simpleTypeTranslator SimpleTypeTranslator to perform lookup in
* @param value Object to base the lookup on
* @param schemaInstancePrefix the prefix representing the schema instance namespace
*/
private void addTypeAttributes(NodeList elements, XMLField field, Object value, String schemaInstancePrefix) {
NamespaceResolver namespaceResolver = field.getNamespaceResolver();
if (!field.isTypedTextField()) {
return;
}
List values;
if (value instanceof List) {
values = (List)value;
} else {
values = new ArrayList();
values.add(value);
}
int size = elements.getLength();
int valuesSize = values.size();
if (size != valuesSize) {
return;
}
Node next = null;
for (int i = 0; i < size; i++) {
next = elements.item(i);
if (next.getNodeType() == Node.ELEMENT_NODE) {
QName qname = field.getXMLType(values.get(i).getClass());
if (qname != null) {
if (null == schemaInstancePrefix) {
schemaInstancePrefix = namespaceResolver.generatePrefix(XMLConstants.SCHEMA_INSTANCE_PREFIX);
((Element)next).setAttributeNS(XMLConstants.XMLNS_URL, XMLConstants.XMLNS + ":" + schemaInstancePrefix, XMLConstants.SCHEMA_INSTANCE_URL);
}
String type;
String prefix = this.resolveNamespacePrefixForURI(qname.getNamespaceURI(), namespaceResolver);
if ((prefix == null) || (prefix.equals(""))) {
type = qname.getLocalPart();
prefix = namespaceResolver.generatePrefix();
((Element)next).setAttributeNS(XMLConstants.XMLNS_URL, XMLConstants.XMLNS + ":" + prefix, qname.getNamespaceURI());
}
type = prefix + ":" + qname.getLocalPart();
((Element)next).setAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL, schemaInstancePrefix + ":" + XMLConstants.SCHEMA_TYPE_ATTRIBUTE, type);
}