private static void validateBlockLength( final Node node, final long specifiedBlockLength, final long computedBlockLength) { if (0 != specifiedBlockLength && computedBlockLength > specifiedBlockLength) { final String msg = "specified blockLength provides insufficient space " + computedBlockLength + " > " + specifiedBlockLength; handleError(node, msg); } }
private Type addType(final Node subTypeNode, final String name, final Type type) { if (containedTypeByNameMap.put(name, type) != null) { XmlSchemaParser.handleError(subTypeNode, "composite already contains a type named: " + name); } return type; }
private void validateValueRef(final Node node, final Map<String, Type> typeByNameMap) { final int periodIndex = valueRef.indexOf('.'); if (periodIndex < 1 || periodIndex == (valueRef.length() - 1)) { handleError(node, "valueRef format not valid (enum-name.valid-value-name): " + valueRef); } final String valueRefType = valueRef.substring(0, periodIndex); final Type valueType = typeByNameMap.get(valueRefType); if (null == valueType) { handleError(node, "valueRef for enum name not found: " + valueRefType); } if (valueType instanceof EnumType) { final EnumType enumType = (EnumType)valueType; final String validValueName = valueRef.substring(periodIndex + 1); if (null == enumType.getValidValue(validValueName)) { handleError(node, "valueRef for validValue name not found: " + validValueName); } } else { handleError(node, "valueRef for is not of type enum: " + valueRefType); } }
XmlSchemaParser.handleError(node, "valueRef not found: " + valueRefType); return null; if (enumType.encodingType() != primitiveType) handleError(node, "valueRef does not match this type: " + valueRef); return null; handleError(node, "valueRef for validValue name not found: " + validValueName); return null;
XmlSchemaParser.handleError(node, "composite for variable length data encoding must have \"length\""); if (!isUnsigned(primitiveType)) XmlSchemaParser.handleError(node, "\"length\" must be unsigned type"); XmlSchemaParser.handleError( node, "composite for variable length data encoding cannot have presence=\"optional\""); XmlSchemaParser.handleError(node, "composite for variable length data encoding must have \"varData\"");
!semanticType.equals(type.semanticType())) handleError(node, "Mismatched semanticType on type and field: " + name); handleError(node, "valueRef not set for constant enum"); handleError(node, "valueRef does not match field type: " + valueRef); handleError(node, "valueRef does not match field type: " + valueRef); handleError(node, "valueRef for enum name not found: " + valueRefType);
/** * Check the composite for any specified offsets and validate they are correctly specified. * * @param node of the XML for this composite */ public void checkForValidOffsets(final Node node) { int offset = 0; for (final Type edt : containedTypeByNameMap.values()) { final int offsetAttribute = edt.offsetAttribute(); if (-1 != offsetAttribute) { if (offsetAttribute < offset) { XmlSchemaParser.handleError( node, String.format("composite element \"%s\" has incorrect offset specified", edt.name())); } offset = offsetAttribute; } offset += edt.encodedLength(); } }
private static void validateGroupMaxValue( final Node node, final PrimitiveType primitiveType, final PrimitiveValue value) { if (null != value) { final long longValue = value.longValue(); final long allowedValue = primitiveType.maxValue().longValue(); if (longValue > allowedValue) { XmlSchemaParser.handleError(node, String.format( "maxValue greater than allowed for type: maxValue=%d allowed=%d", longValue, allowedValue)); } final long maxInt = INT32.maxValue().longValue(); if (primitiveType == UINT32 && longValue > maxInt) { XmlSchemaParser.handleError(node, String.format( "maxValue greater than allowed for type: maxValue=%d allowed=%d", longValue, maxInt)); } } else if (primitiveType == UINT32) { final long maxInt = INT32.maxValue().longValue(); XmlSchemaParser.handleError(node, String.format( "maxValue must be set for varData UINT32 type: max value allowed=%d", maxInt)); } }
if (dataEncountered) handleError(node, "group node specified after data node"); if (groupEncountered || dataEncountered) handleError(node, "field node specified after group or data node specified"); handleError(node, "duplicate id found: " + field.id()); handleError(node, "duplicate name found: " + field.name());
XmlSchemaParser.handleError(node, "composite for message header must have \"blockLength\""); XmlSchemaParser.handleError(node, "\"blockLength\" must be unsigned"); XmlSchemaParser.handleError(node, "composite for message header must have \"templateId\""); XmlSchemaParser.handleError(node, "composite for message header must have \"schemaId\""); XmlSchemaParser.handleError(node, "composite for message header must have \"version\"");
private static void addMessageWithIdCheck( final ObjectHashSet<String> distinctNames, final Map<Long, Message> messageByIdMap, final Message message, final Node node) { if (messageByIdMap.get((long)message.id()) != null) { handleError(node, "message template id already exists: " + message.id()); } if (!distinctNames.add(message.name())) { handleError(node, "message name already exists: " + message.name()); } checkForValidName(node, message.name()); messageByIdMap.put((long)message.id(), message); }
handleError(node, "length of " + length + " is less than provided value: " + nodeValue);
XmlSchemaParser.handleError(subTypeNode, "ref type not found: " + refTypeName); XmlSchemaParser.handleError(refTypeNode, "ref types cannot create circular dependencies."); throw new IllegalStateException("ref types cannot create circular dependencies");
handleError(node, "nullValue set, but presence is not optional"); handleError(node, "presence optional but no null value found"); nullValue = null;
handleError(node, "valueRef format not valid (enum-name.valid-value-name): " + valueRef); handleError(node, "present must be constant when valueRef is set: " + valueRef); handleError(node, "type has declared presence as \"constant\" but XML node has no data"); constValue = null;
XmlSchemaParser.handleError(node, "composite for group encodedLength encoding must have \"blockLength\""); XmlSchemaParser.handleError(node, "\"blockLength\" must be unsigned type"); XmlSchemaParser.handleError(node, "composite for group encodedLength encoding must have \"numInGroup\""); if (null == numInGroupMinValue) XmlSchemaParser.handleError(node, "\"numInGroup\" minValue must be set for signed types"); XmlSchemaParser.handleError(node, String.format( "\"numInGroup\" minValue=%s must be greater than zero " + "for signed \"numInGroup\" types", numInGroupMinValue)); XmlSchemaParser.handleError(node, String.format( "\"numInGroup\" minValue=%s greater than maxValue=%d", numInGroupMinValue, max));
if (dimensionType == null) handleError(node, "could not find dimensionType: " + dimensionTypeName); handleError(node, "dimensionType should be a composite type: " + dimensionTypeName); dimensionType = null;
if (fieldType == null) handleError(node, "could not find type: " + typeName); handleError(node, "data type is not composite type: " + typeName);
private Field parseField(final NodeList nodeList, final int nodeIndex) { final Node node = nodeList.item(nodeIndex); final String typeName = getAttributeValue(node, "type"); final Type fieldType = typeByNameMap.get(typeName); if (fieldType == null) { handleError(node, "could not find type: " + typeName); } final Field field = new Field.Builder() .name(getAttributeValue(node, "name")) .description(getAttributeValueOrNull(node, "description")) .id(Integer.parseInt(getAttributeValue(node, "id"))) .offset(Integer.parseInt(getAttributeValue(node, "offset", "0"))) .semanticType(getAttributeValueOrNull(node, "semanticType")) .presence(getPresence(node, fieldType)) .valueRef(getAttributeValueOrNull(node, "valueRef")) .sinceVersion(Integer.parseInt(getAttributeValue(node, "sinceVersion", "0"))) .deprecated(Integer.parseInt(getAttributeValue(node, "deprecated", "0"))) .epoch(getAttributeValueOrNull(node, "epoch")) .timeUnit(getAttributeValueOrNull(node, "timeUnit")) .type(fieldType) .build(); field.validate(node, typeByNameMap); return field; }
handleError(node, "Offset provides insufficient space at field: " + field.name());