*/
public Object unmarshal(Object obj, IUnmarshallingContext ictx)
throws JiBXException {
// make sure we're at the appropriate start tag
UnmarshallingContext ctx = (UnmarshallingContext)ictx;
if (!ctx.isAt(m_uri, m_name)) {
ctx.throwStartTagNameError(m_uri, m_name);
}
// lookup the prefixes assigned to required namespaces
int nscnt = ctx.getActiveNamespaceCount();
String xsdlead = null;
for (int i = nscnt-1; i >= 0; i--) {
String uri = ctx.getActiveNamespaceUri(i);
if (XSD_NAMESPACE_URI.equals(uri)) {
String prefix = ctx.getActiveNamespacePrefix(i);
if (!"".equals(prefix)) {
xsdlead = prefix + ':';
break;
}
}
}
if (xsdlead == null) {
throw new JiBXException
("Missing required schema namespace declaration");
}
// create new hashmap if needed
int size = ctx.attributeInt(m_uri, SIZE_ATTRIBUTE_NAME, DEFAULT_SIZE);
Map map = (Map)obj;
if (map == null) {
map = new HashMap(size);
}
// process all entries present in document
ctx.parsePastStartTag(m_uri, m_name);
String tdflt = xsdlead + "string";
while (ctx.isAt(m_uri, ENTRY_ELEMENT_NAME)) {
// unmarshal key and type from start tag attributes
Object key = ctx.attributeText(m_uri, KEY_ATTRIBUTE_NAME);
String tname = ctx.attributeText(XSI_NAMESPACE_URI,
TYPE_ATTRIBUTE_NAME, tdflt);
// convert type name to type index number
int type = -1;
if (tname.startsWith(xsdlead)) {
type = s_schemaTypesEnum.
getValue(tname.substring(xsdlead.length()));
}
if (type < 0) {
throw new JiBXException("Value of type " + tname +
" with key " + key + " is not a supported type");
}
// deserialize content as specified type
String text = ctx.parseElementText(m_uri, ENTRY_ELEMENT_NAME);
Object value = null;
switch (type) {
case BOOLEAN_TYPE:
value = Utility.parseBoolean(text) ?
Boolean.TRUE : Boolean.FALSE;
break;
case BYTE_TYPE:
value = new Byte(Utility.parseByte(text));
break;
case DOUBLE_TYPE:
value = new Double(Utility.parseDouble(text));
break;
case FLOAT_TYPE:
value = new Float(Utility.parseFloat(text));
break;
case INT_TYPE:
value = new Integer(Utility.parseInt(text));
break;
case LONG_TYPE:
value = new Long(Utility.parseLong(text));
break;
case SHORT_TYPE:
value = new Short(Utility.parseShort(text));
break;
case DATETIME_TYPE:
value = Utility.deserializeDateTime(text);
break;
//#!j2me{
case DATE_TYPE:
value = Utility.deserializeSqlDate(text);
break;
case TIME_TYPE:
value = Utility.deserializeSqlTime(text);
break;
//#j2me}
case BYTERRAY_TYPE:
value = Utility.deserializeBase64(text);
break;
case DECIMAL_TYPE:
value = new BigDecimal(text);
break;
case INTEGER_TYPE:
value = new BigInteger(text);
break;
case STRING_TYPE:
value = text;
break;
}
// add key-value pair to map
map.put(key, value);
}
// finish by skipping past wrapper end tag
ctx.parsePastEndTag(m_uri, m_name);
return map;
}