org.priha.core
Class SessionImpl

java.lang.Object
  extended by org.priha.core.SessionImpl
All Implemented Interfaces:
NamespaceMapper

public class SessionImpl
extends java.lang.Object
implements 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, 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()
           
 java.lang.String getId()
           
 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()
           
 Session impersonate(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,
                   Credentials creds,
                   java.lang.String name)
            throws RepositoryException
Throws:
RepositoryException
Method Detail

getId

public java.lang.String getId()

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 RepositoryException
Throws:
RepositoryException

hasNode

public boolean hasNode(Path absPath)
                throws RepositoryException
Throws:
RepositoryException

addLockToken

public void addLockToken(java.lang.String lt)

checkPermission

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

Throws:
java.security.AccessControlException
RepositoryException

checkWritePermission

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

Throws:
java.security.AccessControlException
RepositoryException

getAttribute

public java.lang.Object getAttribute(java.lang.String name)

getAttributeNames

public java.lang.String[] getAttributeNames()

getItem

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

getItem

public ItemImpl getItem(java.lang.String absPath)
                 throws PathNotFoundException,
                        RepositoryException
Throws:
PathNotFoundException
RepositoryException

getLockTokens

public java.lang.String[] getLockTokens()

getNodeByUUID

public NodeImpl getNodeByUUID(java.lang.String uuid)
                       throws ItemNotFoundException,
                              RepositoryException
Throws:
ItemNotFoundException
RepositoryException

getRepository

public RepositoryImpl getRepository()

getRootNode

public NodeImpl getRootNode()
                     throws RepositoryException
Throws:
RepositoryException

getUserID

public java.lang.String getUserID()

getValueFactory

public ValueFactoryImpl getValueFactory()
                                 throws UnsupportedRepositoryOperationException,
                                        RepositoryException
Throws:
UnsupportedRepositoryOperationException
RepositoryException

getWorkspace

public WorkspaceImpl getWorkspace()

hasPendingChanges

public boolean hasPendingChanges()
                          throws RepositoryException
Throws:
RepositoryException

impersonate

public Session impersonate(Credentials credentials)
                    throws LoginException,
                           RepositoryException
Throws:
LoginException
RepositoryException

isLive

public final boolean isLive()

itemExists

public boolean itemExists(java.lang.String absPath)
                   throws RepositoryException
Throws:
RepositoryException

logout

public void logout()

move

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

Throws:
ItemExistsException
PathNotFoundException
VersionException
ConstraintViolationException
LockException
NamespaceException
RepositoryException

move

public void move(java.lang.String srcAbsPath,
                 java.lang.String destAbsPath)
          throws ItemExistsException,
                 PathNotFoundException,
                 VersionException,
                 ConstraintViolationException,
                 LockException,
                 RepositoryException
Throws:
ItemExistsException
PathNotFoundException
VersionException
ConstraintViolationException
LockException
RepositoryException

internalMove

public void internalMove(Path srcPath,
                         Path destPath,
                         boolean obeyConstraints)
                  throws ItemExistsException,
                         PathNotFoundException,
                         VersionException,
                         ConstraintViolationException,
                         LockException,
                         NamespaceException,
                         RepositoryException
Throws:
ItemExistsException
PathNotFoundException
VersionException
ConstraintViolationException
LockException
NamespaceException
RepositoryException

internalMove

public void internalMove(java.lang.String srcAbsPath,
                         java.lang.String destAbsPath,
                         boolean obeyConstraints)
                  throws ItemExistsException,
                         PathNotFoundException,
                         VersionException,
                         ConstraintViolationException,
                         LockException,
                         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:
ItemExistsException
PathNotFoundException
VersionException
ConstraintViolationException
LockException
RepositoryException

refresh

public void refresh(boolean keepChanges)
             throws RepositoryException
Throws:
RepositoryException

removeLockToken

public void removeLockToken(java.lang.String lt)

save

public void save()
          throws AccessDeniedException,
                 ItemExistsException,
                 ConstraintViolationException,
                 InvalidItemStateException,
                 VersionException,
                 LockException,
                 NoSuchNodeTypeException,
                 RepositoryException
