View Javadoc

1   /*
2    * Copyright (c) 2006-2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.danube.webdav.xml.dav.request;
14  
15  import org.abstracthorizon.danube.webdav.lock.LockingMechanism;
16  import org.abstracthorizon.danube.webdav.xml.XMLParserHandler;
17  import org.abstracthorizon.danube.webdav.xml.dav.DAVAbstractXMLParser;
18  import org.abstracthorizon.danube.webdav.xml.dav.DAVFactory;
19  
20  import org.xml.sax.Attributes;
21  import org.xml.sax.SAXException;
22  
23  /**
24   * This class models WebDAV's lockentry tag
25   *
26   * @author Daniel Sendula
27   */
28  public class LockEntry extends DAVAbstractXMLParser {
29  
30      /** Requested lock scope */
31      protected LockScope lockScope;
32  
33      /** Requested lock type */
34      protected LockType lockType;
35  
36      /**
37       * Constructor
38       * @param parent parent parser handler
39       * @param factory factory
40       */
41      public LockEntry(XMLParserHandler parent, DAVFactory factory) {
42          super(parent, factory);
43          lockScope = factory.newLockScope(this);
44          lockType = factory.newLockType(this);
45      }
46  
47      @Override
48      public Object start(Object current, String tag, Attributes attributes) throws SAXException {
49          if ("lockscope".equals(tag)) {
50              return lockScope;
51          } else if ("locktype".equals(tag)) {
52              return lockType;
53          }  else {
54              return super.start(current, tag, attributes);
55          }
56      }
57  
58      @Override
59      public Object end(Object current, String tag, String value) throws SAXException {
60          return this;
61      }
62  
63      /**
64       * Returns requested lock's type.
65       * @return lock's type
66       * @see LockingMechanism#TYPE_WRITE
67       */
68      public int getType() {
69          return LockingMechanism.TYPE_WRITE;
70      }
71  
72      /**
73       * Returns requested lock's scope.
74       * @return lock's scope
75       * @see LockingMechanism#SCOPE_EXCLUSIVE
76       * @see LockingMechanism#SCOPE_SHARED
77       */
78      public int getScope() {
79          if (lockScope == null) {
80              return LockingMechanism.SCOPE_NONE;
81          } else {
82              return lockScope.getScope();
83          }
84      }
85  
86      @Override
87      public String toString() {
88          return "LockEntry[" + lockScope + "," + lockType + "]";
89      }
90  }