| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Expression |
|
| 1.0;1 |
| 1 | /* | |
| 2 | Copyright (C) 2007 Grid Systems, S.A. | |
| 3 | ||
| 4 | This library is free software; you can redistribute it and/or | |
| 5 | modify it under the terms of the GNU Lesser General Public | |
| 6 | License as published by the Free Software Foundation; either | |
| 7 | version 2.1 of the License, or (at your option) any later version. | |
| 8 | ||
| 9 | This library is distributed in the hope that it will be useful, | |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | Lesser General Public License for more details. | |
| 13 | ||
| 14 | You should have received a copy of the GNU Lesser General Public | |
| 15 | License along with this library; if not, write to the Free Software | |
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 17 | */ | |
| 18 | package nextgrid.api.pom; | |
| 19 | ||
| 20 | import java.io.Serializable; | |
| 21 | ||
| 22 | import nextgrid.api.env.ProcessEnvironment; | |
| 23 | ||
| 24 | /** | |
| 25 | * Expression wrapper. Each subclass is responsible of implementing a | |
| 26 | * specific language syntax. | |
| 27 | * <p> | |
| 28 | * Expressions are immutable objects. Their contents cannot be changed after | |
| 29 | * construction, and a new instance must be created if a modification is | |
| 30 | * required. | |
| 31 | * | |
| 32 | * @author Rodrigo Ruiz | |
| 33 | */ | |
| 34 | public abstract class Expression implements Serializable { | |
| 35 | ||
| 36 | /** | |
| 37 | * Expression language name. | |
| 38 | */ | |
| 39 | private final String lang; | |
| 40 | ||
| 41 | /** | |
| 42 | * Expression text. | |
| 43 | */ | |
| 44 | private final String text; | |
| 45 | ||
| 46 | /** | |
| 47 | * Creates a new instance. | |
| 48 | * | |
| 49 | * @param lang The expression language | |
| 50 | * @param text The expression text | |
| 51 | * @throws ExpressionException If an error occurs | |
| 52 | */ | |
| 53 | 0 | protected Expression(String lang, String text) throws ExpressionException { |
| 54 | 0 | this.lang = lang; |
| 55 | 0 | this.text = text; |
| 56 | 0 | validate(); |
| 57 | 0 | } |
| 58 | ||
| 59 | /** | |
| 60 | * Gets the language of this expression. | |
| 61 | * | |
| 62 | * @return The language name for this expression | |
| 63 | */ | |
| 64 | public final String getLang() { | |
| 65 | 0 | return this.lang; |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * Gets the text value. | |
| 70 | * | |
| 71 | * @return The text | |
| 72 | */ | |
| 73 | public final String getText() { | |
| 74 | 0 | return this.text; |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * Checks that the expression is valid. | |
| 79 | * | |
| 80 | * @throws ExpressionException If the validation fails | |
| 81 | */ | |
| 82 | public abstract void validate() throws ExpressionException; | |
| 83 | ||
| 84 | /** | |
| 85 | * Evaluate this XPath expression as a boolean. | |
| 86 | * | |
| 87 | * @param env Environment for global configuration | |
| 88 | * @param o The node set where the expression is to be evaluated | |
| 89 | * @return The evaluation result | |
| 90 | * @throws ExpressionException If an error occurs | |
| 91 | */ | |
| 92 | public abstract boolean boolEval(ProcessEnvironment env, Object o) | |
| 93 | throws ExpressionException; | |
| 94 | } |