Made several changes that result in considerable performance improvements:

- Fields inside the IsoMessage are now stored in an IsoValue[] instead of a map (this avoids the sorting step when encoding)
- The constructor IsoValue(IsoType, T, int, CustomField) for LLVAR and LLLVAR types uses the received length parameter instead of reencoding the value with the CustomField; this results in much faster parsing performance.
- FieldParseInfo passes the length of LLVAR and LLLVAR fields to the IsoValue constructor so that reencoding the value (or getting the length of the string) is not necessary. Field header length is checked to be digits when parsing ASCII.
- IsoType now parses AMOUNT values as BigDecimals.
- MessageFactory has separate code for parsing binary and ASCII messages.

Also, the DTD was moved to the resources directory.


git-svn-id: https://j8583.svn.sourceforge.net/svnroot/j8583/j8583@56 db60a039-f72e-0410-b1d2-baa000846441
This commit is contained in:
chochos
2010-11-29 19:27:25 +00:00
parent 2a7d4063e2
commit b1e09634d6
7 changed files with 87 additions and 56 deletions
@@ -313,25 +313,46 @@ public class MessageFactory {
return m;
}
//Now we parse each field
for (Integer i : index) {
FieldParseInfo fpi = parseGuide.get(i);
if (bs.get(i - 1)) {
if (ignoreLast && pos >= buf.length && i == index.get(index.size() -1)) {
log.warn("Field {} is not really in the message even though it's in the bitmap", i);
bs.clear(i - 1);
} else {
IsoValue<?> val = useBinary ? fpi.parseBinary(buf, pos, getCustomField(i)) : fpi.parse(buf, pos, getCustomField(i));
m.setField(i, val);
if (useBinary && !(val.getType() == IsoType.ALPHA || val.getType() == IsoType.LLVAR
|| val.getType() == IsoType.LLLVAR)) {
pos += (val.getLength() / 2) + (val.getLength() % 2);
if (useBinary) {
for (Integer i : index) {
FieldParseInfo fpi = parseGuide.get(i);
if (bs.get(i - 1)) {
if (ignoreLast && pos >= buf.length && i == index.get(index.size() -1)) {
log.warn("Field {} is not really in the message even though it's in the bitmap", i);
bs.clear(i - 1);
} else {
pos += val.getLength();
IsoValue<?> val = fpi.parseBinary(buf, pos, getCustomField(i));
m.setField(i, val);
if (!(val.getType() == IsoType.ALPHA || val.getType() == IsoType.LLVAR
|| val.getType() == IsoType.LLLVAR)) {
pos += (val.getLength() / 2) + (val.getLength() % 2);
} else {
pos += val.getLength();
}
if (val.getType() == IsoType.LLVAR) {
pos++;
} else if (val.getType() == IsoType.LLLVAR) {
pos += 2;
}
}
if (val.getType() == IsoType.LLVAR) {
pos += useBinary ? 1 : 2;
} else if (val.getType() == IsoType.LLLVAR) {
pos += useBinary ? 2 : 3;
}
}
} else {
for (Integer i : index) {
FieldParseInfo fpi = parseGuide.get(i);
if (bs.get(i - 1)) {
if (ignoreLast && pos >= buf.length && i == index.get(index.size() -1)) {
log.warn("Field {} is not really in the message even though it's in the bitmap", i);
bs.clear(i - 1);
} else {
IsoValue<?> val = fpi.parse(buf, pos, getCustomField(i));
m.setField(i, val);
pos += val.getLength();
if (val.getType() == IsoType.LLVAR) {
pos += 2;
} else if (val.getType() == IsoType.LLLVAR) {
pos += 3;
}
}
}
}
@@ -404,6 +425,14 @@ public class MessageFactory {
return typeTemplates.get(type);
}
public void freeze() {
typeTemplates = Collections.unmodifiableMap(typeTemplates);
parseMap = Collections.unmodifiableMap(parseMap);
parseOrder = Collections.unmodifiableMap(parseOrder);
isoHeaders = Collections.unmodifiableMap(isoHeaders);
customFields = Collections.unmodifiableMap(customFields);
}
/** Sets a map with the fields that are to be expected when parsing a certain type of
* message.
* @param type The message type.