@@ -23,6 +23,7 @@ import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
@@ -34,6 +35,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.InputSource;
|
||||
@@ -336,9 +338,8 @@ public class ConfigParser {
|
||||
}
|
||||
HashMap<Integer,FieldParseInfo> child = new HashMap<>();
|
||||
child.putAll(parent);
|
||||
NodeList fields = elem.getElementsByTagName("field");
|
||||
for (int j = 0; j < fields.getLength(); j++) {
|
||||
Element f = (Element)fields.item(j);
|
||||
List<Element> fields = getDirectChildrenByTagName(elem, "field");
|
||||
for (Element f : fields) {
|
||||
int num = Integer.parseInt(f.getAttribute("num"));
|
||||
String typedef = f.getAttribute("type");
|
||||
if ("exclude".equals(typedef)) {
|
||||
@@ -352,6 +353,20 @@ public class ConfigParser {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Element> getDirectChildrenByTagName(Element elem, String tagName) {
|
||||
List<Element> childElementsByTagName = new ArrayList<Element>();
|
||||
NodeList childNodes = elem.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
if (childNodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element childElem = (Element)childNodes.item(i);
|
||||
if (childElem.getTagName().equals(tagName)) {
|
||||
childElementsByTagName.add(childElem);
|
||||
}
|
||||
}
|
||||
}
|
||||
return childElementsByTagName;
|
||||
}
|
||||
|
||||
/** Reads the XML from the stream and configures the message factory with its values.
|
||||
* @param mfact The message factory to be configured with the values read from the XML.
|
||||
|
||||
@@ -201,4 +201,23 @@ public class TestConfigParser {
|
||||
Assert.assertEquals("99", m.getObjectValue(39));
|
||||
Assert.assertEquals("X", m.getObjectValue(61));
|
||||
}
|
||||
|
||||
@Test // issue 47
|
||||
public void testExtendCompositeWithSameField() throws IOException, ParseException {
|
||||
final MessageFactory<IsoMessage> mfact = config("issue47.xml");
|
||||
|
||||
final String m200 = "02001000000000000004000000100000013ABCDEFGHIJKLM";
|
||||
IsoMessage isoMessage = mfact.parseMessage(m200.getBytes(), 0);
|
||||
|
||||
// check field num 4
|
||||
IsoValue<Object> field4 = isoMessage.getField(4);
|
||||
Assert.assertEquals(IsoType.AMOUNT, field4.getType());
|
||||
Assert.assertEquals(IsoType.AMOUNT.getLength(), field4.getLength());
|
||||
|
||||
// check nested field num 4 from composite field 62
|
||||
CompositeField compositeField62 = (CompositeField) isoMessage.<Object>getField(62).getValue();
|
||||
IsoValue<Object> nestedField4 = compositeField62.getField(0); // first in list
|
||||
Assert.assertEquals(IsoType.ALPHA, nestedField4.getType());
|
||||
Assert.assertEquals(13, nestedField4.getLength());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<j8583-config>
|
||||
|
||||
<!-- Parent -->
|
||||
<parse type="000">
|
||||
<field num="4" type="AMOUNT" />
|
||||
</parse>
|
||||
|
||||
<parse type="0200" extends="000">
|
||||
<field num="62" type="LLLVAR">
|
||||
<field num="4" type="ALPHA" length="13" />
|
||||
</field>
|
||||
</parse>
|
||||
|
||||
</j8583-config>
|
||||
Reference in New Issue
Block a user