| 1 | /* |
| 2 | * ComponentGenerator.java |
| 3 | * |
| 4 | * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard |
| 5 | * |
| 6 | * This file is part of BEAST. |
| 7 | * See the NOTICE file distributed with this work for additional |
| 8 | * information regarding copyright ownership and licensing. |
| 9 | * |
| 10 | * BEAST is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU Lesser General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 |
| 13 | * of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * BEAST is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public |
| 21 | * License along with BEAST; if not, write to the |
| 22 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 23 | * Boston, MA 02110-1301 USA |
| 24 | */ |
| 25 | |
| 26 | package dr.app.beauti.generator; |
| 27 | |
| 28 | import dr.app.beauti.util.XMLWriter; |
| 29 | |
| 30 | /** |
| 31 | * This interface is for generators of model components that need to insert XML |
| 32 | * at various places throughout the document. The implementation needs to return |
| 33 | * whether it wishes to make use of an insertion point and then generate code |
| 34 | * for that insertion point. Most implementations will be derived from the abstract |
| 35 | * BaseComponent. |
| 36 | * @author Andrew Rambaut |
| 37 | * @version $Id$ |
| 38 | */ |
| 39 | public interface ComponentGenerator { |
| 40 | enum InsertionPoint { |
| 41 | BEFORE_TAXA, // at the beginning of the document |
| 42 | IN_TAXON, // in each individual taxon |
| 43 | AFTER_TAXA, // after all taxon sets have been defined |
| 44 | AFTER_SEQUENCES, // after all alignments have been defined |
| 45 | AFTER_PATTERNS, // after all patterns |
| 46 | IN_TREE_MODEL, // in the tree model(s) |
| 47 | AFTER_TREE_MODEL, // after the tree model |
| 48 | AFTER_TREE_PRIOR, // after the tree prior |
| 49 | AFTER_SUBSTITUTION_MODEL, // after all substitution models |
| 50 | AFTER_SITE_MODEL, // after all site models |
| 51 | IN_TREE_LIKELIHOOD, // in the tree likelihood(s) |
| 52 | AFTER_TREE_LIKELIHOOD, // after all tree likelihoods |
| 53 | AFTER_TRAITS, // after each traits mapping |
| 54 | BEFORE_OPERATORS, // before the operator schedule |
| 55 | IN_OPERATORS, // in the operator schedule |
| 56 | AFTER_OPERATORS, // after the operator schedule |
| 57 | IN_MCMC_PRIOR, // in the prior section of the MCMC |
| 58 | IN_MCMC_LIKELIHOOD, // in the likelihood section of the MCMC |
| 59 | IN_SCREEN_LOG, // in the screen log |
| 60 | AFTER_SCREEN_LOG, // after the screen log |
| 61 | IN_FILE_LOG_PARAMETERS, // in the file log after the parameters have been logged |
| 62 | IN_FILE_LOG_LIKELIHOODS, // in the file log after the likelihoods have been logged |
| 63 | AFTER_FILE_LOG, // after the file log |
| 64 | IN_TREES_LOG, // in the trees log |
| 65 | AFTER_TREES_LOG, // after the trees log |
| 66 | AFTER_MCMC // after the mcmc element |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Opportunity for a component to do some pre-generation checks of the options selected. |
| 71 | * Throwing a GeneratorException will result in a dialog box being shown to the user and |
| 72 | * generation being disallowed. |
| 73 | * @throws Generator.GeneratorException |
| 74 | */ |
| 75 | void checkOptions() throws Generator.GeneratorException; |
| 76 | |
| 77 | /** |
| 78 | * Returns whether this component requires access to a particular insertion point |
| 79 | * @param point the insertion point |
| 80 | * @return whether it requires it |
| 81 | */ |
| 82 | boolean usesInsertionPoint(InsertionPoint point); |
| 83 | |
| 84 | /** |
| 85 | * Called to allow the component to generate at the particular insertion point. For |
| 86 | * some insertion points (currently only 'IN_TAXON') the specific item is given. |
| 87 | * @param generator the calling generator |
| 88 | * @param point the insertion point |
| 89 | * @param item a reference to the item being generated (or null if not applicable) |
| 90 | * @param writer the XMLWriter |
| 91 | */ |
| 92 | void generateAtInsertionPoint(Generator generator, InsertionPoint point, Object item, XMLWriter writer); |
| 93 | |
| 94 | /** |
| 95 | * Called to allow the component to generate at the particular insertion point. For |
| 96 | * some insertion points the specific item is given plus a prefix to allow for unique IDs. |
| 97 | * @param generator the calling generator |
| 98 | * @param point the insertion point |
| 99 | * @param item a reference to the item being generated (or null if not applicable) |
| 100 | * @param prefix a prefix string |
| 101 | * @param writer the XMLWriter |
| 102 | */ |
| 103 | void generateAtInsertionPoint(Generator generator, InsertionPoint point, Object item, String prefix, XMLWriter writer); |
| 104 | |
| 105 | } |