/*
 * CompoundParameterParser.java
 *
 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
 *
 * This file is part of BEAST.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership and licensing.
 *
 * BEAST is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 *  BEAST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with BEAST; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

package dr.inferencexml.model;

import dr.evomodel.tree.TreeModel;
import dr.inference.model.CompoundParameter;
import dr.inference.model.Parameter;
import dr.xml.*;

/**
 */
public class CompoundParameterParser extends AbstractXMLObjectParser {

    public static final String COMPOUND_PARAMETER = "compoundParameter";

    public String getParserName() {
        return COMPOUND_PARAMETER;
    }

    public Object parseXMLObject(XMLObject xo) throws XMLParseException {

        CompoundParameter compoundParameter = new CompoundParameter((String) null);

        TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
        if (treeModel != null) {
            Parameter parameter = (Parameter) xo.getChild(Parameter.class);
            final int numBranches = treeModel.getNodeCount() - 1;
            for (int i = 0; i < numBranches; i++) {
                compoundParameter.addParameter(new Parameter.Default((String) null, parameter.getParameterValue(0),
                        parameter.getBounds().getLowerLimit(0), parameter.getBounds().getUpperLimit(0)));
            }
        } else {
            for (int i = 0; i < xo.getChildCount(); i++) {
                compoundParameter.addParameter((Parameter) xo.getChild(i));
            }
        }

        return compoundParameter;
    }

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

    public String getParserDescription() {
        return "A multidimensional parameter constructed from its component parameters.";
    }

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

    private final XMLSyntaxRule[] rules;{
        rules = new XMLSyntaxRule[]{
                new ElementRule(Parameter.class, 1, Integer.MAX_VALUE),
                new ElementRule(TreeModel.class, true)
        };
    }

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

@@ -1058,44 +1058,8 @@
 %0D%0A%0D%0A
-import dr.evomodel.tree.TreeModel;%0D%0A
 impo
@@ -1092,32 +1092,32 @@
 oundParameter;%0D%0A
+
 import dr.infere
@@ -1568,573 +1568,8 @@
 %0D%0A%0D%0A
-        TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);%0D%0A        if (treeModel != null) %7B%0D%0A            Parameter parameter = (Parameter) xo.getChild(Parameter.class);%0D%0A            final int numBranches = treeModel.getNodeCount() - 1;%0D%0A            for (int i = 0; i %3C numBranches; i++) %7B%0D%0A                compoundParameter.addParameter(new Parameter.Default((String) null, parameter.getParameterValue(0),%0D%0A                        parameter.getBounds().getLowerLimit(0), parameter.getBounds().getUpperLimit(0)));%0D%0A            %7D%0D%0A        %7D else %7B%0D%0A    
     
@@ -1616,28 +1616,24 @@
 (); i++) %7B%0D%0A
-    
             
@@ -1697,23 +1697,8 @@
 );%0D%0A
-            %7D%0D%0A
     
@@ -2263,16 +2263,16 @@
 ule%5B%5D%7B%0D%0A
+
         
@@ -2340,64 +2340,8 @@
 ),%0D%0A
-                new ElementRule(TreeModel.class, true)%0D%0A
     

revert back CompoundParameterParser @msuchard