smbdav
Class AbstractProperty

java.lang.Object
  extended bysmbdav.AbstractProperty
All Implemented Interfaces:
Property
Direct Known Subclasses:
CreationDateProperty, DisplayNameProperty, GetContentLengthProperty, GetContentTypeProperty, GetETagProperty, GetLastModifiedProperty, IsCollectionProperty, IsHiddenProperty, IsReadOnlyProperty, LockDiscoveryProperty, ResourceTypeProperty, SupportedLockProperty

public abstract class AbstractProperty
extends java.lang.Object
implements Property

This class provides a basic implementation of much of the Property interface. Subclasses need only provide an implementation of the retrieve method for read-only properties which apply to all resources.

Author:
Eric Glass

Field Summary
 
Fields inherited from interface smbdav.Property
DAV_NAMESPACE, WEB_FOLDERS_NAMESPACE, XMLNS_NAMESPACE
 
Constructor Summary
AbstractProperty()
           
 
Method Summary
protected  void addNamespace(org.w3c.dom.Document document, java.lang.String namespace, java.lang.String prefix)
          Assigns the given prefix to the specified namespace URI in the provided document.
 org.w3c.dom.Element createElement(org.w3c.dom.Document document, jcifs.smb.SmbFile file)
          Creates a property element for the given resource (if applicable), with the specified document as the owner.
 void destroy()
          Disposes of the property.
 boolean equals(java.lang.Object obj)
          Indicates whether an Object is equivalent to this Property object.
 java.lang.String getName()
          Returns the property name.
 java.lang.String getNamespace()
          Returns the namespace URI of the property.
protected  java.lang.String getNamespace(org.w3c.dom.Document document, java.lang.String prefix)
          Returns the namespace URI with the given assigned prefix in the specified document.
 java.lang.String getPrefix()
          Returns the prefix used when creating elements for this property.
protected  java.lang.String getPrefix(org.w3c.dom.Document document, java.lang.String namespace)
          Returns the prefix for the specified namespace URI in the given document, or null for the default namespace.
protected  javax.servlet.ServletConfig getServletConfig()
          Returns the servlet configuration.
 int hashCode()
          Returns the hash code for this property.
 void init(java.lang.String name, javax.servlet.ServletConfig config)
          Initilizes the property and identifies it with the provided name.
abstract  int retrieve(jcifs.smb.SmbFile file, org.w3c.dom.Element element)
          Populates the provided Element with the current value of the property for the given resource.
 java.lang.String toString()
           
 int update(jcifs.smb.SmbFile file, org.w3c.dom.Element element)
          Updates this property on the given resource using the information int the specified element.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractProperty

public AbstractProperty()
Method Detail

init

