Statistics
| Revision:

svn-gvsig-desktop / branches / CatalogYNomenclator_v1_1_0_1005 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / utils / CatalogDriverRegister.java @ 12758

History | View | Annotate | Download (3.92 KB)

1
package es.gva.cit.catalogClient.utils;
2

    
3
import java.util.Iterator;
4

    
5
import com.iver.utiles.extensionPoints.ExtensionPoint;
6
import com.iver.utiles.extensionPoints.ExtensionPoints;
7
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
8

    
9
import es.gva.cit.catalogClient.drivers.ICatalogServiceDriver;
10

    
11
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
12
 *
13
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
28
 *
29
 * For more information, contact:
30
 *
31
 *  Generalitat Valenciana
32
 *   Conselleria d'Infraestructures i Transport
33
 *   Av. Blasco Ib??ez, 50
34
 *   46010 VALENCIA
35
 *   SPAIN
36
 *
37
 *      +34 963862235
38
 *   gvsig@gva.es
39
 *      www.gvsig.gva.es
40
 *
41
 *    or
42
 *
43
 *   IVER T.I. S.A
44
 *   Salamanca 50
45
 *   46005 Valencia
46
 *   Spain
47
 *
48
 *   +34 963163400
49
 *   dac@iver.es
50
 */
51
/* CVS MESSAGES:
52
 *
53
 * $Id: CatalogDriverRegister.java 12758 2007-07-24 11:25:43Z jorpiell $
54
 * $Log$
55
 * Revision 1.1.2.1  2007-07-24 11:25:42  jorpiell
56
 * The registers has been refactorized
57
 *
58
 * Revision 1.1.2.1  2007/07/10 11:18:04  jorpiell
59
 * Added the registers
60
 *
61
 *
62
 */
63
/**
64
 * This class is used to register the different catalog
65
 * drivers and to retrieve them. It uses the gvSIG extension
66
 * points.
67
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
68
 */
69
public class CatalogDriverRegister {
70
        private static CatalogDriverRegister instance = null;
71
        private static final String DRIVER_REGISTER_NAME = "CatalogDrivers";        
72

    
73
        /**
74
         * This method cretaes the singleton instance
75
         *
76
         */
77
        private synchronized static void createInstance() {
78
                if (instance == null) { 
79
                        instance = new CatalogDriverRegister();
80
                }
81
        }
82

    
83
        /**
84
         * @return the remote service instance instance
85
         */
86
        public static CatalogDriverRegister getInstance() {
87
                if (instance == null){
88
                        createInstance();
89
                }
90
                return instance;
91
        }
92

    
93
        /**
94
         * This method is used to register a new catalog driver 
95
         * that manage a concrete protocol
96
         * @param driver
97
         * Catalog driver to register
98
         */
99
        public void register(ICatalogServiceDriver driver){
100
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
101
            extensionPoints.add(DRIVER_REGISTER_NAME,driver.getServiceName(), driver);
102
        }
103

    
104
        /**
105
         * It is used to retrieve a driver that supports a concrete 
106
         * protocol
107
         * @param protocol
108
         * Catalog protocol
109
         * @return
110
         * The concrete catalog service driver
111
         */
112
        public ICatalogServiceDriver getDriver(String protocol){
113
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get(DRIVER_REGISTER_NAME);
114
                Iterator keys = extensionPoint.keySet().iterator();
115
                while (keys.hasNext()){
116
                        Object driver = extensionPoint.get(keys.next());
117
                        if (((ICatalogServiceDriver)driver).getServiceName().compareTo(protocol) == 0){
118
                                return (ICatalogServiceDriver)driver;
119
                        }
120
                }
121
                return null;
122
        }
123
        
124
        
125
        /**
126
         * @return a list with all the gazetteer drivers
127
         */
128
        public ICatalogServiceDriver[] getDrivers(){
129
                ICatalogServiceDriver[] drivers = null;
130
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get(DRIVER_REGISTER_NAME);
131
                drivers = new ICatalogServiceDriver[extensionPoint.keySet().size()];
132
                Iterator keys = extensionPoint.keySet().iterator();                
133
                int i = 0;
134
                while (keys.hasNext()){
135
                        drivers[i] = (ICatalogServiceDriver)extensionPoint.get(keys.next());
136
                        i++;
137
                }
138
                return drivers;
139
        }
140
}