Statistics
| Revision:

root / trunk / extensions / extSymbology / src / org / gvsig / symbology / fmap / labeling / lang / functions / Substring.java @ 20768

History | View | Annotate | Download (2.53 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.labeling.lang.functions;
42

    
43
import org.gvsig.symbology.fmap.labeling.lang.Function;
44
import org.gvsig.symbology.fmap.labeling.parse.SemanticException;
45

    
46
import com.hardcode.gdbms.engine.instruction.EvaluationException;
47

    
48
public class Substring implements Function {
49
        
50
        public Object evaluate(Object[] args)  throws SemanticException, EvaluationException {
51
                final String inputString;
52
                final int beginIndex;
53
                final int endIndex;
54
                try {
55
                        inputString = (String) args[0];
56
                } catch (ClassCastException ccEx) {
57
                        throw new SemanticException(SemanticException.TYPE_MISMATCH);
58
                }
59

    
60
                try {
61
                        beginIndex = (Integer) args[1];
62
                } catch (ClassCastException ccEx) {
63
                        throw new SemanticException(SemanticException.TYPE_MISMATCH);
64
                }
65
                
66
                try {
67
                        endIndex = (Integer) args[2];
68
                } catch (ClassCastException ccEx) {
69
                        throw new SemanticException(SemanticException.TYPE_MISMATCH);
70
                }
71
                
72
                if (endIndex < beginIndex) {
73
                        throw new EvaluationException("Begining index is greather than the ending index!");
74
                }
75
        
76
                if (inputString == null) return "";
77
                try {
78
                        return inputString.substring(beginIndex, endIndex);
79
                } catch (Exception e) {
80
                        throw new EvaluationException(e);
81
                }
82
        }
83

    
84
        public int getArgumentCount() {
85
                return 3;
86
        }
87

    
88
        public String getName() {
89
                return "Substring";
90
        }
91

    
92
        public Class returnType() {
93
                return String.class;
94
        }
95
}