org.apache.jackrabbit.commons
Class AbstractSession

java.lang.Object
  extended by org.apache.jackrabbit.commons.AbstractSession
All Implemented Interfaces:
Session
Direct Known Subclasses:
SessionImpl, SessionImpl

public abstract class AbstractSession
extends Object
implements Session

Abstract base class for implementing the JCR Session interface.


Field Summary
 
Fields inherited from interface javax.jcr.Session
ACTION_ADD_NODE, ACTION_READ, ACTION_REMOVE, ACTION_SET_PROPERTY
 
Constructor Summary
AbstractSession()
           
 
Method Summary
 void exportDocumentView(String path, ContentHandler handler, boolean skipBinary, boolean noRecurse)
          Generates a document view export using a DocumentViewExporter instance.
 void exportDocumentView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
          Calls Session.exportDocumentView(String, ContentHandler, boolean, boolean) with the given arguments and a ContentHandler that serializes SAX events to the given output stream.
 void exportSystemView(String path, ContentHandler handler, boolean skipBinary, boolean noRecurse)
          Generates a system view export using a SystemViewExporter instance.
 void exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
          Calls Session.exportSystemView(String, ContentHandler, boolean, boolean) with the given arguments and a ContentHandler that serializes SAX events to the given output stream.
 Item getItem(String absPath)
          Returns the node or property at the given path.
 String getNamespacePrefix(String uri)
          Returns the namespace prefix mapped to the given URI.
 String[] getNamespacePrefixes()
          Returns the prefixes of all known namespace mappings.
 String getNamespaceURI(String prefix)
          Returns the namespace URI mapped to the given prefix.
 Node getNode(String absPath)
          Returns the node with the given absolute path.
 Property getProperty(String absPath)
          Returns the property with the given absolute path.
 Session impersonate(Credentials credentials)
          Logs in the same workspace with the given credentials.
 void importXML(String parentAbsPath, InputStream in, int uuidBehavior)
          Parses the given input stream as an XML document and processes the SAX events using the ContentHandler returned by Session.getImportContentHandler(String, int).
 boolean itemExists(String absPath)
          Calls getItem(String) with the given path and returns true if the call succeeds.
 void logout()
          Clears the local namespace mappings.
 boolean nodeExists(String absPath)
          Checks whether a node with the given absolute path exists.
 boolean propertyExists(String absPath)
          Checks whether a property with the given absolute path exists.
 void removeItem(String absPath)
          Removes the identified item.
 void setNamespacePrefix(String prefix, String uri)
          Modifies the session local namespace mappings to contain the given prefix to URI mapping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.jcr.Session
addLockToken, checkPermission, getAccessControlManager, getAttribute, getAttributeNames, getImportContentHandler, getLockTokens, getNodeByIdentifier, getNodeByUUID, getRepository, getRetentionManager, getRootNode, getUserID, getValueFactory, getWorkspace, hasCapability, hasPendingChanges, hasPermission, isLive, move, refresh, removeLockToken, save
 

Constructor Detail

AbstractSession

public AbstractSession()
Method Detail

logout

public void logout()
Clears the local namespace mappings. Subclasses that for example want to participate in a session pools should remember to call super.logout() when overriding this method to avoid namespace mappings to be carried over to a new session.

Specified by:
logout in interface Session

getNamespacePrefix

public String getNamespacePrefix(String uri)
                          throws NamespaceException,
                                 RepositoryException
Returns the namespace prefix mapped to the given URI. The mapping is added to the set of session-local namespace mappings unless it already exists there.

This behaviour is based on JSR 283 (JCR 2.0), but remains backwards compatible with JCR 1.0.

Specified by:
getNamespacePrefix in interface Session
Parameters:
uri - namespace URI
Returns:
namespace prefix
Throws:
NamespaceException - if the namespace is not found
RepositoryException - if a repository error occurs

getNamespaceURI

public String getNamespaceURI(String prefix)
                       throws NamespaceException,
                              RepositoryException
Returns the namespace URI mapped to the given prefix. The mapping is added to the set of session-local namespace mappings unless it already exists there.

This behaviour is based on JSR 283 (JCR 2.0), but remains backwards compatible with JCR 1.0.

Specified by:
getNamespaceURI in interface Session
Parameters:
prefix - namespace prefix
Returns:
namespace URI
Throws:
NamespaceException - if the namespace is not found
RepositoryException - if a repository error occurs

getNamespacePrefixes

public String[] getNamespacePrefixes()
                              throws RepositoryException
Returns the prefixes of all known namespace mappings. All global mappings not already included in the local set of namespace mappings are added there.

This behaviour is based on JSR 283 (JCR 2.0), but remains backwards compatible with JCR 1.0.

Specified by:
getNamespacePrefixes in interface Session
Returns:
namespace prefixes
Throws:
RepositoryException - if a repository error occurs

setNamespacePrefix

public void setNamespacePrefix(String prefix,
                               String uri)
                        throws NamespaceException,
                               RepositoryException
Modifies the session local namespace mappings to contain the given prefix to URI mapping.

This behaviour is based on JSR 283 (JCR 2.0), but remains backwards compatible with JCR 1.0.

Specified by:
setNamespacePrefix in interface Session
Parameters:
prefix - namespace prefix
uri - namespace URI
Throws:
NamespaceException - if the mapping is illegal
RepositoryException - if a repository error occurs

exportDocumentView

public void exportDocumentView(String path,
                               ContentHandler handler,
                               boolean skipBinary,
                               boolean noRecurse)
                        throws PathNotFoundException,
                               SAXException,
                               RepositoryException
