Statistics
| Revision:

gvsig-catalog / trunk / appCatalog / src / org / gvsig / catalog / protocols / Z3950ConnectionFactory.java @ 6

History | View | Annotate | Download (4.68 KB)

1
package org.gvsig.catalog.protocols;
2

    
3
import java.net.URI;
4
import java.util.Hashtable;
5

    
6
import org.jzkit.search.provider.iface.SearchException;
7
import org.jzkit.search.provider.iface.Searchable;
8
import org.jzkit.search.provider.z3950.Z3950ServiceFactory;
9
import org.springframework.context.ApplicationContext;
10
import org.springframework.context.support.FileSystemXmlApplicationContext;
11

    
12
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
13
 *
14
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
29
 *
30
 * For more information, contact:
31
 *
32
 *  Generalitat Valenciana
33
 *   Conselleria d'Infraestructures i Transport
34
 *   Av. Blasco Ib??ez, 50
35
 *   46010 VALENCIA
36
 *   SPAIN
37
 *
38
 *      +34 963862235
39
 *   gvsig@gva.es
40
 *      www.gvsig.gva.es
41
 *
42
 *    or
43
 *
44
 *   IVER T.I. S.A
45
 *   Salamanca 50
46
 *   46005 Valencia
47
 *   Spain
48
 *
49
 *   +34 963163400
50
 *   dac@iver.es
51
 */
52
/* CVS MESSAGES:
53
 *
54
 * $Id: Z3950ConnectionFactory.java 568 2007-07-27 07:23:27 +0000 (Fri, 27 Jul 2007) jpiera $
55
 * $Log$
56
 * Revision 1.1.2.2.4.2  2007/07/13 12:00:35  jorpiell
57
 * Add the posibility to add a new panel
58
 *
59
 * Revision 1.1.2.2.4.1  2007/07/10 11:18:04  jorpiell
60
 * Added the registers
61
 *
62
 * Revision 1.1.2.2  2006/11/15 00:08:08  jjdelcerro
63
 * *** empty log message ***
64
 *
65
 * Revision 1.2  2006/10/02 08:29:07  jorpiell
66
 * Modificados los cambios del Branch 10 al head
67
 *
68
 * Revision 1.1.2.1  2006/09/20 12:01:07  jorpiell
69
 * Se ha cambiado la versi?n de la jzkit, se ha incorporado la funcionalidad de cargar arcims
70
 *
71
 * Revision 1.1  2006/09/20 11:20:17  jorpiell
72
 * Se ha cambiado la versi?n de la librer?a jzkit de la 1 a la 2.0
73
 *
74
 *
75
 */
76
/**
77
 * This factory creates Z39.50 connections
78
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
79
 */
80
public class Z3950ConnectionFactory {
81
        private static ApplicationContext app_context = null;
82
        private static boolean appContextInitialized = false;
83
        private static Z3950ServiceFactory factory = null;
84
        private static Hashtable connections = new Hashtable();
85
        
86
        public static Z3950Connection getConnection(URI uri){
87
                Z3950Connection connection = (Z3950Connection)connections.get(uri);
88
                if (connection == null){
89
                        connection = new Z3950Connection(uri);
90
                        connections.put(uri,connection);
91
                }
92
                return connection;
93
        }
94
        
95
        public static Searchable getSearchable(URI uri) throws SearchException{
96
                if (!(appContextInitialized)){
97
                        initAppContext(uri);
98
                        factory = new Z3950ServiceFactory();                
99
                        factory.setApplicationContext(app_context);
100
                        factory.setDefaultRecordSyntax("usmarc");
101
                        factory.setDefaultElementSetName("F");
102
                        factory.getRecordArchetypes().put("Default","usmarc::F");
103
                        factory.getRecordArchetypes().put("FullDisplay","usmarc::F");
104
                        factory.getRecordArchetypes().put("BriefDisplay","usmarc::B");
105
                        factory.getRecordArchetypes().put("Holdings","usmarc::F");
106
                }
107
                factory.setHost(uri.getHost());
108
                factory.setPort(uri.getPort());
109
                Searchable s = factory.newSearchable();
110
                s.setApplicationContext(app_context);        
111
                return s;
112
        }
113

    
114
        /**
115
         * Initialize the application context
116
         * @param url 
117
         */
118
        private static void initAppContext(URI uri){
119
                System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
120
                try{
121
                        app_context = new FileSystemXmlApplicationContext(new String[]{"config/ApplicationContextAlone.xml"},false);
122
                        ((FileSystemXmlApplicationContext)app_context).setClassLoader(Z3950ConnectionFactory.class.getClassLoader());
123
                        ((FileSystemXmlApplicationContext)app_context).refresh();
124
                }catch(Exception e){
125
                        e.printStackTrace();
126
                        app_context = new FileSystemXmlApplicationContext(new String[]{"gvSIG/extensiones/es.gva.cit.gvsig.catalogClient/config/ApplicationContext.xml"},false);
127
                        ((FileSystemXmlApplicationContext)app_context).setClassLoader(Z3950ConnectionFactory.class.getClassLoader());
128
                        ((FileSystemXmlApplicationContext)app_context).refresh();
129
                }                        
130
                
131
                if (app_context == null){
132
                        throw new RuntimeException("Unable to locate TestApplicationContext.xml definition file");
133
                }
134
                appContextInitialized = true;
135
        }
136
        
137
}