if (oAdm.isConnected()) oAdm.disconnect();
if (oAdm.isOpen()) oAdm.close();
}
}
} // fi
AttributeMultiValue oAttr;
Iterator<String> oKeys = keySet().iterator();
while (oKeys.hasNext()) {
String sKey = oKeys.next();
Object oVal = get(sKey);
if (oVal!=null) {
if (oVal instanceof String) {
oAttr = oDoc.attribute(sKey);
oAttr.set((String) oVal);
} else if (oVal instanceof Date) {
oAttr = oDoc.attribute(sKey);
if (oAttr.type().getDataType().equals(DataType.DATE))
oAttr.set((Date) (oVal));
else if (oAttr.type().getDataType().equals(DataType.DATE_TIME))
oAttr.set((long) DateConversions.getIPSATimeFromDate((Date) (oVal)));
else
throw new ClassCastException("Cannot bind Java "+oVal.getClass().getName()+" into "+sKey+" "+oAttr.type().getDataType().name());
} else if (oVal instanceof BigDecimal) {
oAttr = oDoc.attribute(sKey);
BigDecimal oDec = (BigDecimal) oVal;
try {
BigInteger oBig = oDec.toBigIntegerExact();
oAttr.set(oBig.longValue());
} catch (ArithmeticException ex) {
oAttr.set(oDec);
}
} else if (oVal instanceof Integer) {
oAttr = oDoc.attribute(sKey);
oAttr.set((long) ((Integer) oVal).intValue());
} else if (oVal instanceof Long) {
oAttr = oDoc.attribute(sKey);
oAttr.set(((Long) oVal).longValue());
} else if (oVal instanceof Float) {
oAttr = oDoc.attribute(sKey);
oAttr.set((double) ((Float) oVal).floatValue());
} else if (oVal instanceof Double) {
oAttr = oDoc.attribute(sKey);
oAttr.set(((Double) oVal).doubleValue());
} else if (oVal instanceof String[]) {
String[] aStrs = (String[]) oVal;
oAttr = oDoc.attribute(sKey);
if (!oAttr.type().isMultivaluable()) throw new AttributeTypeHasValuesException("Cannot set multiple values for attribute "+sKey);
int nVals = oAttr.count();
for (int c=0; c<aStrs.length; c++) {
if (c<nVals)
oAttr.get(c).set(aStrs[c]);
else
oAttr.add().set(aStrs[c]);
} // next
} else if (oVal instanceof BigDecimal[]) {
oAttr = oDoc.attribute(sKey);
if (!oAttr.type().isMultivaluable()) throw new AttributeTypeHasValuesException("Cannot set multiple values for attribute "+sKey);
int nVals = oAttr.count();
BigDecimal[] aDecs = (BigDecimal[]) oVal;
for (int c=0; c<aDecs.length; c++) {
try {
BigInteger oBig = aDecs[c].toBigIntegerExact();
if (c<nVals)
oAttr.get(c).set(oBig.longValue());
else
oAttr.add().set(oBig.longValue());
} catch (ArithmeticException ex) {
if (c<nVals)
oAttr.get(c).set(aDecs[c]);
else
oAttr.add().set(aDecs[c]);
}
} // next
} else {
throw new ClassCastException("Cannot bind Java "+oVal.getClass().getName()+" into "+sKey);
}