Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / io / rmf / ClientRegister.java @ 12281

History | View | Annotate | Download (3.01 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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
package org.gvsig.raster.dataset.io.rmf;
20

    
21
import java.util.ArrayList;
22

    
23
/**
24
 * Clase base para el gestor de ficheros rmf. Esta contiene el mecanismo de registro de objetos
25
 * serializadores. Mantiene una lista de IRmfBlock.
26
 * 
27
 * 21-abr-2007
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public abstract class ClientRegister {
31

    
32
        protected ArrayList clients = new ArrayList();
33
        
34
        /**
35
         * A?ade un objeto IRmfBlock
36
         * @param block
37
         */
38
        public void addClient(IRmfBlock block) {
39
                for (int i = 0; i < clients.size(); i++) {
40
                        if(clients.get(i).getClass().equals(block.getClass()))
41
                                clients.remove(i);
42
                }
43
                clients.add(block);
44
        }
45
        
46
        /**
47
         * Elimina un objeto IRmfBlock de la lista a trav?s del nombre de su serializador. El nombre
48
         * de este coincide con el nombre del objeto que se est? serializando seguido de la palabra 
49
         * Serializer. Asi pues, el serializador del objeto Histogram se llamar? HistogramSerializer.
50
         * @param id
51
         */
52
        public void removeClient(Class c) {
53
                for (int i = 0; i < clients.size(); i++) {
54
                        if(clients.get(i).getClass().equals(c))
55
                                clients.remove(i);
56
                }
57
        }
58
        
59
        /**
60
         * Obtiene el objeto serializador a trav?s de su nombre de clase. El nombre
61
         * de este coincide con el nombre del objeto que se est? serializando seguido de la palabra 
62
         * Serializer. Asi pues, el serializador del objeto Histogram se llamar? HistogramSerializer.
63
         * @param id
64
         * @return IRmfBlock
65
         */
66
        public IRmfBlock getClient(String id) {
67
                for (int i = 0; i < clients.size(); i++) {
68
                        try {
69
                                if(Class.forName(id).isInstance(clients.get(i)))
70
                                        return (IRmfBlock)clients.get(i);
71
                        } catch (ClassNotFoundException e) {
72
                                return null; //No devuelve ninguno
73
                        }
74
                }
75
                return null;
76
        }
77
        
78
        /**
79
         * Obtiene el objeto serializador a trav?s de su posici?n. 
80
         * @param pos Posici?n
81
         * @return IRmfBlock
82
         */
83
        public IRmfBlock getClient(int pos) {
84
                return (IRmfBlock)clients.get(pos);
85
        }
86
        
87
        /**
88
         * Elimina todos los objetos serializadores de la lista.
89
         */
90
        public void deleteAllClients() {
91
                clients.clear();
92
        }
93
        
94
        /**
95
         * Obtiene el n?mero de clientes registrado (Objetos IRmfBlock).
96
         * @return Entero con el n?mero de clientes registrado
97
         */
98
        public int getClientsCount() {
99
                return clients.size();
100
        }
101
}