root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / protocols / Z3950ConnectionFactory.java @ 7394
History | View | Annotate | Download (5.24 KB)
1 |
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: Z3950ConnectionFactory.java 7394 2006-09-20 11:24:05Z jorpiell $
|
76 |
* $Log$
|
77 |
* Revision 1.1 2006-09-20 11:20:17 jorpiell
|
78 |
* Se ha cambiado la versi?n de la librer?a jzkit de la 1 a la 2.0
|
79 |
*
|
80 |
*
|
81 |
*/
|
82 |
/**
|
83 |
* This factory creates Z39.50 connections
|
84 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
85 |
*/
|
86 |
public class Z3950ConnectionFactory { |
87 |
private static ApplicationContext app_context = null; |
88 |
private static boolean appContextInitialized = false; |
89 |
private static Z3950ServiceFactory factory = null; |
90 |
private static Hashtable connections = new Hashtable(); |
91 |
|
92 |
public static Z3950Connection getConnection(URL url){ |
93 |
Z3950Connection connection = (Z3950Connection)connections.get(url); |
94 |
if (connection == null){ |
95 |
connection = new Z3950Connection(url);
|
96 |
connections.put(url,connection); |
97 |
} |
98 |
return connection;
|
99 |
} |
100 |
|
101 |
public static Searchable getSearchable(URL url) throws SearchException{ |
102 |
if (!(appContextInitialized)){
|
103 |
initAppContext(url); |
104 |
factory = new Z3950ServiceFactory();
|
105 |
factory.setApplicationContext(app_context); |
106 |
factory.setDefaultRecordSyntax("usmarc");
|
107 |
factory.setDefaultElementSetName("F");
|
108 |
factory.getRecordArchetypes().put("Default","usmarc::F"); |
109 |
factory.getRecordArchetypes().put("FullDisplay","usmarc::F"); |
110 |
factory.getRecordArchetypes().put("BriefDisplay","usmarc::B"); |
111 |
factory.getRecordArchetypes().put("Holdings","usmarc::F"); |
112 |
} |
113 |
factory.setHost(url.getHost()); |
114 |
factory.setPort(url.getPort()); |
115 |
Searchable s = factory.newSearchable(); |
116 |
s.setApplicationContext(app_context); |
117 |
return s;
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* Initialize the application context
|
122 |
* @param url
|
123 |
*/
|
124 |
private static void initAppContext(URL url){ |
125 |
System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); |
126 |
try{
|
127 |
app_context = new FileSystemXmlApplicationContext(new String[]{"config/ApplicationContextAlone.xml"},false); |
128 |
((FileSystemXmlApplicationContext)app_context).setClassLoader(Z3950ConnectionFactory.class.getClassLoader()); |
129 |
((FileSystemXmlApplicationContext)app_context).refresh(); |
130 |
}catch(Exception e){ |
131 |
app_context = new FileSystemXmlApplicationContext(new String[]{"gvSIG/extensiones/es.gva.cit.gvsig.catalogClient/config/ApplicationContext.xml"},false); |
132 |
((FileSystemXmlApplicationContext)app_context).setClassLoader(Z3950ConnectionFactory.class.getClassLoader()); |
133 |
((FileSystemXmlApplicationContext)app_context).refresh(); |
134 |
} |
135 |
|
136 |
if (app_context == null){ |
137 |
throw new RuntimeException("Unable to locate TestApplicationContext.xml definition file"); |
138 |
} |
139 |
appContextInitialized = true;
|
140 |
} |
141 |
|
142 |
} |