| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.inferencexml.operators; |
| 27 |
|
| 28 |
import dr.inference.operators.AlternatingOperatorSchedule; |
| 29 |
import dr.inference.operators.OperatorSchedule; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class AlternatingOperatorScheduleParser extends AbstractXMLObjectParser { |
| 36 |
|
| 37 |
public static final String ALTERNATING_OPERATORS = "alternatingOperators"; |
| 38 |
public static final String SCHEDULE = "schedule"; |
| 39 |
public static final String COUNT = "count"; |
| 40 |
|
| 41 |
public String getParserName() { |
| 42 |
return ALTERNATING_OPERATORS; |
| 43 |
} |
| 44 |
|
| 45 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 46 |
|
| 47 |
AlternatingOperatorSchedule schedule = new AlternatingOperatorSchedule(); |
| 48 |
|
| 49 |
for (int i = 0; i < xo.getChildCount(); i++) { |
| 50 |
XMLObject cxo = (XMLObject)xo.getChild(i); |
| 51 |
long count = cxo.getLongIntegerAttribute(COUNT); |
| 52 |
schedule.addOperatorSchedule((OperatorSchedule)cxo.getChild(OperatorSchedule.class), count); |
| 53 |
} |
| 54 |
|
| 55 |
return schedule; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 63 |
return rules; |
| 64 |
} |
| 65 |
|
| 66 |
private final XMLSyntaxRule[] rules = { |
| 67 |
new ElementRule(SCHEDULE, new XMLSyntaxRule[] { |
| 68 |
AttributeRule.newLongIntegerRule(COUNT), |
| 69 |
new ElementRule(OperatorSchedule.class) |
| 70 |
}, 1, Integer.MAX_VALUE) |
| 71 |
}; |
| 72 |
|
| 73 |
public String getParserDescription() { |
| 74 |
return "An operator scheduler that alternates between nested schedulers"; |
| 75 |
} |
| 76 |
|
| 77 |
public Class getReturnType() { |
| 78 |
return AlternatingOperatorSchedule.class; |
| 79 |
} |
| 80 |
|
| 81 |
} |