Throws:
AccessDeniedException
ItemExistsException
ConstraintViolationException
InvalidItemStateException
VersionException
LockException
NoSuchNodeTypeException
RepositoryException

saveNodes

protected void saveNodes(Path pathprefix)
                  throws 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:
RepositoryException

itemExists

public boolean itemExists(Path absPath)
                   throws RepositoryException
Throws:
RepositoryException

remove

public void remove(ItemImpl itemImpl)
            throws RepositoryException
Throws:
RepositoryException

getReferences

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

importXML

public void importXML(java.lang.String parentAbsPath,
                      java.io.InputStream in,
                      int uuidBehavior)
               throws java.io.IOException,
                      PathNotFoundException,
                      ItemExistsException,
                      ConstraintViolationException,
                      VersionException,
                      InvalidSerializedDataException,
                      LockException,
                      RepositoryException
Throws:
java.io.IOException
PathNotFoundException
ItemExistsException
ConstraintViolationException
VersionException
InvalidSerializedDataException
LockException
RepositoryException

getImportContentHandler

public org.xml.sax.ContentHandler getImportContentHandler(java.lang.String parentAbsPath,
                                                          int uuidBehavior)
                                                   throws PathNotFoundException,
                                                          ConstraintViolationException,
                                                          VersionException,
                                                          LockException,
                                                          RepositoryException
Throws:
PathNotFoundException
ConstraintViolationException
VersionException
LockException
RepositoryException

exportDocumentView

public void exportDocumentView(java.lang.String absPath,
                               org.xml.sax.ContentHandler contentHandler,
                               boolean skipBinary,
                               boolean noRecurse)
                        throws PathNotFoundException,
                               org.xml.sax.SAXException,
                               RepositoryException
Throws:
PathNotFoundException
org.xml.sax.SAXException
RepositoryException

exportDocumentView

public void exportDocumentView(java.lang.String absPath,
                               java.io.OutputStream out,
                               boolean skipBinary,
                               boolean noRecurse)
                        throws java.io.IOException,
                               PathNotFoundException,
                               RepositoryException
Throws:
java.io.IOException
PathNotFoundException
RepositoryException

exportSystemView

public void exportSystemView(java.lang.String absPath,
                             org.xml.sax.ContentHandler contentHandler,
                             boolean skipBinary,
                             boolean noRecurse)
                      throws PathNotFoundException,
                             org.xml.sax.SAXException,
                             RepositoryException
Throws:
PathNotFoundException
org.xml.sax.SAXException
RepositoryException

exportSystemView

public void exportSystemView(java.lang.String absPath,
                             java.io.OutputStream out,
                             boolean skipBinary,
                             boolean noRecurse)
                      throws java.io.IOException,
                             PathNotFoundException,
                             RepositoryException
Throws:
java.io.IOException
PathNotFoundException
RepositoryException

setNamespacePrefix

public void setNamespacePrefix(java.lang.String newPrefix,
                               java.lang.String existingUri)
                        throws NamespaceException,
                               RepositoryException
Throws:
NamespaceException
RepositoryException

getNamespacePrefix

public java.lang.String getNamespacePrefix(java.lang.String uri)
                                    throws NamespaceException,
                                           RepositoryException
Throws:
NamespaceException
RepositoryException

getNamespacePrefixes

public java.lang.String[] getNamespacePrefixes()
                                        throws RepositoryException
Throws:
RepositoryException

getNamespaceURI

public java.lang.String getNamespaceURI(java.lang.String prefix)
                                 throws NamespaceException,
                                        RepositoryException
Throws:
NamespaceException
RepositoryException

fromQName

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

toQName

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

createNode

protected NodeImpl createNode(Path absPath,
                              QNodeType assignedType,
                              QNodeDefinition assignedNodeDef,
                              boolean initDefaults)
                       throws 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:
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 PathNotFoundException
Shortcut for getPathManager().getPath().

Parameters:
p -
Returns:
Throws:
PathNotFoundException

getPathManager

public PathManager getPathManager()

rename

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