SymbolResolver extends TreeSymbolTable { @Override public FixNode resolve(PathStep pathStep) { FixNode node = null; final String pathName = pathStep.getName(); if (pathName.length() > 1 && pathName.startsWith(VARIABLE_ROOT.getName())) { final Scope variables = (Scope) super.resolve(VARIABLE_ROOT); final PathStep vPathStep = new PathStep(pathName.substring(1)); vPathStep.setIndex(pathStep.getIndex()); vPathStep.setPredicate(pathStep.getPredicate()); node = variables.resolve(vPathStep); } else if (pathName.length() > 5 && pathName.startsWith(LOCAL_ROOT.getName())) { final Scope variables = (Scope) super.resolve(LOCAL_ROOT); final PathStep vPathStep = new PathStep(pathName.substring(5)); vPathStep.setIndex(pathStep.getIndex()); vPathStep.setPredicate(pathStep.getPredicate()); node = variables.resolve(vPathStep); } else { node = super.resolve(pathStep); } if (node == null) { final Scope local = (Scope) super.resolve(LOCAL_ROOT); node = local.resolve(pathStep); } return node; } SymbolResolver(); @Override FixValue<?> assign(PathStep pathStep, FixValue<?> value); @Override FixNode resolve(PathStep pathStep); static final PathStep VARIABLE_ROOT; static final PathStep CODE_SET_ROOT; static final PathStep LOCAL_ROOT; }
@Test public void testResolve() throws ModelException { symbolResolver.nest(CODE_SET_ROOT, new TreeSymbolTable("Codes")); Scope node = (Scope) symbolResolver.resolve(CODE_SET_ROOT); FixValue<?> value = new FixValue<Character>("Market", FixType.charType, '1'); PathStep pathStep2 = new PathStep(value.getName()); node.assign(pathStep2, value); @SuppressWarnings("unchecked") FixValue<Character> found = (FixValue<Character>) node.resolve(pathStep2); assertNotNull(found); assertEquals(Character.valueOf('1'), found.getValue()); }