Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1003 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / protocols / Z3950ConnectionFactory.java @ 12271

History | View | Annotate | Download (5.56 KB)

1 7394 jorpiell
package es.gva.cit.catalogClient.protocols;
2
3
import java.beans.Beans;
4
import java.io.File;
5
import java.io.FileNotFoundException;
6
import java.net.URL;
7
import java.util.Hashtable;
8
9
import javax.swing.Spring;
10
import javax.xml.parsers.DocumentBuilderFactory;
11
12
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
13
import org.apache.xerces.jaxp.DocumentBuilderImpl;
14
import org.jzkit.search.provider.iface.SearchException;
15
import org.jzkit.search.provider.iface.Searchable;
16
import org.jzkit.search.provider.z3950.Z3950ServiceFactory;
17
import org.springframework.beans.MutablePropertyValues;
18
import org.springframework.beans.factory.config.ConstructorArgumentValues;
19
import org.springframework.beans.factory.support.AbstractBeanDefinition;
20
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
21
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
22
import org.springframework.beans.factory.xml.BeansDtdResolver;
23
import org.springframework.context.ApplicationContext;
24
import org.springframework.context.support.AbstractApplicationContext;
25
import org.springframework.context.support.AbstractXmlApplicationContext;
26
import org.springframework.context.support.ClassPathXmlApplicationContext;
27
import org.springframework.context.support.FileSystemXmlApplicationContext;
28
import org.springframework.context.support.StaticApplicationContext;
29
import org.springframework.core.io.DefaultResourceLoader;
30
import org.springframework.web.context.support.StaticWebApplicationContext;
31
import org.springframework.web.context.support.XmlWebApplicationContext;
32
33
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
34
 *
35
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
36
 *
37
 * This program is free software; you can redistribute it and/or
38
 * modify it under the terms of the GNU General Public License
39
 * as published by the Free Software Foundation; either version 2
40
 * of the License, or (at your option) any later version.
41
 *
42
 * This program is distributed in the hope that it will be useful,
43
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45
 * GNU General Public License for more details.
46
 *
47
 * You should have received a copy of the GNU General Public License
48
 * along with this program; if not, write to the Free Software
49
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
50
 *
51
 * For more information, contact:
52
 *
53
 *  Generalitat Valenciana
54
 *   Conselleria d'Infraestructures i Transport
55
 *   Av. Blasco Ib??ez, 50
56
 *   46010 VALENCIA
57
 *   SPAIN
58
 *
59
 *      +34 963862235
60
 *   gvsig@gva.es
61
 *      www.gvsig.gva.es
62
 *
63
 *    or
64
 *
65
 *   IVER T.I. S.A
66
 *   Salamanca 50
67
 *   46005 Valencia
68
 *   Spain
69
 *
70
 *   +34 963163400
71
 *   dac@iver.es
72
 */
73
/* CVS MESSAGES:
74
 *
75
 * $Id$
76
 * $Log$
77 8765 jjdelcerro
 * Revision 1.1.2.2  2006-11-15 00:08:08  jjdelcerro
78
 * *** empty log message ***
79
 *
80
 * Revision 1.2  2006/10/02 08:29:07  jorpiell
81
 * Modificados los cambios del Branch 10 al head
82
 *
83
 * Revision 1.1.2.1  2006/09/20 12:01:07  jorpiell
84 7400 jorpiell
 * Se ha cambiado la versi?n de la jzkit, se ha incorporado la funcionalidad de cargar arcims
85
 *
86
 * Revision 1.1  2006/09/20 11:20:17  jorpiell
87 7394 jorpiell
 * Se ha cambiado la versi?n de la librer?a jzkit de la 1 a la 2.0
88
 *
89
 *
90
 */
91
/**
92
 * This factory creates Z39.50 connections
93
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
94
 */
95
public class Z3950ConnectionFactory {
96
        private static ApplicationContext app_context = null;
97
        private static boolean appContextInitialized = false;
98
        private static Z3950ServiceFactory factory = null;
99
        private static Hashtable connections = new Hashtable();
100
101
        public static Z3950Connection getConnection(URL url){
102
                Z3950Connection connection = (Z3950Connection)connections.get(url);
103
                if (connection == null){
104
                        connection = new Z3950Connection(url);
105
                        connections.put(url,connection);
106
                }
107
                return connection;
108
        }
109
110
        public static Searchable getSearchable(URL url) throws SearchException{
111
                if (!(appContextInitialized)){
112
                        initAppContext(url);
113
                        factory = new Z3950ServiceFactory();
114
                        factory.setApplicationContext(app_context);
115
                        factory.setDefaultRecordSyntax("usmarc");
116
                        factory.setDefaultElementSetName("F");
117
                        factory.getRecordArchetypes().put("Default","usmarc::F");
118
                        factory.getRecordArchetypes().put("FullDisplay","usmarc::F");
119
                        factory.getRecordArchetypes().put("BriefDisplay","usmarc::B");
120
                        factory.getRecordArchetypes().put("Holdings","usmarc::F");
121
                }
122
                factory.setHost(url.getHost());
123
                factory.setPort(url.getPort());
124
                Searchable s = factory.newSearchable();
125
                s.setApplicationContext(app_context);
126
                return s;
127
        }
128
129
        /**
130
         * Initialize the application context
131
         * @param url
132
         */
133
        private static void initAppContext(URL url){
134
                System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
135
                try{
136
                        app_context = new FileSystemXmlApplicationContext(new String[]{"config/ApplicationContextAlone.xml"},false);
137
                        ((FileSystemXmlApplicationContext)app_context).setClassLoader(Z3950ConnectionFactory.class.getClassLoader());
138
                        ((FileSystemXmlApplicationContext)app_context).refresh();
139
                }catch(Exception e){
140
                        app_context = new FileSystemXmlApplicationContext(new String[]{"gvSIG/extensiones/es.gva.cit.gvsig.catalogClient/config/ApplicationContext.xml"},false);
141
                        ((FileSystemXmlApplicationContext)app_context).setClassLoader(Z3950ConnectionFactory.class.getClassLoader());
142
                        ((FileSystemXmlApplicationContext)app_context).refresh();
143
                }
144
145
                if (app_context == null){
146
                        throw new RuntimeException("Unable to locate TestApplicationContext.xml definition file");
147
                }
148
                appContextInitialized = true;
149
        }
150
151
}