Search in sources :

Example 1 with CodeType

use of io.fixprotocol._2020.orchestra.repository.CodeType in project fix-orchestra by FIXTradingCommunity.

the class CodeSetScope method resolve.

/*
   * (non-Javadoc)
   *
   * @see
   * io.fixprotocol.orchestra.dsl.antlr.Scope#resolve(io.fixprotocol.orchestra.dsl.antlr.PathStep)
   */
@SuppressWarnings("unchecked")
@Override
public FixValue<?> resolve(PathStep pathStep) {
    final String dataTypeString = codeSet.getType();
    final FixType dataType = FixType.forName(dataTypeString);
    final String name = pathStep.getName();
    final List<CodeType> codes = codeSet.getCode();
    for (final CodeType code : codes) {
        if (code.getName().equals(name)) {
            @SuppressWarnings("rawtypes") FixValue fixValue;
            try {
                fixValue = FixValueFactory.create(name, dataType, dataType.getValueClass());
                fixValue.setValue(dataType.getValueClass().cast(dataType.fromString(code.getValue())));
                return fixValue;
            } catch (final ModelException e) {
                return null;
            }
        }
    }
    return null;
}
Also used : FixValue(io.fixprotocol.orchestra.model.FixValue) ModelException(io.fixprotocol.orchestra.model.ModelException) CodeType(io.fixprotocol._2020.orchestra.repository.CodeType) FixType(io.fixprotocol.orchestra.model.FixType)

Example 2 with CodeType

use of io.fixprotocol._2020.orchestra.repository.CodeType in project fix-orchestra by FIXTradingCommunity.

the class DocGenerator method generateCodeSetDetail.

private void generateCodeSetDetail(final Path datatypesOutputPath, final CodeSetType codeSet) throws Exception {
    final Path path = datatypesOutputPath.resolve(String.format("%s-%s.html", codeSet.getName(), codeSet.getScenario()));
    try (final STWriterWrapper writer = getWriter(path)) {
        final ST stCodesetStart = stGroup.getInstanceOf("codeSetStart");
        stCodesetStart.add("codeSet", codeSet);
        stCodesetStart.write(writer, templateErrorListener);
        final List<CodeType> codeList = codeSet.getCode();
        for (final CodeType code : codeList) {
            final ST stCode = stGroup.getInstanceOf("code");
            stCode.add("code", code);
            stCode.add("supported", supportedMap.get(code.getSupported()));
            stCode.write(writer, templateErrorListener);
        }
        final ST stCodesetEnd = stGroup.getInstanceOf("codeSetEnd");
        stCodesetEnd.add("codeSet", codeSet);
        stCodesetEnd.write(writer, templateErrorListener);
    }
}
Also used : Path(java.nio.file.Path) ST(org.stringtemplate.v4.ST) CodeType(io.fixprotocol._2020.orchestra.repository.CodeType)

Aggregations

CodeType (io.fixprotocol._2020.orchestra.repository.CodeType)2 FixType (io.fixprotocol.orchestra.model.FixType)1 FixValue (io.fixprotocol.orchestra.model.FixValue)1 ModelException (io.fixprotocol.orchestra.model.ModelException)1 Path (java.nio.file.Path)1 ST (org.stringtemplate.v4.ST)1