Statistics
| Revision:

svn-gvsig-desktop / branches / v02_desarrollo / libraries / sld / org.gvsig.sldsupport / org.gvsig.sldsupport.lib / org.gvsig.sldsupport.lib.api / src / main / java / org / gvsig / sldsupport / filterencoding / operations / OperatorsFactory.java @ 40754

History | View | Annotate | Download (3.58 KB)

1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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.sldsupport.filterencoding.operations;
42

    
43

    
44
import java.util.HashMap;
45
import java.util.Hashtable;
46

    
47

    
48
/**
49
 * Implements methods that allow the user to create new operators to be
50
 * included in an expression to be parsed
51
 *
52
 * @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es
53
 *
54
 */
55
public class OperatorsFactory  {
56

    
57
        private static OperatorsFactory instance = new OperatorsFactory();
58
    public HashMap<String,Class> functions = new HashMap<String,Class>();
59
        Class myClass;
60

    
61
    public static OperatorsFactory getInstance()
62
    {
63
        return instance;
64
    }
65

    
66
    private OperatorsFactory()
67
    {
68

    
69
        // logical functions
70
        addOperator(OrOperator.class);
71
        addOperator(AndOperator.class);
72
        addOperator(NotOperator.class);
73
        addOperator(EqOperator.class);
74
        addOperator(NeOperator.class);
75
        addOperator(LessThanOperator.class);
76
        addOperator(LessThanOrEqualsOperator.class);
77
        addOperator(GreaterThanOperator.class);
78
        addOperator(GreaterThanOrEqualsOperator.class);
79
        addOperator(AddOperator.class);
80
        addOperator(MinusOperator.class);
81
        addOperator(MultOperator.class);
82
        addOperator(DivOperator.class);
83
        addOperator(IsBetweenOperator.class);
84
        addOperator(IsNullOperator.class);
85
        addOperator(ReplaceOperator.class);
86

    
87
    }
88

    
89
    public void addOperator(Class<? extends Expression> newClass)
90
    {
91
        if (!Expression.class.isAssignableFrom(newClass))
92
            throw new RuntimeException("Tried to register an operator which does not implement the Expression inteface");
93

    
94
        try {
95
                        functions.put(((Expression) newClass.
96
                                        getConstructor(new Class[] { Hashtable.class }).newInstance(
97
                                                        new Hashtable<String, Object>())).getName(), newClass);
98

    
99
                } catch (Exception e) {
100
                         throw new RuntimeException("Tried to register an operator which does not implement the Expression inteface");
101
                }
102

    
103
    }
104

    
105

    
106
    public Expression getOperator(String name) throws Exception {
107

    
108
        return (Expression)functions.get(name).newInstance();
109

    
110
    }
111

    
112
    public Expression createOperator(String name) throws Exception
113
    {
114
            myClass = (Class)functions.get(name);
115
        if (myClass == null)
116
            return null;
117

    
118
        return (Expression)myClass.newInstance();
119
    }
120

    
121

    
122

    
123
}