Statistics
| Revision:

gvsig-sldtools / org.gvsig.sld / org.gvsig.sldsupport / org.gvsig.sldsupport.lib / org.gvsig.sldsupport.lib.impl / src / main / java / org / gvsig / sldsupport / impl / sld / parsing / filteroperator / logic / UnaryLogicOperatorElement.java @ 46

History | View | Annotate | Download (3.26 KB)

1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.sldsupport.impl.sld.parsing.filteroperator.logic;
27

    
28
import java.io.IOException;
29

    
30
import org.xmlpull.v1.XmlPullParser;
31
import org.xmlpull.v1.XmlPullParserException;
32

    
33
import org.gvsig.sldsupport.exception.InvalidSLDObjectException;
34
import org.gvsig.sldsupport.exception.SLDReadException;
35
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException;
36
import org.gvsig.sldsupport.impl.sld.parsing.filteroperator.FilterOperatorElement;
37
import org.gvsig.sldsupport.impl.util.SLDUtils;
38
import org.gvsig.sldsupport.impl.util.XmlBuilder;
39
import org.gvsig.sldsupport.sld.filter.FilterTags;
40
import org.gvsig.sldsupport.sld.filter.SLDFilterOperator;
41
import org.gvsig.sldsupport.sld.filter.operator.logic.SLDUnaryLogicOperator;
42

    
43
public class UnaryLogicOperatorElement {
44

    
45
    public static void append(SLDUnaryLogicOperator obj, XmlBuilder xb,
46
        String version) throws InvalidSLDObjectException,
47
        UnsupportedSLDObjectException {
48

    
49
        xb.openTag(obj.getOperatorType());
50
        // ==========================
51
        if (obj.getOperator() == null) {
52
            throw new InvalidSLDObjectException(obj.getOperatorType(),
53
                "No operand found in unary operator");
54
        }
55
        FilterOperatorElement.append(obj.getOperator(), xb, version);
56
        // ==========================
57
        xb.closeTag();
58
    }
59

    
60
    public static SLDUnaryLogicOperator parse(XmlPullParser parser,
61
        String version) throws XmlPullParserException, IOException,
62
        SLDReadException {
63

    
64
        SLDUnaryLogicOperator resp = new SLDUnaryLogicOperator();
65
        String op_type = parser.getName();
66
        if (SLDUtils.isStr(op_type, FilterTags.NOT)) {
67
            resp.setOperatorType(FilterTags.NOT);
68
        } else {
69
            throw new SLDReadException("Unknwon unary operator: " + op_type);
70
        }
71

    
72
        parser.nextTag();
73
        SLDFilterOperator foper = FilterOperatorElement.parse(parser, version);
74
        resp.setOperator(foper);
75
        parser.require(XmlPullParser.END_TAG, null, FilterTags.NOT);
76
        parser.nextTag();
77
        return resp;
78
    }
79
}