private static String semanticTypeOf(final Type type, final Field field) { final String typeSemanticType = null != type ? type.semanticType() : null; if (typeSemanticType != null) { return typeSemanticType; } return null != field ? field.semanticType() : null; }
/** * Creates an instance of {@link ParserOptions} with all the values set. * * @return an instance of {@link ParserOptions} with all the values set. */ public ParserOptions build() { return new ParserOptions(stopOnError, warningsFatal, suppressOutput, xIncludeAware, xsdFilename); } }
/** * Generate a complete {@link uk.co.real_logic.sbe.ir.Ir} for a given schema. * * @param schema from which the {@link uk.co.real_logic.sbe.ir.Ir} should be generated. * @return complete {@link uk.co.real_logic.sbe.ir.Ir} for a given schema. */ public Ir generate(final MessageSchema schema) { return generate(schema, null); }
@Test public void shouldExitAfterMessage() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 13 errors"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-message-schema.xml"), options); }
@Before public void setUp() throws Exception { final ParserOptions options = ParserOptions.builder().stopOnError(true).build(); final MessageSchema schema = parse(TestUtil.getLocalResource("code-generation-schema.xml"), options); final IrGenerator irg = new IrGenerator(); ir = irg.generate(schema); outputManager.clear(); outputManager.setPackageName(ir.applicableNamespace()); }
private List<Token> generateForMessage(final MessageSchema schema, final long messageId) { tokenList.clear(); final Message msg = schema.getMessage(messageId); addMessageSignal(msg, Signal.BEGIN_MESSAGE); addAllFields(msg.fields()); addMessageSignal(msg, Signal.END_MESSAGE); return tokenList; }
private static void addTypeWithNameCheck(final Map<String, Type> typeByNameMap, final Type type, final Node node) { if (typeByNameMap.get(type.name()) != null) { handleWarning(node, "type already exists for name: " + type.name()); } checkForValidName(node, type.name()); typeByNameMap.put(type.name(), type); }
/** * Construct a new {@link ErrorHandler} that outputs to a provided {@link PrintStream}. * * @param stream to which output should be sent. * @param options the parsing options. */ public ErrorHandler(final PrintStream stream, final ParserOptions options) { out = stream; stopOnError = options.stopOnError(); warningsFatal = options.warningsFatal(); suppressOutput = options.suppressOutput(); }
private static Presence getPresence(final Node node, final Type fieldType) { final String presenceStr = getAttributeValueOrNull(node, "presence"); final Presence presence; if (null != presenceStr) { presence = Presence.get(presenceStr); } else if (null != fieldType) { presence = fieldType.presence(); } else { presence = Presence.REQUIRED; } return presence; }
private PrimitiveValue lookupValueRef(final String valueRef) { final int periodIndex = valueRef.indexOf('.'); final String valueRefType = valueRef.substring(0, periodIndex); final String validValueName = valueRef.substring(periodIndex + 1); final EnumType enumType = (EnumType)schema.getType(valueRefType); final EnumType.ValidValue validValue = enumType.getValidValue(validValueName); return validValue.primitiveValue(); }
private List<Token> generateForHeader(final MessageSchema schema) { tokenList.clear(); add(schema.messageHeader(), 0, null); return tokenList; }
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); } }
/** * Creates a builder. * * @return a new builder instance. */ public static Builder builder() { return new Builder(); }
@Test public void shouldExitAfterMessageWhenGroupDimensionsNotComposite() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 1 errors"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-group-dimensions-schema.xml"), options); }
@Test public void shouldExitAfterTypesWhenDupTypesDefined() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 1 warnings"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-types-dup-schema.xml"), options); }
@Test public void shouldExitInvalidFieldNames() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 16 warnings"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-invalid-name.xml"), options); }
@Test public void shouldExitAfterMessageWhenDupMessageIdsDefined() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 1 errors"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-dup-message-schema.xml"), options); }
@Test public void shouldExitAfterTypesWhenCompositeOffsetsIncorrect() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 2 errors"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-invalid-composite-offsets-schema.xml"), options); }
@Test public void shouldTestForCyclicRefs() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("ref types cannot create circular dependencies"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("cyclic-refs-schema.xml"), options); } }
@Test public void shouldExitAfterTypes() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 2 errors"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).build(); parse(TestUtil.getLocalResource("error-handler-types-schema.xml"), options); }