示例#1
0
  /**
   * Computes the definition table for the given ZSect and all its parents. In order to provide as
   * much information as possible, it fails gracefully by accumulating all raised exceptions to the
   * end (top-most parent). It also updates the manager with what was possible to calculate, despite
   * the errors. In the end, they are raised. It is up to the caller to fix the section manager with
   * a better table, if needed.
   *
   * @param name
   * @param manager
   * @return
   * @throws CommandException
   */
  @Override
  public boolean compute(String name, SectionManager manager) throws CommandException {
    Key<ZSect> sectKey = new Key<ZSect>(name, ZSect.class);
    ZSect zsect = manager.get(sectKey);
    Key<DefinitionTable> defTblKey = new Key<DefinitionTable>(name, DefinitionTable.class);
    DefinitionTable table;

    // the definition table cannot be cached - parsing does not calculate the definition table

    DefinitionTableVisitor visitor = new DefinitionTableVisitor(manager);
    // calculate table
    try {
      table = visitor.run(zsect);
      updateManager(manager, sectKey, defTblKey, table);
      return table != null;
    } catch (CommandException f) {
      // in case of raised definition exception, still update the manager
      // with calculated results, if they are available, before raising
      // the error. It is up to the caller to fix the manager.
      if (f instanceof DefinitionException) {
        updateManager(manager, sectKey, defTblKey, visitor.getDefinitionTable());
      }
      // then throw it
      throw f;
    } catch (CztException e) {
      // catch visiting related exceptions. cmd exceptions must be handled by caller
      throw new CommandException(
          manager.getDialect(),
          "Could not calculate definition table for "
              + name
              + "\n\t with message "
              + e.getMessage()
              + (e.getCause() != null ? ("\n\t and cause " + e.getCause().getMessage()) : "")
              + ".",
          e);
    }
  }
示例#2
0
 public DefinitionTable run(ZSect sect, SectionInfo sectInfo) throws CommandException {
   DefinitionTableVisitor visitor = new DefinitionTableVisitor(sectInfo);
   return visitor.run(sect);
 }