001: //$HeadURL$
002: /*---------------- FILE HEADER ------------------------------------------
003: This file is part of deegree.
004: Copyright (C) 2001-2008 by:
005: Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/deegree/
007: lat/lon GmbH
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: Contact:
022:
023: Andreas Poth
024: lat/lon GmbH
025: Aennchenstr. 19
026: 53177 Bonn
027: Germany
028: E-Mail: poth@lat-lon.de
029:
030: Prof. Dr. Klaus Greve
031: Department of Geography
032: University of Bonn
033: Meckenheimer Allee 166
034: 53115 Bonn
035: Germany
036: E-Mail: greve@giub.uni-bonn.de
037: ---------------------------------------------------------------------------*/
038:
039: package org.deegree.ogcwebservices.csw.manager;
040:
041: import java.io.IOException;
042: import java.net.URL;
043: import java.util.Collection;
044: import java.util.HashMap;
045: import java.util.Iterator;
046: import java.util.Map;
047:
048: import org.deegree.framework.log.ILogger;
049: import org.deegree.framework.log.LoggerFactory;
050: import org.deegree.framework.xml.XSLTDocument;
051: import org.deegree.ogcwebservices.MissingParameterValueException;
052: import org.deegree.ogcwebservices.csw.configuration.CatalogueConfiguration;
053: import org.deegree.ogcwebservices.csw.configuration.CatalogueDeegreeParams;
054: import org.deegree.ogcwebservices.csw.manager.HarvestRepository.ResourceType;
055: import org.deegree.ogcwebservices.wfs.WFService;
056: import org.deegree.ogcwebservices.wfs.capabilities.WFSCapabilities;
057: import org.xml.sax.SAXException;
058:
059: /**
060: *
061: *
062: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
063: * @author last edited by: $Author: poth $
064: *
065: * @version $Revision: 6251 $, $Date: 2007-03-19 16:59:28 +0100 (Mo, 19 Mrz 2007) $
066: */
067: abstract class AbstractManager implements Manager {
068:
069: private static final ILogger LOG = LoggerFactory
070: .getLogger(AbstractManager.class);
071:
072: protected static Map<ResourceType, AbstractHarvester> harvester = null;
073:
074: protected XSLTDocument IN_XSL = null;
075:
076: protected XSLTDocument OUT_XSL = null;
077:
078: protected WFService wfsService;
079:
080: /**
081: * starts all known/registered harvester. This method can be used to start harvesting using
082: * requests e.g. if a server has been shutdown and restarted.
083: */
084: public static void startAllHarvester() {
085: initHarvester();
086: Collection con = harvester.values();
087: for (Iterator iter = con.iterator(); iter.hasNext();) {
088: AbstractHarvester h = (AbstractHarvester) iter.next();
089: if (!h.isRunning()) {
090: h.startHarvesting();
091: }
092: }
093: }
094:
095: /**
096: * stpos all known/registered harvester. This method can be used to stop harvesting using
097: * requests e.g. if a server has shall be shut down.
098: *
099: */
100: public static void stopAllHarvester() {
101: if (harvester != null) {
102: Collection con = harvester.values();
103: for (Iterator iter = con.iterator(); iter.hasNext();) {
104: AbstractHarvester h = (AbstractHarvester) iter.next();
105: if (h.isRunning()) {
106: LOG.logInfo("stop harvesting for: "
107: + h.getClass().getName());
108: h.stopHarvesting();
109: }
110: }
111: }
112: }
113:
114: /* (non-Javadoc)
115: * @see org.deegree.ogcwebservices.csw.manager.Manager#getWfsService()
116: */
117: public WFService getWFService() {
118: return wfsService;
119: }
120:
121: /* (non-Javadoc)
122: * @see org.deegree.ogcwebservices.csw.manager.Manager#init(org.deegree.ogcwebservices.wfs.WFService, org.deegree.ogcwebservices.csw.configuration.CatalogueConfiguration)
123: */
124: public void init(WFService wfsService,
125: CatalogueConfiguration catalogueConfiguration)
126: throws MissingParameterValueException {
127: this .wfsService = wfsService;
128:
129: // try {
130: CatalogueDeegreeParams cdp = catalogueConfiguration
131: .getDeegreeParams();
132: URL url = cdp.getTransformationInputXSLT().getLinkage()
133: .getHref();
134: IN_XSL = new XSLTDocument();
135: try {
136: IN_XSL.load(url);
137: } catch (IOException e) {
138: String s = "If a CS-W is defined to handle Transaction and/or Harvest requests, XSLT scripts for request transformations (e.g. mapping the input schema to gml) must be defined in the deegreeParams section of the capabilities document. While trying to read an xslt script from: '"
139: + url.toString()
140: + "' (which was defined for the transformation of incoming request), the following error occurred: "
141: + e.getMessage();
142: LOG.logError(s, e);
143: throw new MissingParameterValueException(getClass()
144: .getName(), s);
145: } catch (SAXException e) {
146: String s = "The xslt script (transforming incoming requests) read from the location: '"
147: + url
148: + "' could not be parsed because: "
149: + e.getMessage();
150: LOG.logError(s, e);
151: throw new MissingParameterValueException(getClass()
152: .getName(), s);
153: }
154: url = cdp.getTransformationOutputXSLT().getLinkage().getHref();
155: OUT_XSL = new XSLTDocument();
156: try {
157: OUT_XSL.load(url);
158: } catch (IOException e) {
159: String s = "If a CS-W is defined to handle Transaction and/or Harvest requests, XSLT scripts for request transformations (e.g. mapping the input schema to gml) must be defined in the deegreeParams section of the capabilities document. While trying to read an xslt script from: '"
160: + url.toString()
161: + "' (which was defined for the transformation of the response), the following error occurred: "
162: + e.getMessage();
163: LOG.logError(s, e);
164: throw new MissingParameterValueException(getClass()
165: .getName(), s);
166: } catch (SAXException e) {
167: String s = "The xslt script (transforming the response) read from the location: '"
168: + url
169: + "' could not be parsed because: "
170: + e.getMessage();
171: LOG.logError(s, e);
172: throw new MissingParameterValueException(getClass()
173: .getName(), s);
174: }
175: WFSCapabilities capa = wfsService.getCapabilities();
176:
177: initHarvester();
178:
179: LOG
180: .logInfo("CSW Manager initialized with WFS resource, wfs version:"
181: + capa.getVersion());
182:
183: }
184:
185: /**
186: * initializes a static Map containing a harvester for other coatalogues, for services and for single CSW-profile
187: * documents.
188: */
189: static void initHarvester() {
190: if (harvester == null) {
191: harvester = new HashMap<ResourceType, AbstractHarvester>();
192: harvester.put(ResourceType.catalogue, CatalogueHarvester
193: .getInstance());
194: harvester.put(ResourceType.service, ServiceHarvester
195: .getInstance());
196: harvester.put(ResourceType.csw_profile, CSWProfileHarvester
197: .getInstance());
198: }
199: }
200:
201: }
|