001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/csw/manager/Transaction.java $ 002 /*---------------------------------------------------------------------------- 003 This file is part of deegree, http://deegree.org/ 004 Copyright (C) 2001-2009 by: 005 Department of Geography, University of Bonn 006 and 007 lat/lon GmbH 008 009 This library is free software; you can redistribute it and/or modify it under 010 the terms of the GNU Lesser General Public License as published by the Free 011 Software Foundation; either version 2.1 of the License, or (at your option) 012 any later version. 013 This library is distributed in the hope that it will be useful, but WITHOUT 014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 016 details. 017 You should have received a copy of the GNU Lesser General Public License 018 along with this library; if not, write to the Free Software Foundation, Inc., 019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 020 021 Contact information: 022 023 lat/lon GmbH 024 Aennchenstr. 19, 53177 Bonn 025 Germany 026 http://lat-lon.de/ 027 028 Department of Geography, University of Bonn 029 Prof. Dr. Klaus Greve 030 Postfach 1147, 53001 Bonn 031 Germany 032 http://www.geographie.uni-bonn.de/deegree/ 033 034 e-mail: info@deegree.org 035 ----------------------------------------------------------------------------*/ 036 037 package org.deegree.ogcwebservices.csw.manager; 038 039 import java.util.List; 040 import java.util.Map; 041 042 import org.deegree.framework.log.ILogger; 043 import org.deegree.framework.log.LoggerFactory; 044 import org.deegree.framework.xml.NamespaceContext; 045 import org.deegree.framework.xml.XMLException; 046 import org.deegree.framework.xml.XMLParsingException; 047 import org.deegree.framework.xml.XMLTools; 048 import org.deegree.i18n.Messages; 049 import org.deegree.ogcbase.CommonNamespaces; 050 import org.deegree.ogcbase.ExceptionCode; 051 import org.deegree.ogcwebservices.AbstractOGCWebServiceRequest; 052 import org.deegree.ogcwebservices.InvalidParameterValueException; 053 import org.deegree.ogcwebservices.OGCWebServiceException; 054 import org.deegree.ogcwebservices.csw.CSWPropertiesAccess; 055 import org.w3c.dom.Element; 056 057 /** 058 * A Transaction defines an atomic unit of work and is a container for one or more insert, update 059 * and/or delete actions. 060 * 061 * 062 * @version $Revision: 18195 $ 063 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 064 * @author last edited by: $Author: mschneider $ 065 * 066 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $ 067 * 068 */ 069 public class Transaction extends AbstractOGCWebServiceRequest { 070 071 private static final long serialVersionUID = -4393029325052150570L; 072 073 protected static final ILogger LOG = LoggerFactory.getLogger( Transaction.class ); 074 075 private static NamespaceContext nsContext = CommonNamespaces.getNamespaceContext(); 076 077 private List<Operation> operations = null; 078 079 private boolean verboseResponse = false; 080 081 /** 082 * creates a Transaction object from its XML representation defined in OGC CS-W 2.0.0 083 * specification 084 * 085 * @param id 086 * uniquely identifies the given request 087 * 088 * @param root 089 * the root of the xml-encoded transaction request 090 * @return a Transaction with the values taken form the XML-Document. 091 * @throws OGCWebServiceException 092 * if the Transaction could not be created 093 */ 094 public static final Transaction create( String id, Element root ) 095 throws OGCWebServiceException { 096 097 String version = null; 098 try { 099 // first try to read verdsion attribute which is optional for CSW 2.0.0 and 2.0.1 100 version = XMLTools.getNodeAsString( root, "./@version", nsContext, null ); 101 } catch ( XMLParsingException e ) { 102 // ignored 103 } 104 if ( version == null ) { 105 // if no version attribute has been set try mapping namespace URI to a version; 106 // this is not well defined for 2.0.0 and 2.0.1 which uses the same namespace. 107 // in this case 2.0.0 will be returned! 108 version = CSWPropertiesAccess.getString( root.getNamespaceURI() ); 109 } 110 111 // read class for version depenging parsing of Transaction request from properties 112 String className = CSWPropertiesAccess.getString( "Transaction" + version ); 113 Class<?> clzz = null; 114 try { 115 clzz = Class.forName( className ); 116 } catch ( ClassNotFoundException e ) { 117 LOG.logError( e.getMessage(), e ); 118 throw new InvalidParameterValueException( e.getMessage(), e ); 119 } 120 TransactionDocument document = null; 121 try { 122 document = (TransactionDocument) clzz.newInstance(); 123 } catch ( InstantiationException e ) { 124 LOG.logError( e.getMessage(), e ); 125 throw new InvalidParameterValueException( e.getMessage(), e ); 126 } catch ( IllegalAccessException e ) { 127 LOG.logError( e.getMessage(), e ); 128 throw new InvalidParameterValueException( e.getMessage(), e ); 129 } 130 131 document.setRootElement( root ); 132 133 try { 134 return document.parse( id ); 135 } catch ( XMLException e ) { 136 String msg = Messages.getMessage( "CSW_ERROR_WHILE_PARSING_TRANSACTION", e.getMessage() ); 137 LOG.logError( msg, e ); 138 throw new OGCWebServiceException( msg, ExceptionCode.INVALID_FORMAT ); 139 } catch ( XMLParsingException e ) { 140 String msg = Messages.getMessage( "CSW_ERROR_WHILE_PARSING_TRANSACTION", e.getMessage() ); 141 LOG.logError( msg, e ); 142 throw new OGCWebServiceException( msg, ExceptionCode.INVALID_FORMAT ); 143 } 144 } 145 146 /** 147 * 148 * @param version 149 * @param id 150 * @param vendorSpecificParameter 151 * @param operations 152 * @param verboseResponse 153 */ 154 public Transaction( String version, String id, Map<String, String> vendorSpecificParameter, 155 List<Operation> operations, boolean verboseResponse ) { 156 super( version, id, vendorSpecificParameter ); 157 this.operations = operations; 158 this.verboseResponse = verboseResponse; 159 } 160 161 /** 162 * @return the name of the service; always CSW 163 */ 164 public String getServiceName() { 165 return "CSW"; 166 } 167 168 /** 169 * The verboseResponseattribute is a boolean that may be used by a client to indicate to a 170 * server the amount of detail to generate in the rsponse. A value of FALSE means that a CSW 171 * should generate a terse or brief transaction response. A value of TRUE, or the absence of the 172 * attribute, means that the normal detailed transaction response should be generated. 173 * 174 * @return true if the response should be verbose 175 */ 176 public boolean verboseResponse() { 177 return verboseResponse; 178 } 179 180 /** 181 * returns all operations being part of a transaction 182 * 183 * @return all operations being part of a transaction 184 */ 185 public List<Operation> getOperations() { 186 return operations; 187 } 188 }