throw new JiBXException("Invalid object type for marshaller");
} else {
// start by setting up added namespaces
MarshallingContext ctx = (MarshallingContext)ictx;
IXMLWriter xwrite = ctx.getXmlWriter();
int ixsi = xwrite.getNamespaces().length;
String[][] extens = xwrite.getExtensionNamespaces();
if (extens != null) {
for (int i = 0; i < extens.length; i++) {
ixsi += extens[i].length;
}
}
xwrite.pushExtensionNamespaces(SCHEMA_NAMESPACE_URIS);
// generate start tag for containing element
Map map = (Map)obj;
ctx.startTagNamespaces(m_index, m_name, new int[] { ixsi, ixsi+1 },
SCHEMA_NAMESPACE_PREFIXES).
attribute(m_index, SIZE_ATTRIBUTE_NAME, map.size()).
closeStartContent();
// loop through all entries in hashmap
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
// first make sure we have a value
Map.Entry entry = (Map.Entry)iter.next();
Object value = entry.getValue();
if (value != null) {
// write element with key attribute
ctx.startTagAttributes(m_index, ENTRY_ELEMENT_NAME);
ctx.attribute(m_index, KEY_ATTRIBUTE_NAME,
entry.getKey().toString());
// translate value object class to schema type
String tname = value.getClass().getName();
int type = s_javaTypesEnum.getValue(tname);
if (type < 0) {
throw new JiBXException("Value of type " + tname +
" with key " + entry.getKey() +
" is not a supported type");
}
// generate xsi:type attribute for value
ctx.attribute(ixsi, TYPE_ATTRIBUTE_NAME,
XSD_PREFIX_LEAD + s_schemaTypesEnum.getName(type));
ctx.closeStartContent();
// handle the actual value conversion based on type
switch (type) {
case BOOLEAN_TYPE:
ctx.content(Utility.serializeBoolean
(((Boolean)value).booleanValue()));
break;
case BYTE_TYPE:
ctx.content(Utility.
serializeByte(((Byte)value).byteValue()));
break;
case DOUBLE_TYPE:
ctx.content(Utility.
serializeDouble(((Double)value).doubleValue()));
break;
case FLOAT_TYPE:
ctx.content(Utility.
serializeFloat(((Float)value).floatValue()));
break;
case INT_TYPE:
ctx.content(((Integer)value).intValue());
break;
case LONG_TYPE:
ctx.content(Utility.
serializeLong(((Long)value).longValue()));
break;
case SHORT_TYPE:
ctx.content(Utility.
serializeShort(((Short)value).shortValue()));
break;
case DATETIME_TYPE:
ctx.content(Utility.serializeDateTime((Date)value));
break;
//#!j2me{
case DATE_TYPE:
ctx.content(Utility.
serializeSqlDate((java.sql.Date)value));
break;
case TIME_TYPE:
ctx.content(Utility.
serializeSqlTime((java.sql.Time)value));
break;
//#j2me}
case BYTERRAY_TYPE:
ctx.content(Utility.serializeBase64((byte[])value));
break;
case DECIMAL_TYPE:
case INTEGER_TYPE:
case STRING_TYPE:
ctx.content(value.toString());
break;
}
// finish with close tag for entry element
ctx.endTag(m_index, ENTRY_ELEMENT_NAME);
}
}
// finish with end tag for container element
ctx.endTag(m_index, m_name);
xwrite.popExtensionNamespaces();
}
}