001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wfs/operation/Lock.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    package org.deegree.ogcwebservices.wfs.operation;
037    
038    import org.deegree.datatypes.QualifiedName;
039    import org.deegree.framework.log.ILogger;
040    import org.deegree.framework.log.LoggerFactory;
041    import org.deegree.model.feature.Feature;
042    import org.deegree.model.feature.schema.FeatureType;
043    import org.deegree.model.filterencoding.Filter;
044    import org.deegree.ogcwebservices.wfs.WFService;
045    
046    /**
047     * Represents a <code>wfs:Lock</code> element (usually part of <code>wfs:LockFeature</code> documents).
048     *
049     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a>
050     * @author last edited by: $Author: mschneider $
051     *
052     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
053     */
054    public class Lock {
055    
056        private static final ILogger LOG = LoggerFactory.getLogger( Lock.class );
057    
058        private String handle;
059    
060        private QualifiedName typeName;
061    
062        private Filter filter;
063    
064        /**
065         * Creates a new <code>Lock</code> instance from the given parameters.
066         *
067         * @param handle
068         * @param typeName
069         * @param filter
070         */
071        public Lock( String handle, QualifiedName typeName, Filter filter ) {
072            this.handle = handle;
073            this.typeName = typeName;
074            this.filter = filter;
075        }
076    
077        /**
078         * Returns the lock's handle.
079         *
080         * @return the lock's handle (may be null)
081         */
082        public String getHandle() {
083            return this.handle;
084        }
085    
086        /**
087         * Returns the name of the {@link FeatureType} that is affected by this lock.
088         *
089         * @return the name of the <code>FeatureType</code> (never null)
090         */
091        public QualifiedName getTypeName() {
092            return this.typeName;
093        }
094    
095        /**
096         * Returns the filter that is used to select the {@link Feature} instances for locking.
097         *
098         * @return the filter that is used to select the <code>Feature<code> instances (may be null)
099         */
100        public Filter getFilter() {
101            return this.filter;
102        }
103    
104        /**
105         * Adds missing namespaces in the names of targeted feature types.
106         * <p>
107         * If the {@link QualifiedName} of a targeted type has a null namespace, the first qualified feature type name of
108         * the given {@link WFService} with the same local name is used instead.
109         * <p>
110         * Note: The method changes this request part (the feature type names) and should only be called by the
111         * <code>WFSHandler</code> class.
112         *
113         * @param wfs
114         *            {@link WFService} instance that is used for the lookup of proper (qualified) feature type names
115         */
116        public void guessMissingNamespaces( WFService wfs ) {
117            if ( typeName.getNamespace() == null ) {
118                if ( typeName.getLocalName().equals( typeName.getLocalName() ) ) {
119                    LOG.logWarning( "Requested feature type name has no namespace information. Guessing namespace for feature type '"
120                                    + typeName.getLocalName() + "' (quirks lookup mode)." );
121                    for ( QualifiedName ftName : wfs.getMappedFeatureTypes().keySet() ) {
122                        if ( ftName.getLocalName().equals( typeName.getLocalName() ) ) {
123                            LOG.logWarning( "Using feature type '" + ftName + "'." );
124                            typeName = ftName;
125                            break;
126                        }
127                    }
128                }
129            }
130        }
131    }