Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / DefaultFeatureRules.java @ 44871

History | View | Annotate | Download (3.86 KB)

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

    
26
import java.util.ArrayList;
27
import java.util.Iterator;
28
import org.gvsig.expressionevaluator.Expression;
29
import org.gvsig.expressionevaluator.impl.DefaultFeatureRuleExpression;
30

    
31
import org.gvsig.fmap.dal.exception.DataException;
32
import org.gvsig.fmap.dal.feature.Feature;
33
import org.gvsig.fmap.dal.feature.FeatureRule;
34
import org.gvsig.fmap.dal.feature.FeatureRules;
35
import org.gvsig.fmap.dal.feature.FeatureStore;
36
import org.gvsig.tools.persistence.PersistentState;
37
import org.gvsig.tools.persistence.exception.PersistenceException;
38
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40

    
41
public class DefaultFeatureRules extends ArrayList<FeatureRule> implements FeatureRules {
42

    
43
  private final static Logger LOGGER = LoggerFactory.getLogger(DefaultFeatureRules.class);
44

    
45
  /**
46
   *
47
   */
48
  private static final long serialVersionUID = -8084546505498274121L;
49

    
50
  @Override
51
  public boolean add(FeatureRule rule) {
52
    return super.add(rule);
53
  }
54

    
55
  @Override
56
  public boolean add(String name, String description, boolean checkAtUpdate, boolean checkAtFinishEdition, Expression expression) {
57
    FeatureRule rule = new DefaultFeatureRuleExpression(name, description, checkAtUpdate, checkAtFinishEdition, expression);
58
    return this.add(rule);
59
  }
60

    
61
  @Override
62
  public FeatureRule getRule(int index) {
63
    return (FeatureRule) super.get(index);
64
  }
65

    
66
  @Override
67
  public boolean remove(FeatureRule rule) {
68
    return super.remove(rule);
69
  }
70

    
71
  @Override
72
  public FeatureRules getCopy() {
73
    DefaultFeatureRules copy = new DefaultFeatureRules();
74
    copy.addAll(this);
75
    return copy;
76
  }
77

    
78
//        /**
79
//         * @deprecated use validate(Feature feature, int mode)
80
//         * @param feature
81
//         * @throws DataException 
82
//         */
83
//        public void validate(Feature feature) throws DataException {
84
//            logger.warn("Calling deprecated method validate without mode.");
85
//            FeatureStore store = ((DefaultFeature)feature).getStore();
86
//            for( FeatureRule rule : this ) {
87
//                rule.validate(feature, store);
88
//            }
89
//
90
//        }
91
  public void validate(Feature feature, int mode) throws DataException {
92
    FeatureStore store = ((DefaultFeature) feature).getStore();
93
    for (FeatureRule rule : this) {
94
      if (rule.checkAtFinishEditing() && mode == Feature.FINISH_EDITING) {
95
        rule.validate(feature, store);
96
      }
97
      if (rule.checkAtUpdate() && mode == Feature.UPDATE) {
98
        rule.validate(feature, store);
99
      }
100
    }
101

    
102
  }
103

    
104
  public static void selfRegister() {
105
    
106
  }
107

    
108
  @Override
109
  public void saveToState(PersistentState state) throws PersistenceException {
110
    state.set("rules", this.iterator());
111
  }
112

    
113
  @Override
114
  public void loadFromState(PersistentState state) throws PersistenceException {
115
    this.clear();
116
    Iterator<FeatureRule> it = state.getIterator("rules");
117
    while (it.hasNext()) {
118
      FeatureRule rule = it.next();
119
      this.add(rule);
120
    }
121
  }
122
  
123
}