@@ -64,7 +64,8 @@ public EncodedDataType(final Node node, final String givenName)
6464 super (node , givenName , null );
6565
6666 primitiveType = PrimitiveType .get (getAttributeValue (node , "primitiveType" ));
67- length = Integer .parseInt (getAttributeValue (node , "length" , "1" ));
67+ final String lengthAttr = getAttributeValueOrNull (node , "length" );
68+ length = Integer .parseInt (null == lengthAttr ? "1" : lengthAttr );
6869 varLen = Boolean .parseBoolean (getAttributeValue (node , "variableLength" , "false" ));
6970
7071 if (PrimitiveType .CHAR == primitiveType )
@@ -89,13 +90,34 @@ public EncodedDataType(final Node node, final String givenName)
8990 final String nodeValue = node .getFirstChild ().getNodeValue ();
9091 if (PrimitiveType .CHAR == primitiveType )
9192 {
92- if (nodeValue .length () == 1 )
93+ final int valueLength = nodeValue .length ();
94+
95+ if (null != lengthAttr && length < valueLength )
96+ {
97+ handleError (node , "length of " + length + " is less than provided value: " + nodeValue );
98+ }
99+
100+ if (valueLength == 1 )
93101 {
94- constValue = PrimitiveValue .parse (nodeValue , primitiveType , characterEncoding );
102+ if (null == lengthAttr )
103+ {
104+ constValue = PrimitiveValue .parse (nodeValue , primitiveType , characterEncoding );
105+ }
106+ else
107+ {
108+ constValue = PrimitiveValue .parse (nodeValue , length , characterEncoding );
109+ }
95110 }
96111 else
97112 {
98- constValue = PrimitiveValue .parse (nodeValue , nodeValue .length (), characterEncoding );
113+ if (null == lengthAttr )
114+ {
115+ constValue = PrimitiveValue .parse (nodeValue , valueLength , characterEncoding );
116+ }
117+ else
118+ {
119+ constValue = PrimitiveValue .parse (nodeValue , length , characterEncoding );
120+ }
99121 }
100122 }
101123 else
0 commit comments