View Javadoc

1   /*
2   Copyright (C) 2004 Grid Systems, S.A.
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License, version 2, as
6   published by the Free Software Foundation.
7   
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17  package com.gridsystems.beanfilter;
18  
19  /**
20   * Type description.
21   *
22   * @author Rodrigo Ruiz
23   * @author Xmas
24   * @version 1.0
25   */
26  public abstract class EvalValue {
27    /**
28     * Boolean type.
29     */
30    public static final int BOOLEAN = 0;
31  
32    /**
33     * Numeric type.
34     */
35    public static final int NUMBER = 1;
36  
37    /**
38     * String type.
39     */
40    public static final int STRING = 2;
41  
42    /**
43     * Collection type.
44     */
45    public static final int COLLECTION = 3;
46  
47    /**
48     * Void type.
49     */
50    public static final int VOID = 4;
51  
52    /**
53     * Unknown type.
54     */
55    public static final int UNKNOWN = 5;
56  
57    /**
58     * The token line position.
59     */
60    private int lineNumber;
61  
62    /**
63     * The token char position.
64     */
65    private int charPosition;
66  
67    /**
68     * Creates a new instance.
69     *
70     * @param linePos  The line token position
71     * @param charPos  The char token position
72     */
73    public EvalValue(int linePos, int charPos) {
74      this.lineNumber = linePos;
75      this.charPosition = charPos;
76    }
77  
78    /**
79     * Gets the value.
80     *
81     * @param src  The data source
82     * @return  The value
83     * @throws EvalException FTR005: Unknown field path
84     * @throws EvalException FTR006: Invalid operand
85     * @throws EvalException FTR007: Pattern syntax error
86     */
87    public abstract Object getValue(Object src) throws EvalException;
88  
89    /**
90     * Gets the line position of the beginning of this value in the filter expression.
91     *
92     * @return  The line position of this value in the filter expression
93     */
94    public int getLinePos() {
95      return this.lineNumber;
96    }
97  
98    /**
99     * Gets the char position of the beginning of this value in the filter expression.
100    *
101    * @return  The char position of this value in the filter expression
102    */
103   public int getCharPos() {
104     return this.charPosition;
105   }
106 
107   /**
108    * @param parentClass Parent Class
109    * @return Return the Java Class that represents or null if it is unknown.
110    * @throws EvalException If an error occurs
111    */
112   public abstract Class<?> getClassValue(Class<?> parentClass) throws EvalException;
113 }