public XMLSyntaxRule[] getSyntaxRules() {
   return new XMLSyntaxRule[] {
     AttributeRule.newBooleanRule(BeagleTreeLikelihoodParser.USE_AMBIGUITIES, true),
     AttributeRule.newStringRule(RECONSTRUCTION_TAG_NAME, true),
     AttributeRule.newBooleanRule(INTEGRATE_GAIN_RATE),
     new ElementRule(
         IMMIGRATION_RATE, new XMLSyntaxRule[] {new ElementRule(Parameter.class)}, true),
     new ElementRule(PatternList.class),
     new ElementRule(TreeModel.class),
     new ElementRule(GammaSiteRateModel.class),
     new ElementRule(BranchModel.class, true),
     new ElementRule(BranchRateModel.class, true),
     new ElementRule(TipStatesModel.class, true),
     new ElementRule(SubstitutionModel.class, true),
     AttributeRule.newStringRule(BeagleTreeLikelihoodParser.SCALING_SCHEME, true),
     new ElementRule(
         PARTIALS_RESTRICTION,
         new XMLSyntaxRule[] {
           new ElementRule(TaxonList.class), new ElementRule(Parameter.class),
         },
         true),
     new ElementRule(
         OBSERVATION_PROCESS,
         new XMLSyntaxRule[] {
           AttributeRule.newStringRule(OBSERVATION_TYPE, false),
           AttributeRule.newStringRule(OBSERVATION_TAXON, true)
         })
   };
 }
public class TreeLengthStatisticParser extends AbstractXMLObjectParser {

  public static final String TREE_LENGTH_STATISTIC = "treeLengthStatistic";

  public String getParserName() {
    return TREE_LENGTH_STATISTIC;
  }

  public Object parseXMLObject(XMLObject xo) throws XMLParseException {

    String name = xo.getAttribute(Statistic.NAME, xo.getId());
    Tree tree = (Tree) xo.getChild(Tree.class);

    return new TreeLengthStatistic(name, tree);
  }

  // ************************************************************************
  // AbstractXMLObjectParser implementation
  // ************************************************************************

  public String getParserDescription() {
    return "A statistic that returns the average of the branch rates";
  }

  public Class getReturnType() {
    return TreeLengthStatistic.class;
  }

  public XMLSyntaxRule[] getSyntaxRules() {
    return rules;
  }

  private final XMLSyntaxRule[] rules = {
    AttributeRule.newStringRule(Statistic.NAME, true), new ElementRule(TreeModel.class),
  };
}