Generates a document view export using a DocumentViewExporter instance.

Specified by:
exportDocumentView in interface Session
Parameters:
path - of the node to be exported
handler - handler for the SAX events of the export
skipBinary - whether binary values should be skipped
noRecurse - whether to export just the identified node
Throws:
PathNotFoundException - if a node at the given path does not exist
SAXException - if the SAX event handler failed
RepositoryException - if another error occurs

exportSystemView

public void exportSystemView(String path,
                             ContentHandler handler,
                             boolean skipBinary,
                             boolean noRecurse)
                      throws PathNotFoundException,
                             SAXException,
                             RepositoryException
Generates a system view export using a SystemViewExporter instance.

Specified by:
exportSystemView in interface Session
Parameters:
path - of the node to be exported
handler - handler for the SAX events of the export
skipBinary - whether binary values should be skipped
noRecurse - whether to export just the identified node
Throws:
PathNotFoundException - if a node at the given path does not exist
SAXException - if the SAX event handler failed
RepositoryException - if another error occurs

exportDocumentView

public void exportDocumentView(String absPath,
                               OutputStream out,
                               boolean skipBinary,
                               boolean noRecurse)
                        throws IOException,
                               RepositoryException
Calls Session.exportDocumentView(String, ContentHandler, boolean, boolean) with the given arguments and a ContentHandler that serializes SAX events to the given output stream.

Specified by:
exportDocumentView in interface Session
Parameters:
absPath - passed through
out - output stream to which the SAX events are serialized
skipBinary - passed through
noRecurse - passed through
Throws:
IOException - if the SAX serialization failed
RepositoryException - if another error occurs

exportSystemView

public void exportSystemView(String absPath,
                             OutputStream out,
                             boolean skipBinary,
                             boolean noRecurse)
                      throws IOException,
                             RepositoryException
Calls Session.exportSystemView(String, ContentHandler, boolean, boolean) with the given arguments and a ContentHandler that serializes SAX events to the given output stream.

Specified by:
exportSystemView in interface Session
Parameters:
absPath - passed through
out - output stream to which the SAX events are serialized
skipBinary - passed through
noRecurse - passed through
Throws:
IOException - if the SAX serialization failed
RepositoryException - if another error occurs

importXML

public void importXML(String parentAbsPath,
                      InputStream in,
                      int uuidBehavior)
               throws IOException,
                      InvalidSerializedDataException,
                      RepositoryException
Parses the given input stream as an XML document and processes the SAX events using the ContentHandler returned by Session.getImportContentHandler(String, int).

Specified by:
importXML in interface Session
Parameters:
parentAbsPath - passed through
in - input stream to be parsed as XML and imported
uuidBehavior - passed through
Throws:
IOException - if an I/O error occurs
InvalidSerializedDataException - if an XML parsing error occurs
RepositoryException - if a repository error occurs

getItem

public Item getItem(String absPath)
             throws PathNotFoundException,
                    RepositoryException
Returns the node or property at the given path.

The default implementation:

Specified by:
getItem in interface Session
Parameters:
absPath - absolute path
Returns:
the node or property with the given path
Throws:
PathNotFoundException - if the given path is invalid or not found
RepositoryException - if another error occurs
See Also:
Session.getItem(String)

itemExists

public boolean itemExists(String absPath)
                   throws RepositoryException
Calls getItem(String) with the given path and returns true if the call succeeds. Returns false if a PathNotFoundException was thrown. Other exceptions are passed through.

Specified by:
itemExists in interface Session
Parameters:
absPath - absolute path
Returns:
true if an item exists at the given path, false otherwise
Throws:
RepositoryException - if an error occurs
See Also:
Session.itemExists(String)

removeItem

public void removeItem(String absPath)
                throws RepositoryException
Removes the identified item. Implemented by calling Item.remove() on the item removed by getItem(String).

Specified by:
removeItem in interface Session
Parameters:
absPath - An absolute path of the item to be removed
Throws:
RepositoryException - if the item can not be removed
See Also:
Session.removeItem(String)

getNode

public Node getNode(String absPath)
             throws RepositoryException
Returns the node with the given absolute path.

Specified by:
getNode in interface Session
Parameters:
absPath - absolute path
Returns:
node at the given path
Throws:
RepositoryException - if the node can not be accessed
See Also:
Session.getNode(String)

nodeExists

public boolean nodeExists(String absPath)
                   throws RepositoryException
Checks whether a node with the given absolute path exists.

Specified by:
nodeExists in interface Session
Parameters:
absPath - absolute path
Returns:
true if a node with the given path exists, false otherwise
Throws:
RepositoryException - if the path is invalid
See Also:
Session.nodeExists(String)

getProperty

public Property getProperty(String absPath)
                     throws RepositoryException
Returns the property with the given absolute path.

Specified by:
getProperty in interface Session
Parameters:
absPath - absolute path
Returns:
node at the given path
Throws:
RepositoryException - if the property can not be accessed
See Also:
Session.getProperty(String)

propertyExists

public boolean propertyExists(String absPath)
                       throws RepositoryException
Checks whether a property with the given absolute path exists.

Specified by:
propertyExists in interface Session
Parameters:
absPath - absolute path
Returns:
true if a property with the given path exists, false otherwise
Throws:
RepositoryException - if the path is invalid
See Also:
Session.propertyExists(String)

impersonate

public Session impersonate(Credentials credentials)
                    throws RepositoryException
Logs in the same workspace with the given credentials.

The default implementation:

Specified by:
impersonate in interface Session
Parameters:
credentials - login credentials
Returns:
logged in session
Throws:
RepositoryException - if an error occurs


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.