@@ -88,11 +88,6 @@ private static Supplier<DocumentBuilderFactory> createDocumentBuilderFactorySupp
8888 }
8989
9090 private boolean hasVersion = false ;
91- private boolean checkFieldsOutOfOrder = true ;
92- private boolean checkFieldsHaveValues = true ;
93- private boolean checkUserDefinedFields = true ;
94- private boolean checkUnorderedGroupFields = true ;
95- private boolean allowUnknownMessageFields = false ;
9691 private String beginString ;
9792 private String fullVersion ;
9893 private String majorVersion ;
@@ -532,86 +527,6 @@ private boolean isMultipleValueStringField(int field) {
532527 fieldType == FieldType .MULTIPLECHARVALUE ;
533528 }
534529
535- /**
536- * Controls whether out of order fields are checked.
537- *
538- * @param flag true = checked, false = not checked
539- */
540- public void setCheckFieldsOutOfOrder (boolean flag ) {
541- checkFieldsOutOfOrder = flag ;
542- }
543-
544- public boolean isCheckFieldsOutOfOrder () {
545- return checkFieldsOutOfOrder ;
546- }
547-
548- public boolean isCheckUnorderedGroupFields () {
549- return checkUnorderedGroupFields ;
550- }
551-
552- public boolean isCheckFieldsHaveValues () {
553- return checkFieldsHaveValues ;
554- }
555-
556- public boolean isCheckUserDefinedFields () {
557- return checkUserDefinedFields ;
558- }
559-
560- public boolean isAllowUnknownMessageFields () {
561- return allowUnknownMessageFields ;
562- }
563-
564- /**
565- * Controls whether group fields are in the same order
566- *
567- * @param flag true = checked, false = not checked
568- */
569- public void setCheckUnorderedGroupFields (boolean flag ) {
570- checkUnorderedGroupFields = flag ;
571- for (Map <Integer , GroupInfo > gm : groups .values ()) {
572- for (GroupInfo gi : gm .values ()) {
573- gi .getDataDictionary ().setCheckUnorderedGroupFields (flag );
574- }
575- }
576- }
577-
578- /**
579- * Controls whether empty field values are checked.
580- *
581- * @param flag true = checked, false = not checked
582- */
583- public void setCheckFieldsHaveValues (boolean flag ) {
584- checkFieldsHaveValues = flag ;
585- for (Map <Integer , GroupInfo > gm : groups .values ()) {
586- for (GroupInfo gi : gm .values ()) {
587- gi .getDataDictionary ().setCheckFieldsHaveValues (flag );
588- }
589- }
590- }
591-
592- /**
593- * Controls whether user defined fields are checked.
594- *
595- * @param flag true = checked, false = not checked
596- */
597- public void setCheckUserDefinedFields (boolean flag ) {
598- checkUserDefinedFields = flag ;
599- for (Map <Integer , GroupInfo > gm : groups .values ()) {
600- for (GroupInfo gi : gm .values ()) {
601- gi .getDataDictionary ().setCheckUserDefinedFields (flag );
602- }
603- }
604- }
605-
606- public void setAllowUnknownMessageFields (boolean allowUnknownFields ) {
607- allowUnknownMessageFields = allowUnknownFields ;
608- for (Map <Integer , GroupInfo > gm : groups .values ()) {
609- for (GroupInfo gi : gm .values ()) {
610- gi .getDataDictionary ().setAllowUnknownMessageFields (allowUnknownFields );
611- }
612- }
613- }
614-
615530 private void copyFrom (DataDictionary rhs ) {
616531 hasVersion = rhs .hasVersion ;
617532 beginString = rhs .beginString ;
@@ -632,13 +547,6 @@ private void copyFrom(DataDictionary rhs) {
632547 copyMap (valueNames , rhs .valueNames );
633548 copyGroups (groups , rhs .groups );
634549 copyMap (components , rhs .components );
635-
636- setCheckFieldsOutOfOrder (rhs .checkFieldsOutOfOrder );
637- setCheckFieldsHaveValues (rhs .checkFieldsHaveValues );
638- setCheckUserDefinedFields (rhs .checkUserDefinedFields );
639- setCheckUnorderedGroupFields (rhs .checkUnorderedGroupFields );
640- setAllowUnknownMessageFields (rhs .allowUnknownMessageFields );
641-
642550 calculateOrderedFields ();
643551 }
644552
@@ -688,34 +596,39 @@ private static <V> void copyCollection(Collection<V> lhs, Collection<V> rhs) {
688596 * Validate a message, including the header and trailer fields.
689597 *
690598 * @param message the message
599+ * @param settings
691600 * @throws IncorrectTagValue if a field value is not valid
692601 * @throws FieldNotFound if a field cannot be found
693602 * @throws IncorrectDataFormat if a field value has a wrong data type
694603 */
695- public void validate (Message message ) throws IncorrectTagValue , FieldNotFound ,
604+ public void validate (Message message , ValidationSettings settings ) throws IncorrectTagValue , FieldNotFound ,
696605 IncorrectDataFormat {
697- validate (message , false );
606+ validate (message , false , settings );
698607 }
699608
700609 /**
701610 * Validate the message body, with header and trailer fields being validated conditionally.
702611 *
703612 * @param message the message
704613 * @param bodyOnly whether to validate just the message body, or to validate the header and trailer sections as well.
614+ * @param settings
705615 * @throws IncorrectTagValue if a field value is not valid
706616 * @throws FieldNotFound if a field cannot be found
707617 * @throws IncorrectDataFormat if a field value has a wrong data type
708618 */
709- public void validate (Message message , boolean bodyOnly ) throws IncorrectTagValue ,
619+ public void validate (Message message , boolean bodyOnly , ValidationSettings settings ) throws IncorrectTagValue ,
710620 FieldNotFound , IncorrectDataFormat {
711- validate (message , bodyOnly ? null : this , this );
621+ validate (message , bodyOnly ? null : this , this , settings );
712622 }
713623
714624 static void validate (Message message , DataDictionary sessionDataDictionary ,
715- DataDictionary applicationDataDictionary ) throws IncorrectTagValue , FieldNotFound ,
625+ DataDictionary applicationDataDictionary , ValidationSettings settings ) throws IncorrectTagValue , FieldNotFound ,
716626 IncorrectDataFormat {
717627 final boolean bodyOnly = sessionDataDictionary == null ;
718-
628+ if (settings == null ) {
629+ settings = new ValidationSettings ();
630+ }
631+
719632 if (isVersionSpecified (sessionDataDictionary )
720633 && !sessionDataDictionary .getVersion ().equals (
721634 message .getHeader ().getString (BeginString .FIELD ))
@@ -737,38 +650,38 @@ static void validate(Message message, DataDictionary sessionDataDictionary,
737650 }
738651
739652 if (!bodyOnly ) {
740- sessionDataDictionary .iterate (message .getHeader (), HEADER_ID , sessionDataDictionary );
741- sessionDataDictionary .iterate (message .getTrailer (), TRAILER_ID , sessionDataDictionary );
653+ sessionDataDictionary .iterate (settings , message .getHeader (), HEADER_ID , sessionDataDictionary );
654+ sessionDataDictionary .iterate (settings , message .getTrailer (), TRAILER_ID , sessionDataDictionary );
742655 }
743656
744- applicationDataDictionary .iterate (message , msgType , applicationDataDictionary );
657+ applicationDataDictionary .iterate (settings , message , msgType , applicationDataDictionary );
745658 }
746659
747660 private static boolean isVersionSpecified (DataDictionary dd ) {
748661 return dd != null && dd .hasVersion ;
749662 }
750663
751- private void iterate (FieldMap map , String msgType , DataDictionary dd ) throws IncorrectTagValue ,
664+ private void iterate (ValidationSettings settings , FieldMap map , String msgType , DataDictionary dd ) throws IncorrectTagValue ,
752665 IncorrectDataFormat {
753666 for (final Field <?> f : map ) {
754667 final StringField field = (StringField ) f ;
755668
756- checkHasValue (field );
669+ checkHasValue (settings , field );
757670
758671 if (hasVersion ) {
759- checkValidFormat (field );
672+ checkValidFormat (settings , field );
760673 checkValue (field );
761674 }
762675
763676 if (beginString != null ) {
764- dd .checkField (field , msgType , map instanceof Message );
677+ dd .checkField (settings , field , msgType , map instanceof Message );
765678 dd .checkGroupCount (field , map , msgType );
766679 }
767680 }
768681
769682 for (final List <Group > groups : map .getGroups ().values ()) {
770683 for (final Group group : groups ) {
771- iterate (group , msgType , dd .getGroup (msgType , group .getFieldTag ())
684+ iterate (settings , group , msgType , dd .getGroup (msgType , group .getFieldTag ())
772685 .getDataDictionary ());
773686 }
774687 }
@@ -789,10 +702,10 @@ void checkValidTagNumber(Field<?> field) {
789702 }
790703
791704 /** Check if field tag is defined for message or group **/
792- void checkField (Field <?> field , String msgType , boolean message ) {
705+ void checkField (ValidationSettings settings , Field <?> field , String msgType , boolean message ) {
793706 // use different validation for groups and messages
794707 boolean messageField = message ? isMsgField (msgType , field .getField ()) : fields .contains (field .getField ());
795- boolean fail = checkFieldFailure (field .getField (), messageField );
708+ boolean fail = checkFieldFailure (settings , field .getField (), messageField );
796709
797710 if (fail ) {
798711 if (fields .contains (field .getField ())) {
@@ -803,22 +716,22 @@ void checkField(Field<?> field, String msgType, boolean message) {
803716 }
804717 }
805718
806- boolean checkFieldFailure (int field , boolean messageField ) {
719+ boolean checkFieldFailure (ValidationSettings settings , int field , boolean messageField ) {
807720 boolean fail ;
808721 if (field < USER_DEFINED_TAG_MIN ) {
809- fail = !messageField && !allowUnknownMessageFields ;
722+ fail = !messageField && !settings . allowUnknownMessageFields ;
810723 } else {
811- fail = !messageField && checkUserDefinedFields ;
724+ fail = !messageField && settings . checkUserDefinedFields ;
812725 }
813726 return fail ;
814727 }
815728
816- private void checkValidFormat (StringField field ) throws IncorrectDataFormat {
729+ private void checkValidFormat (ValidationSettings settings , StringField field ) throws IncorrectDataFormat {
817730 FieldType fieldType = getFieldType (field .getTag ());
818731 if (fieldType == null ) {
819732 return ;
820733 }
821- if (!checkFieldsHaveValues && field .getValue ().length () == 0 ) {
734+ if (!settings . checkFieldsHaveValues && field .getValue ().length () == 0 ) {
822735 return ;
823736 }
824737 try {
@@ -883,8 +796,8 @@ private void checkValue(StringField field) throws IncorrectTagValue {
883796 }
884797
885798 /** Check if a field has a value. **/
886- private void checkHasValue (StringField field ) {
887- if (checkFieldsHaveValues && field .getValue ().length () == 0 ) {
799+ private void checkHasValue (ValidationSettings settings , StringField field ) {
800+ if (settings . checkFieldsHaveValues && field .getValue ().length () == 0 ) {
888801 throw new FieldException (SessionRejectReason .TAG_SPECIFIED_WITHOUT_A_VALUE ,
889802 field .getField ());
890803 }
0 commit comments