Skip to content

Commit

Permalink
jPOS-29 re-applied Robert's patch against r2980 using r2994 as a refe…
Browse files Browse the repository at this point in the history
…rence
  • Loading branch information
ar committed Oct 14, 2010
1 parent baafba4 commit b89db91
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 119 deletions.
2 changes: 1 addition & 1 deletion build.properties
@@ -1,4 +1,4 @@
# Thu Oct 14 17:50:30 UYST 2010
# Thu Oct 14 20:06:33 UYST 2010
version=1.6.9
revision=$Revision$
build.dir=build
Expand Down
69 changes: 39 additions & 30 deletions modules/jpos/src/org/jpos/iso/packager/GenericPackager.java
Expand Up @@ -29,9 +29,10 @@
import org.xml.sax.helpers.XMLReaderFactory;

import java.io.InputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Stack;
import java.util.TreeMap;


/**
Expand Down Expand Up @@ -147,16 +148,19 @@ public void setConfiguration (Configuration cfg)
}
}

@Override
protected int getMaxValidField()
{
return maxValidField;
}

@Override
protected boolean emitBitMap()
{
return emitBitmap;
}

@Override
protected ISOFieldPackager getBitMapfieldPackager()
{
return fld[bitmapField];
Expand Down Expand Up @@ -199,6 +203,7 @@ public void readFile(InputStream input) throws ISOException
throw new ISOException(e);
}
}
@Override
public void setLogger (Logger logger, String realm) {
super.setLogger (logger, realm);
if (fld != null) {
Expand Down Expand Up @@ -230,6 +235,7 @@ private XMLReader createXMLReader () throws SAXException {
reader.setErrorHandler(handler);
return reader;
}
@Override
public String getDescription () {
StringBuilder sb = new StringBuilder();
sb.append (super.getDescription());
Expand Down Expand Up @@ -269,13 +275,15 @@ private void setGenericPackagerParams (Attributes atts)

public class GenericContentHandler extends DefaultHandler
{
private Stack fieldStack;
private Stack<Object> fieldStack;

@Override
public void startDocument()
{
fieldStack = new Stack();
fieldStack = new Stack<Object>();
}

@Override
public void endDocument() throws SAXException
{
if (!fieldStack.isEmpty())
Expand All @@ -284,6 +292,7 @@ public void endDocument() throws SAXException
}
}

@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
throws SAXException
{
Expand All @@ -299,8 +308,8 @@ public void startElement(String namespaceURI, String localName, String qName, At

if (localName.equals("isopackager"))
{
// Stick a new Hashtable on stack to collect the fields
fieldStack.push(new Hashtable());
// Stick a new Map on stack to collect the fields
fieldStack.push(new TreeMap());

setGenericPackagerParams (atts);
}
Expand All @@ -313,7 +322,7 @@ public void startElement(String namespaceURI, String localName, String qName, At
1) an Integer indicating the field ID
2) an instance of the specified ISOFieldPackager class
3) an instance of the specified ISOBasePackager (msgPackager) class
4) a Hashtable to collect the subfields
4) a Map to collect the subfields
*/
String packager = atts.getValue("packager");

Expand All @@ -339,7 +348,7 @@ public void startElement(String namespaceURI, String localName, String qName, At
}
fieldStack.push(p);

fieldStack.push(new Hashtable());
fieldStack.push(new TreeMap());
}

if (localName.equals("isofield"))
Expand All @@ -354,10 +363,10 @@ public void startElement(String namespaceURI, String localName, String qName, At
if( f instanceof IF_TBASE){
((IF_TBASE)f).setToken( token );
}
// Insert this new isofield into the Hashtable
// Insert this new isofield into the Map
// on the top of the stack using the fieldID as the key
Hashtable ht = (Hashtable) fieldStack.peek();
ht.put(new Integer(id), f);
Map m = (Map) fieldStack.peek();
m.put(new Integer(id), f);
}
}
catch (Exception ex)
Expand All @@ -367,48 +376,45 @@ public void startElement(String namespaceURI, String localName, String qName, At
}

/**
* Convert the ISOFieldPackagers in the Hashtable
* Convert the ISOFieldPackagers in the Map
* to an array of ISOFieldPackagers
*/
private ISOFieldPackager[] makeFieldArray(Hashtable tab)
private ISOFieldPackager[] makeFieldArray(Map<Integer,ISOFieldPackager> m)
{
int maxField = 0;

// First find the largest field number in the Hashtable
for (Enumeration e=tab.keys(); e.hasMoreElements(); )
{
int n = (Integer) e.nextElement();
if (n > maxField) maxField = n;
}
// First find the largest field number in the Map
for (Entry<Integer,ISOFieldPackager> ent :m.entrySet())
if (ent.getKey() > maxField)
maxField = ent.getKey();

// Create the array
ISOFieldPackager fld[] = new ISOFieldPackager[maxField+1];

// Populate it
for (Enumeration e=tab.keys(); e.hasMoreElements(); )
{
Integer key = (Integer) e.nextElement();
fld[key] = (ISOFieldPackager)tab.get(key);
}
for (Entry<Integer,ISOFieldPackager> ent :m.entrySet())
fld[ent.getKey()] = ent.getValue();
return fld;
}

@Override
public void endElement(String namespaceURI, String localName, String qName)
{
Map<Integer,ISOFieldPackager> m;
if (localName.equals("isopackager"))
{
Hashtable tab = (Hashtable)fieldStack.pop();
m = (Map)fieldStack.pop();

setFieldPackager(makeFieldArray(tab));
setFieldPackager(makeFieldArray(m));
}

if (localName.equals("isofieldpackager"))
{
// Pop the 4 entries off the stack in the correct order
Hashtable tab = (Hashtable)fieldStack.pop();
m = (Map)fieldStack.pop();

ISOBasePackager msgPackager = (ISOBasePackager) fieldStack.pop();
msgPackager.setFieldPackager (makeFieldArray(tab));
msgPackager.setFieldPackager (makeFieldArray(m));

ISOFieldPackager fieldPackager = (ISOFieldPackager) fieldStack.pop();

Expand All @@ -423,22 +429,25 @@ public void endElement(String namespaceURI, String localName, String qName)
// Add the newly created ISOMsgField packager to the
// lower level field stack

tab=(Hashtable)fieldStack.peek();
tab.put(fno, mfp);
m=(Map)fieldStack.peek();
m.put(fno, mfp);
}
}

// ErrorHandler Methods
@Override
public void error (SAXParseException ex) throws SAXException
{
throw ex;
}

@Override
public void fatalError (SAXParseException ex) throws SAXException
{
throw ex;
}
}
@Override
protected int getFirstField() {
if (firstField != null)
return Integer.parseInt (firstField);
Expand Down
Expand Up @@ -46,6 +46,7 @@ public GenericSubFieldPackager() throws ISOException
super();
}

@Override
public int unpack (ISOComponent m, byte[] b) throws ISOException
{
LogEvent evt = new LogEvent (this, "unpack");
Expand Down

0 comments on commit b89db91

Please sign in to comment.