Index: src/quickfix/Message.java =================================================================== --- src/quickfix/Message.java (revision 393) +++ src/quickfix/Message.java (working copy) @@ -1,19 +1,19 @@ /******************************************************************************* - * Copyright (c) quickfixengine.org All rights reserved. - * - * This file is part of the QuickFIX FIX Engine - * - * This file may be distributed under the terms of the quickfixengine.org - * license as defined by quickfixengine.org and appearing in the file - * LICENSE included in the packaging of this file. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING - * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. - * - * See http://www.quickfixengine.org/LICENSE for licensing information. - * - * Contact ask@quickfixengine.org if any conditions of this licensing + * Copyright (c) quickfixengine.org All rights reserved. + * + * This file is part of the QuickFIX FIX Engine + * + * This file may be distributed under the terms of the quickfixengine.org + * license as defined by quickfixengine.org and appearing in the file + * LICENSE included in the packaging of this file. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING + * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE. + * + * See http://www.quickfixengine.org/LICENSE for licensing information. + * + * Contact ask@quickfixengine.org if any conditions of this licensing * are not clear to you. ******************************************************************************/ @@ -69,7 +69,7 @@ * Represents a FIX message. */ public class Message extends FieldMap { - + static final long serialVersionUID = -3193357271891865972L; protected Header header = new Header(); @@ -158,43 +158,43 @@ public void headerAddGroup(Group group) { header.addGroup(group); } - + public void headerReplaceGroup(int num, Group group) { header.replaceGroup(num, group); } - + public Group headerGetGroup(int num, Group group) throws FieldNotFound { return header.getGroup(num, group); } - + public void headerRemoveGroup(Group group) { header.removeGroup(group); } - + public boolean headerHasGroup(int field) { return header.hasGroup(field); } - + public boolean headerHasGroup(int num, int field) { return header.hasGroup(num, field); } - + public boolean headerHasGroup(int num, Group group) { - return headerHasGroup( num, group.getFieldTag() ); + return headerHasGroup(num, group.getFieldTag()); } - + public boolean headerHasGroup(Group group) { - return headerHasGroup( group.getFieldTag() ); + return headerHasGroup(group.getFieldTag()); } public void trailerAddGroup(Group group) { trailer.addGroup(group); } - + public Group trailerGetGroup(int num, Group group) throws FieldNotFound { return trailer.getGroup(num, group); } - + public void trailerReplaceGroup(int num, Group group) { trailer.replaceGroup(num, group); } @@ -202,27 +202,27 @@ public void trailerRemoveGroup(Group group) { trailer.removeGroup(group); } - + public boolean trailerHasGroup(int field) { return trailer.hasGroup(field); } - + public boolean trailerHasGroup(int num, int field) { return trailer.hasGroup(num, field); } - + public boolean trailerHasGroup(int num, Group group) { - return trailerHasGroup( num, group.field() ); - } - + return trailerHasGroup(num, group.field()); + } + public boolean trailerHasGroup(Group group) { - return trailerHasGroup( group.field() ); + return trailerHasGroup(group.field()); } - + public String toXML() { return toXML(null); } - + public String toXML(DataDictionary dataDictionary) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); @@ -310,9 +310,8 @@ static final long serialVersionUID = -3193357271891865972L; protected void calculateString(StringBuffer buffer, int[] excludedFields, int[] postFields) { - super.calculateString(buffer, new int[] { BeginString.FIELD, BodyLength.FIELD, MsgType.FIELD }, postFields); + super.calculateString(buffer, new int[]{BeginString.FIELD, BodyLength.FIELD, MsgType.FIELD}, postFields); } - } public class Trailer extends FieldMap { @@ -320,7 +319,7 @@ static final long serialVersionUID = -3193357271891865972L; protected void calculateString(StringBuffer buffer, int[] excludedFields, int[] postFields) { - super.calculateString(buffer, null, new int[] { CheckSum.FIELD }); + super.calculateString(buffer, null, new int[]{CheckSum.FIELD}); } } @@ -331,8 +330,9 @@ if (header.isSetField(BeginString.FIELD)) { String beginString = header.getString(BeginString.FIELD); - if (beginString.length() > 0) + if (beginString.length() > 0) { this.header.setString(BeginString.FIELD, beginString); + } this.header.removeField(OnBehalfOfLocationID.FIELD); this.header.removeField(DeliverToLocationID.FIELD); @@ -360,8 +360,9 @@ private void copyField(Header header, int fromField, int toField) throws FieldNotFound { if (header.isSetField(fromField)) { String value = header.getString(fromField); - if (value.length() > 0) + if (value.length() > 0) { this.header.setString(toField, value); + } } } @@ -380,6 +381,7 @@ parseTrailer(dd); } catch (InvalidMessage e) { isValidStructure = false; + throw e; } if (doValidation) { validate(messageData); @@ -493,6 +495,9 @@ } } else { if (rg.getDataDictionary().isField(field.getTag())) { + if (!firstFieldFound) { + throw new InvalidMessage("Repeating group " + groupCountTag + " is out of order: first field should be " + firstField + ", but was " + field.getField() + "."); + } group.setField(field); } else { if (group != null) { @@ -617,8 +622,9 @@ /* Assume length field is 1 less. */ int lengthField = tag - 1; /* Special case for Signature which violates above assumption. */ - if (tag == 89) + if (tag == 89) { lengthField = 93; + } int fieldLength; try { if (group == null) { @@ -639,7 +645,7 @@ /** * Queries message structural validity. (smb - I'm not sure how this is * related to other message validations.) - * + * * @return flag indicating whether the message has a valid structure */ public boolean hasValidStructure() {