public void init(java.lang.String name,
                 javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Description copied from interface: Property
Initilizes the property and identifies it with the provided name.

Specified by:
init in interface Property
Parameters:
name - The name by which the property will be identified.
config - The servlet configuration object containing initialization information for the property.
Throws:
javax.servlet.ServletException - If the property could not be initialized.

destroy

public void destroy()
Description copied from interface: Property
Disposes of the property.

Specified by:
destroy in interface Property

getName

public java.lang.String getName()
Description copied from interface: Property
Returns the property name.

Specified by:
getName in interface Property
Returns:
A String containing the name of the property. This will be the local name of the element in the XML document.

getNamespace

public java.lang.String getNamespace()
Description copied from interface: Property
Returns the namespace URI of the property.

Specified by:
getNamespace in interface Property
Returns:
A String containing the namespace URI in which the property resides.

getPrefix

public java.lang.String getPrefix()
Description copied from interface: Property
Returns the prefix used when creating elements for this property. If the namespace URI for this property already has a prefix associated with it, the existing prefix will be used.

Specified by:
getPrefix in interface Property
Returns:
A String containing the prefix applied to elements created by this property.

createElement

public org.w3c.dom.Element createElement(org.w3c.dom.Document document,
                                         jcifs.smb.SmbFile file)
                                  throws java.io.IOException
Creates a property element for the given resource (if applicable), with the specified document as the owner. The element will not be added to the document. This default implementation creates an empty element, and adds a namespace assignment to the given document if necessary.

Specified by:
createElement in interface Property
Parameters:
document - The document that is to own the property element.
file - The resource being queried.
Returns:
An Element for the property. If this property does not apply to the specified resource, null will be returned. The default implementation creates an empty element for all resources.
Throws:
java.io.IOException - If an IO error occurs while creating the element.

update

public int update(jcifs.smb.SmbFile file,
                  org.w3c.dom.Element element)
           throws java.io.IOException
Updates this property on the given resource using the information int the specified element. This default implementation does nothing, and returns HttpServletResponse.SC_CONFLICT.

Specified by:
update in interface Property
Parameters:
file - The resource that is to be updated.
element - The element containing the update information.
Returns:
An int containing the HTTP response code.
Throws:
java.io.IOException - If an IO error occurs while updating the property value.

equals

public boolean equals(java.lang.Object obj)
Description copied from interface: Property
Indicates whether an Object is equivalent to this Property object. Two properties are equal if they reside in the same namespace and have the same name (regardless of prefix equivalence).

Specified by:
equals in interface Property

hashCode

public int hashCode()
Description copied from interface: Property
Returns the hash code for this property. The hash code for a property object is defined as the hash code of the property's name XORed with the hash code of the property's namespace.

Specified by:
hashCode in interface Property

toString

public java.lang.String toString()

getServletConfig

protected javax.servlet.ServletConfig getServletConfig()
Returns the servlet configuration.

Returns:
A ServletConfig containing the servlet's configuration information.

getPrefix

protected java.lang.String getPrefix(org.w3c.dom.Document document,
                                     java.lang.String namespace)
Returns the prefix for the specified namespace URI in the given document, or null for the default namespace. If the namespace has not been mapped to a prefix in the document, an IllegalArgumentException is thrown.

Parameters:
document - The document whose assigned prefix for the given namespace URI is to be retrieved.
namespace - The namespace URI whose prefix in the document is to be retrieved.
Returns:
A String containing the prefix assigned to the given namespace URI in the specified document. If the given namespace URI is the default namespace for the document, this method returns null.
Throws:
java.lang.IllegalArgumentException - If the specified namespace URI has not been assigned a prefix in the given document.

getNamespace

protected java.lang.String getNamespace(org.w3c.dom.Document document,
                                        java.lang.String prefix)
Returns the namespace URI with the given assigned prefix in the specified document. Returns null if the prefix has not been assigned to a namespace.

Parameters:
document - The document from which the namespace is to be retrieved.
prefix - The prefix for which a namespace is to be retrieved. A value of null for this parameter will retrieve the default namespace of the document.
Returns:
A String containing the namespace URI to which the given prefix has been assigned in the specified document. If no such namespace exists, this method returns null.

addNamespace

protected void addNamespace(org.w3c.dom.Document document,
                            java.lang.String namespace,
                            java.lang.String prefix)
                     throws java.io.IOException
Assigns the given prefix to the specified namespace URI in the provided document.

Parameters:
document - The document in which the namespace assignment is to be made.
namespace - The namespace URI for which an assignment is being established.
prefix - The prefix to assign to the namespace URI.
Throws:
java.io.IOException - If the prefix has already been assigned to another namespace URI in the document.

retrieve

public abstract int retrieve(jcifs.smb.SmbFile file,
                             org.w3c.dom.Element element)
                      throws java.io.IOException
Description copied from interface: Property
Populates the provided Element with the current value of the property for the given resource.

Specified by:
retrieve in interface Property
Parameters:
file - The resource whose property value is to be retrieved.
element - The element which receives the value.
Returns:
An int containing the HTTP response code. For a successful retrieval, this will be HttpServletResponse.SC_OK.
Throws:
java.io.IOException - If an IO error occurs while retrieving the property value.


Copyright © 2004 Eric Glass