org.priha.core
Class SessionImpl

java.lang.Object
  extended by org.priha.core.SessionImpl
All Implemented Interfaces:
javax.jcr.Session, NamespaceMapper

public class SessionImpl
extends java.lang.Object
implements javax.jcr.Session, NamespaceMapper

The SessionImpl class implements a JCR Session. It is non thread safe, so each Thread must have its own Session.


Field Summary
protected  SessionProvider m_provider
           
 
Constructor Summary
SessionImpl(RepositoryImpl rep, javax.jcr.Credentials creds, java.lang.String name)
           
 
Method Summary
 void addLockToken(java.lang.String lt)
           
 void checkPermission(java.lang.String absPath, java.lang.String actions)
          Any credentials are fine to give full access.
protected  void checkWritePermission()
          Quick way to check for write permissions.
protected  NodeImpl createNode(Path absPath, QNodeType assignedType, QNodeDefinition assignedNodeDef, boolean initDefaults)
          This method creates a correct Node subclass based on the NodeType.
 void dump()
          This method provides debug information about the state of the Session.
 void exportDocumentView(java.lang.String absPath, org.xml.sax.ContentHandler contentHandler, boolean skipBinary, boolean noRecurse)
           
 void exportDocumentView(java.lang.String absPath, java.io.OutputStream out, boolean skipBinary, boolean noRecurse)
           
 void exportSystemView(java.lang.String absPath, org.xml.sax.ContentHandler contentHandler, boolean skipBinary, boolean noRecurse)
           
 void exportSystemView(java.lang.String absPath, java.io.OutputStream out, boolean skipBinary, boolean noRecurse)
           
 java.lang.String fromQName(QName c)
           
 java.lang.Object getAttribute(java.lang.String name)
           
 java.lang.String[] getAttributeNames()
           
 org.xml.sax.ContentHandler getImportContentHandler(java.lang.String parentAbsPath, int uuidBehavior)
           
 ItemImpl getItem(Path absPath)
           
 ItemImpl getItem(java.lang.String absPath)
           
 java.lang.String[] getLockTokens()
           
 java.lang.String getNamespacePrefix(java.lang.String uri)
           
 java.lang.String[] getNamespacePrefixes()
           
 java.lang.String getNamespaceURI(java.lang.String prefix)
           
 NodeImpl getNodeByUUID(java.lang.String uuid)
           
 Path getPath(PathRef p)
          Shortcut for getPathManager().getPath().
 PathManager getPathManager()
           
 java.util.List<PropertyImpl> getReferences(java.lang.String uuid)
           
 RepositoryImpl getRepository()
           
 NodeImpl getRootNode()
           
 java.lang.String getUserID()
           
 ValueFactoryImpl getValueFactory()
           
 WorkspaceImpl getWorkspace()
           
 boolean hasNode(Path absPath)
           
 boolean hasPendingChanges()
           
 javax.jcr.Session impersonate(javax.jcr.Credentials credentials)
           
 void importXML(java.lang.String parentAbsPath, java.io.InputStream in, int uuidBehavior)
           
 void internalMove(Path srcPath, Path destPath, boolean obeyConstraints)
           
 void internalMove(java.lang.String srcAbsPath, java.lang.String destAbsPath, boolean obeyConstraints)
          Moves work as follows: We add a new Node to the destAbsPath We copy all properties from the old Node to the new Node The old Node gets tagged with a property "priha:oldPath" which contains the current path The Path of the old Node (and all other Nodes which refer to it) is changed to point at the new location The Node is marked as being MOVED instead of REMOVED.
 boolean isLive()
           
 boolean isSuper()
          Returns true, if this Session should be considered to be a supersession, which can do whatever it wants (that is, mostly ignore any Constraint Violations.
 boolean itemExists(Path absPath)
           
 boolean itemExists(java.lang.String absPath)
           
 java.util.List<Path> listNodes(Path parentpath)
           
 void logout()
           
 void move(Path srcPath, Path destPath)
          A convenience class to move stuff based on Paths instead of Strings.
 void move(java.lang.String srcAbsPath, java.lang.String destAbsPath)
           
 void refresh(boolean keepChanges)
           
 void remove(ItemImpl itemImpl)
           
 void removeLockToken(java.lang.String lt)
           
 void rename(Path path1, Path.Component newName)
           
 void save()
           
protected  void saveNodes(Path pathprefix)
          Saves all modified nodes that start with the given path prefix.
 void setNamespacePrefix(java.lang.String newPrefix, java.lang.String existingUri)
           
 boolean setSuper(boolean value)
           
 QName toQName(java.lang.String c)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_provider

protected SessionProvider m_provider
Constructor Detail

SessionImpl

public SessionImpl(RepositoryImpl rep,
                   javax.jcr.Credentials creds,
                   java.lang.String name)
            throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException
Method Detail

setSuper

public boolean setSuper(boolean value)

isSuper

public boolean isSuper()
Returns true, if this Session should be considered to be a supersession, which can do whatever it wants (that is, mostly ignore any Constraint Violations.

One should be careful, since it is possible with this method to end up in a repository with an inconsistent state.

Returns:

listNodes

public java.util.List<Path> listNodes(Path parentpath)
                               throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

hasNode

public boolean hasNode(Path absPath)
                throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

addLockToken

public void addLockToken(java.lang.String lt)
Specified by:
addLockToken in interface javax.jcr.Session

checkPermission

public void checkPermission(java.lang.String absPath,
                            java.lang.String actions)
                     throws java.security.AccessControlException,
                            javax.jcr.RepositoryException
Any credentials are fine to give full access.

Specified by:
checkPermission in interface javax.jcr.Session
Throws:
java.security.AccessControlException
javax.jcr.RepositoryException

checkWritePermission

protected void checkWritePermission()
                             throws java.security.AccessControlException,
                                    javax.jcr.RepositoryException
Quick way to check for write permissions.

Throws:
java.security.AccessControlException
javax.jcr.RepositoryException

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Specified by:
getAttribute in interface javax.jcr.Session

getAttributeNames

public java.lang.String[] getAttributeNames()
Specified by:
getAttributeNames in interface javax.jcr.Session

getItem

public ItemImpl getItem(Path absPath)
                 throws javax.jcr.PathNotFoundException,
                        javax.jcr.RepositoryException
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

getItem

public ItemImpl getItem(java.lang.String absPath)
                 throws javax.jcr.PathNotFoundException,
                        javax.jcr.RepositoryException
Specified by:
getItem in interface javax.jcr.Session
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

getLockTokens

public java.lang.String[] getLockTokens()
Specified by:
getLockTokens in interface javax.jcr.Session

getNodeByUUID

public NodeImpl getNodeByUUID(java.lang.String uuid)
                       throws javax.jcr.ItemNotFoundException,
                              javax.jcr.RepositoryException
Specified by:
getNodeByUUID in interface javax.jcr.Session
Throws:
javax.jcr.ItemNotFoundException
javax.jcr.RepositoryException

getRepository

public RepositoryImpl getRepository()
Specified by:
getRepository in interface javax.jcr.Session

getRootNode

public NodeImpl getRootNode()
                     throws javax.jcr.RepositoryException
Specified by:
getRootNode in interface javax.jcr.Session
Throws:
javax.jcr.RepositoryException

getUserID

public java.lang.String getUserID()
Specified by:
getUserID in interface javax.jcr.Session

getValueFactory

public ValueFactoryImpl getValueFactory()
                                 throws javax.jcr.UnsupportedRepositoryOperationException,
                                        javax.jcr.RepositoryException
Specified by:
getValueFactory in interface javax.jcr.Session
Throws:
javax.jcr.UnsupportedRepositoryOperationException
javax.jcr.RepositoryException

getWorkspace

public WorkspaceImpl getWorkspace()
Specified by:
getWorkspace in interface javax.jcr.Session

hasPendingChanges

public boolean hasPendingChanges()
                          throws javax.jcr.RepositoryException
Specified by:
hasPendingChanges in interface javax.jcr.Session
Throws:
javax.jcr.RepositoryException

impersonate

public javax.jcr.Session impersonate(javax.jcr.Credentials credentials)
                              throws javax.jcr.LoginException,
                                     javax.jcr.RepositoryException
Specified by:
impersonate in interface javax.jcr.Session
Throws:
javax.jcr.LoginException
javax.jcr.RepositoryException

isLive

public final boolean isLive()
Specified by:
isLive in interface javax.jcr.Session

itemExists

public boolean itemExists(java.lang.String absPath)
                   throws javax.jcr.RepositoryException
Specified by:
itemExists in interface javax.jcr.Session
Throws:
javax.jcr.RepositoryException

logout

public void logout()
Specified by:
logout in interface javax.jcr.Session

move

public void move(Path srcPath,
                 Path destPath)
          throws javax.jcr.ItemExistsException,
                 javax.jcr.PathNotFoundException,
                 javax.jcr.version.VersionException,
                 javax.jcr.nodetype.ConstraintViolationException,
                 javax.jcr.lock.LockException,
                 javax.jcr.NamespaceException,
                 javax.jcr.RepositoryException
A convenience class to move stuff based on Paths instead of Strings.

Throws:
javax.jcr.ItemExistsException
javax.jcr.PathNotFoundException
javax.jcr.version.VersionException
javax.jcr.nodetype.ConstraintViolationException
javax.jcr.lock.LockException
javax.jcr.NamespaceException
javax.jcr.RepositoryException

move

public void move(java.lang.String srcAbsPath,
                 java.lang.String destAbsPath)
          throws javax.jcr.ItemExistsException,
                 javax.jcr.PathNotFoundException,
                 javax.jcr.version.VersionException,
                 javax.jcr.nodetype.ConstraintViolationException,
                 javax.jcr.lock.LockException,
                 javax.jcr.RepositoryException
Specified by:
move in interface javax.jcr.Session
Throws:
javax.jcr.ItemExistsException
javax.jcr.PathNotFoundException
javax.jcr.version.VersionException
javax.jcr.nodetype.ConstraintViolationException
javax.jcr.lock.LockException
javax.jcr.RepositoryException

internalMove

public void internalMove(Path srcPath,
                         Path destPath,
                         boolean obeyConstraints)
                  throws javax.jcr.ItemExistsException,
                         javax.jcr.PathNotFoundException,
                         javax.jcr.version.VersionException,
                         javax.jcr.nodetype.ConstraintViolationException,
                         javax.jcr.lock.LockException,
                         javax.jcr.NamespaceException,
                         javax.jcr.RepositoryException
Throws:
javax.jcr.ItemExistsException
javax.jcr.PathNotFoundException
javax.jcr.version.VersionException
javax.jcr.nodetype.ConstraintViolationException
javax.jcr.lock.LockException
javax.jcr.NamespaceException
javax.jcr.RepositoryException

internalMove

public void internalMove(java.lang.String srcAbsPath,
                         java.lang.String destAbsPath,
                         boolean obeyConstraints)
                  throws javax.jcr.ItemExistsException,
                         javax.jcr.PathNotFoundException,
                         javax.jcr.version.VersionException,
                         javax.jcr.nodetype.ConstraintViolationException,
                         javax.jcr.lock.LockException,
                         javax.jcr.RepositoryException
Moves work as follows:
  1. We add a new Node to the destAbsPath
  2. We copy all properties from the old Node to the new Node
  3. The old Node gets tagged with a property "priha:oldPath" which contains the current path
  4. The Path of the old Node (and all other Nodes which refer to it) is changed to point at the new location
  5. The Node is marked as being MOVED instead of REMOVED.

Throws:
javax.jcr.ItemExistsException
javax.jcr.PathNotFoundException
javax.jcr.version.VersionException
javax.jcr.nodetype.ConstraintViolationException
javax.jcr.lock.LockException
javax.jcr.RepositoryException

refresh

public void refresh(boolean keepChanges)
             throws javax.jcr.RepositoryException
Specified by:
refresh in interface javax.jcr.Session
Throws:
javax.jcr.RepositoryException

removeLockToken

public void removeLockToken(java.lang.String lt)
Specified by:
removeLockToken in interface javax.jcr.Session

save

public void save()
          throws javax.jcr.AccessDeniedException,
                 javax.jcr.ItemExistsException,
                 javax.jcr.nodetype.ConstraintViolationException,
                 javax.jcr.InvalidItemStateException,
                 javax.jcr.version.VersionException,
                 javax.jcr.lock.LockException,
                 javax.jcr.nodetype.NoSuchNodeTypeException,
                 javax.jcr.RepositoryException
Specified by:
save in interface javax.jcr.Session
Throws:
javax.jcr.AccessDeniedException
javax.jcr.ItemExistsException
javax.jcr.nodetype.ConstraintViolationException
javax.jcr.InvalidItemStateException
javax.jcr.version.VersionException
javax.jcr.lock.LockException
javax.jcr.nodetype.NoSuchNodeTypeException
javax.jcr.RepositoryException

saveNodes

protected void saveNodes(Path pathprefix)
                  throws javax.jcr.RepositoryException
Saves all modified nodes that start with the given path prefix. This can be used to save a node and all its children.

Parameters:
pathprefix -
Throws:
javax.jcr.RepositoryException

itemExists

public boolean itemExists(Path absPath)
                   throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

remove

public void remove(ItemImpl itemImpl)
            throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getReferences

public java.util.List<PropertyImpl> getReferences(java.lang.String uuid)
                                           throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

importXML

public void importXML(java.lang.String parentAbsPath,
                      java.io.InputStream in,
                      int uuidBehavior)
               throws java.io.IOException,
                      javax.jcr.PathNotFoundException,
                      javax.jcr.ItemExistsException,
                      javax.jcr.nodetype.ConstraintViolationException,
                      javax.jcr.version.VersionException,
                      javax.jcr.InvalidSerializedDataException,
                      javax.jcr.lock.LockException,
                      javax.jcr.RepositoryException
Specified by:
importXML in interface javax.jcr.Session
Throws:
java.io.IOException
javax.jcr.PathNotFoundException
javax.jcr.ItemExistsException
javax.jcr.nodetype.ConstraintViolationException
javax.jcr.version.VersionException
javax.jcr.InvalidSerializedDataException
javax.jcr.lock.LockException
javax.jcr.RepositoryException

getImportContentHandler

public org.xml.sax.ContentHandler getImportContentHandler(java.lang.String parentAbsPath,
                                                          int uuidBehavior)
                                                   throws javax.jcr.PathNotFoundException,
                                                          javax.jcr.nodetype.ConstraintViolationException,
                                                          javax.jcr.version.VersionException,
                                                          javax.jcr.lock.LockException,
                                                          javax.jcr.RepositoryException
Specified by:
getImportContentHandler in interface javax.jcr.Session
Throws:
javax.jcr.PathNotFoundException
javax.jcr.nodetype.ConstraintViolationException
javax.jcr.version.VersionException
javax.jcr.lock.LockException
javax.jcr.RepositoryException

exportDocumentView

public void exportDocumentView(java.lang.String absPath,
                               org.xml.sax.ContentHandler contentHandler,
                               boolean skipBinary,
                               boolean noRecurse)
                        throws javax.jcr.PathNotFoundException,
                               org.xml.sax.SAXException,
                               javax.jcr.RepositoryException
Specified by:
exportDocumentView in interface javax.jcr.Session
Throws:
javax.jcr.PathNotFoundException
org.xml.sax.SAXException
javax.jcr.RepositoryException

exportDocumentView

public void exportDocumentView(java.lang.String absPath,
                               java.io.OutputStream out,
                               boolean skipBinary,
                               boolean noRecurse)
                        throws java.io.IOException,
                               javax.jcr.PathNotFoundException,
                               javax.jcr.RepositoryException
Specified by:
exportDocumentView in interface javax.jcr.Session
Throws:
java.io.IOException
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

exportSystemView

public void exportSystemView(java.lang.String absPath,
                             org.xml.sax.ContentHandler contentHandler,
                             boolean skipBinary,
                             boolean noRecurse)
                      throws javax.jcr.PathNotFoundException,
                             org.xml.sax.SAXException,
                             javax.jcr.RepositoryException
Specified by:
exportSystemView in interface javax.jcr.Session
Throws:
javax.jcr.PathNotFoundException
org.xml.sax.SAXException
javax.jcr.RepositoryException

exportSystemView

public void exportSystemView(java.lang.String absPath,
                             java.io.OutputStream out,
                             boolean skipBinary,
                             boolean noRecurse)
                      throws java.io.IOException,
                             javax.jcr.PathNotFoundException,
                             javax.jcr.RepositoryException
Specified by:
exportSystemView in interface javax.jcr.Session
Throws:
java.io.IOException
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

setNamespacePrefix

public void setNamespacePrefix(java.lang.String newPrefix,
                               java.lang.String existingUri)
                        throws javax.jcr.NamespaceException,
                               javax.jcr.RepositoryException
Specified by:
setNamespacePrefix in interface javax.jcr.Session
Throws:
javax.jcr.NamespaceException
javax.jcr.RepositoryException

getNamespacePrefix

public java.lang.String getNamespacePrefix(java.lang.String uri)
                                    throws javax.jcr.NamespaceException,
                                           javax.jcr.RepositoryException
Specified by:
getNamespacePrefix in interface javax.jcr.Session
Throws:
javax.jcr.NamespaceException
javax.jcr.RepositoryException

getNamespacePrefixes

public java.lang.String[] getNamespacePrefixes()
                                        throws javax.jcr.RepositoryException
Specified by:
getNamespacePrefixes in interface javax.jcr.Session
Throws:
javax.jcr.RepositoryException

getNamespaceURI

public java.lang.String getNamespaceURI(java.lang.String prefix)
                                 throws javax.jcr.NamespaceException,
                                        javax.jcr.RepositoryException
Specified by:
getNamespaceURI in interface javax.jcr.Session
Throws:
javax.jcr.NamespaceException
javax.jcr.RepositoryException

fromQName

public java.lang.String fromQName(QName c)
Specified by:
fromQName in interface NamespaceMapper

toQName

public QName toQName(java.lang.String c)
              throws javax.jcr.NamespaceException,
                     javax.jcr.RepositoryException
Specified by:
toQName in interface NamespaceMapper
Throws:
javax.jcr.NamespaceException
javax.jcr.RepositoryException

createNode

protected NodeImpl createNode(Path absPath,
                              QNodeType assignedType,
                              QNodeDefinition assignedNodeDef,
                              boolean initDefaults)
                       throws javax.jcr.RepositoryException
This method creates a correct Node subclass based on the NodeType. It can return Version or VersionHistory objects, as well as regular Nodes.

Parameters:
absPath -
assignedType -
assignedNodeDef -
Returns:
Throws:
javax.jcr.RepositoryException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

dump

public void dump()
This method provides debug information about the state of the Session. Do not rely it giving it in any particular format. The dump will be done to the System.out stream.


getPath

public Path getPath(PathRef p)
             throws javax.jcr.PathNotFoundException
Shortcut for getPathManager().getPath().

Parameters:
p -
Returns:
Throws:
javax.jcr.PathNotFoundException

getPathManager

public PathManager getPathManager()

rename

public void rename(Path path1,
                   Path.Component newName)