Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libTools / src / org / gvsig / tools / visitor / impl / AbstractIndexedVisitable.java @ 31544

History | View | Annotate | Download (2.46 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {}  {{Task}}
26
 */
27
package org.gvsig.tools.visitor.impl;
28

    
29
import org.gvsig.tools.exception.BaseException;
30
import org.gvsig.tools.visitor.IndexedVisitable;
31
import org.gvsig.tools.visitor.VisitCanceledException;
32
import org.gvsig.tools.visitor.Visitable;
33
import org.gvsig.tools.visitor.Visitor;
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

    
37
/**
38
 * Abstract base implementation for {@link Visitable} classes.
39
 * 
40
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
41
 */
42
public abstract class AbstractIndexedVisitable extends AbstractVisitable
43
                implements IndexedVisitable {
44

    
45
        private static final Logger LOG =
46
                        LoggerFactory.getLogger(AbstractIndexedVisitable.class);
47

    
48
        public final void accept(Visitor visitor, long firstValueIndex)
49
                        throws BaseException {
50
                try {
51
                        doAccept(visitor, firstValueIndex);
52
                } catch (VisitCanceledException ex) {
53
                        // The visit has been cancelled by the visitor, so we finish here.
54
                        LOG.debug(
55
                                        "The visit, beggining on position {}, has been cancelled by the visitor: {}",
56
                                        new Long(firstValueIndex), visitor);
57
                }
58
        }
59

    
60
        protected void doAccept(Visitor visitor) throws VisitCanceledException,
61
                        BaseException {
62
                doAccept(visitor, 0);
63
        }
64

    
65
        /**
66
         * Provides each value of this container to the provided {@link Visitor}.
67
         * The {@link VisitCanceledException} will be managed by the parent
68
         * {@link AbstractIndexedVisitable} class, so simply throw it.
69
         */
70
        protected abstract void doAccept(Visitor visitor, long firstValueIndex)
71
                        throws VisitCanceledException, BaseException;
72

    
73
}