org.modeshape.jcr

## Class JcrSession

- java.lang.Object
- - org.modeshape.jcr.JcrSession

- All Implemented Interfaces:
    Session
  Direct Known Subclasses:
    JcrXaSession

      public class JcrSession
      extends Object
      implements Session

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `JcrSession.JcrPreSave` Define the operations that are to be performed on all the nodes that were created or modified within this session.
    `protected class` | `JcrSession.SystemSessionCache`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected JcrRepository` | `repository`

    - ### Fields inherited from interface javax.jcr.Session

      `ACTION_ADD_NODE, ACTION_READ, ACTION_REMOVE, ACTION_SET_PROPERTY`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `JcrSession(JcrRepository repository, String workspaceName, ExecutionContext context, Map<String,Object> sessionAttributes, boolean readOnly)`
    `protected` | `JcrSession(JcrSession original, boolean readOnly)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected long` | `aclAdded()`
    `protected long` | `aclChangesCount()`
    `protected long` | `aclRemoved()`
    `void` | `addLockToken(String lockToken)`
    `void` | `checkPermission(String path, String actions)`
    `static NodeKey` | `createNodeKeyFromIdentifier(String identifier, NodeKey rootKey)` Determine if the supplied string represents just the `node's identifier` or whether it is a string representation of a NodeKey.
    `String` | `decode(String localName)` Evaluate a local name and replace any characters that were previously `encoded`.
    `String` | `encode(String localName)` Evaluate a local name and replace any characters that are not allowed within the local names of nodes and properties.
    `protected SchematicEntry` | `entryForNode(NodeKey nodeKey)`
    `void` | `exportDocumentView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse)`
    `void` | `exportDocumentView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)`
    `void` | `exportSystemView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse)`
    `void` | `exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)`
    `AccessControlManager` | `getAccessControlManager()`
    `Object` | `getAttribute(String name)`
    `String[]` | `getAttributeNames()`
    `ContentHandler` | `getImportContentHandler(String parentAbsPath, int uuidBehavior)`
    `org.modeshape.jcr.AbstractJcrItem` | `getItem(String absPath)`
    `String[]` | `getLockTokens()`
    `String` | `getNamespacePrefix(String uri)`
    `String[]` | `getNamespacePrefixes()`
    `String` | `getNamespaceURI(String prefix)`
    `org.modeshape.jcr.AbstractJcrNode` | `getNode(String absPath)`
    `protected org.modeshape.jcr.AbstractJcrNode` | `getNode(String absPath, boolean accessControlScope)`
    `org.modeshape.jcr.AbstractJcrNode` | `getNodeByIdentifier(String id)`
    `org.modeshape.jcr.AbstractJcrNode` | `getNodeByUUID(String uuid)` Deprecated.
    `org.modeshape.jcr.AbstractJcrNode` | `getNonSystemNodeByIdentifier(String id)` A variant of the standard `getNodeByIdentifier(String)` method that does not find nodes within the system area.
    `Property` | `getProperty(String absPath)`
    `JcrRepository` | `getRepository()`
    `RetentionManager` | `getRetentionManager()`
    `org.modeshape.jcr.JcrRootNode` | `getRootNode()`
    `String` | `getUserID()`
    `JcrValueFactory` | `getValueFactory()`
    `org.modeshape.jcr.JcrWorkspace` | `getWorkspace()`
    `boolean` | `hasCapability(String methodName, Object target, Object[] arguments)` Makes a "best effort" determination of whether the given method can be successfully called on the given target with the given arguments.
    `boolean` | `hasPendingChanges()`
    `boolean` | `hasPermission(String absPath, String actions)`
    `Session` | `impersonate(Credentials credentials)`
    `void` | `importXML(String parentAbsPath, InputStream in, int uuidBehavior)`
    `protected void` | `initBaseVersionKeys()`
    `protected void` | `initOriginalVersionKeys()`
    `boolean` | `isAnonymous()`
    `protected boolean` | `isForeignKey(NodeKey key)` Checks if the node given key is foreign by comparing the source key & workspace key against the same keys from this session's root.
    `static boolean` | `isForeignKey(NodeKey key, NodeKey rootKey)` Checks if the node given key is foreign by comparing the source key & workspace key against the same keys from this session's root.
    `boolean` | `isLive()`
    `boolean` | `isReadOnly()`
    `boolean` | `itemExists(String absPath)`
    `void` | `logout()`
    `void` | `move(String srcAbsPath, String destAbsPath)`
    `protected boolean` | `nodeExists(NodeKey key)` Utility method to determine if the node with the specified key still exists within the transient & persisted state.
    `boolean` | `nodeExists(String absPath)`
    `protected String` | `nodeIdentifier(NodeKey key)` Returns a string representing a node's identifier, based on whether the node is foreign or not.
    `static String` | `nodeIdentifier(NodeKey key, NodeKey rootKey)` Returns a string representing a node's identifier, based on whether the node is foreign or not.
    `boolean` | `propertyExists(String absPath)`
    `protected String` | `readable(Path path)`
    `protected String` | `readableLocation(CachedNode node)`
    `void` | `refresh(boolean keepChanges)`
    `protected void` | `releaseCachedNode(org.modeshape.jcr.AbstractJcrNode node)`
    `void` | `removeItem(String absPath)`
    `void` | `removeLockToken(String lockToken)`
    `void` | `save()`
    `boolean` | `sequence(String sequencerName, Property inputProperty, Node outputNode)` Sequence the specified property using the named sequencer, and place the generated output at the specified location using this session.
    `void` | `setNamespacePrefix(String newPrefix, String existingUri)`
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### repository

          protected final JcrRepository repository

  - ### Constructor Detail

    - #### JcrSession

          protected JcrSession(JcrRepository repository,
                    String workspaceName,
                    ExecutionContext context,
                    Map<String,Object> sessionAttributes,
                    boolean readOnly)

    - #### JcrSession

          protected JcrSession(JcrSession original,
                    boolean readOnly)

  - ### Method Detail

    - #### entryForNode

          protected SchematicEntry entryForNode(NodeKey nodeKey)
                                         throws RepositoryException

      Throws:
        `RepositoryException`

    - #### isReadOnly

          public final boolean isReadOnly()

    - #### readableLocation

          protected final String readableLocation(CachedNode node)

    - #### aclChangesCount

          protected final long aclChangesCount()

    - #### aclAdded

          protected final long aclAdded()

    - #### aclRemoved

          protected final long aclRemoved()

    - #### readable

          protected final String readable(Path path)

    - #### releaseCachedNode

          protected void releaseCachedNode(org.modeshape.jcr.AbstractJcrNode node)

    - #### getRepository

          public JcrRepository getRepository()

      Specified by:
        `getRepository` in interface `Session`

    - #### getUserID

          public String getUserID()

      Specified by:
        `getUserID` in interface `Session`

    - #### isAnonymous

          public boolean isAnonymous()

    - #### getAttributeNames

          public String[] getAttributeNames()

      Specified by:
        `getAttributeNames` in interface `Session`

    - #### getAttribute

          public Object getAttribute(String name)

      Specified by:
        `getAttribute` in interface `Session`

    - #### getWorkspace

          public org.modeshape.jcr.JcrWorkspace getWorkspace()

      Specified by:
        `getWorkspace` in interface `Session`

    - #### getRootNode

          public org.modeshape.jcr.JcrRootNode getRootNode()
                                                    throws RepositoryException

      Specified by:
        `getRootNode` in interface `Session`
      Throws:
        `RepositoryException`

    - #### impersonate

          public Session impersonate(Credentials credentials)
                              throws LoginException,
                                     RepositoryException

      Specified by:
        `impersonate` in interface `Session`
      Throws:
        `LoginException`
        `RepositoryException`

    - #### getNodeByUUID

          @Deprecated
          public org.modeshape.jcr.AbstractJcrNode getNodeByUUID(String uuid)
                                                          throws ItemNotFoundException,
                                                                 RepositoryException

      Deprecated.
      Specified by:
        `getNodeByUUID` in interface `Session`
      Throws:
        `ItemNotFoundException`
        `RepositoryException`

    - #### getNodeByIdentifier

          public org.modeshape.jcr.AbstractJcrNode getNodeByIdentifier(String id)
                                                                throws ItemNotFoundException,
                                                                       RepositoryException

      Specified by:
        `getNodeByIdentifier` in interface `Session`
      Throws:
        `ItemNotFoundException`
        `RepositoryException`

    - #### getNonSystemNodeByIdentifier

          public org.modeshape.jcr.AbstractJcrNode getNonSystemNodeByIdentifier(String id)
                                                                         throws ItemNotFoundException,
                                                                                RepositoryException

      A variant of the standard `getNodeByIdentifier(String)` method that does not find nodes within the system area. This is often needed by the `JcrVersionManager` functionality.
      Parameters:
        `id` - the string identifier
      Returns:
        the node; never null
      Throws:
        `ItemNotFoundException` - if a node cannot be found in the non-system content of the repository
        `RepositoryException` - if there is another problem
      See Also:
        `getNodeByIdentifier(String)`

    - #### getNode

          public org.modeshape.jcr.AbstractJcrNode getNode(String absPath)
                                                    throws PathNotFoundException,
                                                           RepositoryException

      Specified by:
        `getNode` in interface `Session`
      Throws:
        `PathNotFoundException`
        `RepositoryException`

    - #### getNode

          protected org.modeshape.jcr.AbstractJcrNode getNode(String absPath,
                                                  boolean accessControlScope)
                                                       throws PathNotFoundException,
                                                              RepositoryException

      Throws:
        `PathNotFoundException`
        `RepositoryException`

    - #### getItem

          public org.modeshape.jcr.AbstractJcrItem getItem(String absPath)
                                                    throws PathNotFoundException,
                                                           RepositoryException

      Specified by:
        `getItem` in interface `Session`
      Throws:
        `PathNotFoundException`
        `RepositoryException`

    - #### getProperty

          public Property getProperty(String absPath)
                               throws PathNotFoundException,
                                      RepositoryException

      Specified by:
        `getProperty` in interface `Session`
      Throws:
        `PathNotFoundException`
        `RepositoryException`

    - #### itemExists

          public boolean itemExists(String absPath)
                             throws RepositoryException

      Specified by:
        `itemExists` in interface `Session`
      Throws:
        `RepositoryException`

    - #### removeItem

          public void removeItem(String absPath)
                          throws VersionException,
                                 LockException,
                                 ConstraintViolationException,
                                 AccessDeniedException,
                                 RepositoryException

      Specified by:
        `removeItem` in interface `Session`
      Throws:
        `VersionException`
        `LockException`
        `ConstraintViolationException`
        `AccessDeniedException`
        `RepositoryException`

    - #### nodeExists

          public boolean nodeExists(String absPath)
                             throws RepositoryException

      Specified by:
        `nodeExists` in interface `Session`
      Throws:
        `RepositoryException`

    - #### nodeExists

          protected boolean nodeExists(NodeKey key)

      Utility method to determine if the node with the specified key still exists within the transient & persisted state.
      Parameters:
        `key` - the key of the node; may not be null
      Returns:
        true if the node exists, or false if it does not

    - #### propertyExists

          public boolean propertyExists(String absPath)
                                 throws RepositoryException

      Specified by:
        `propertyExists` in interface `Session`
      Throws:
        `RepositoryException`

    - #### move

          public void move(String srcAbsPath,
                  String destAbsPath)
                    throws ItemExistsException,
                           PathNotFoundException,
                           VersionException,
                           ConstraintViolationException,
                           LockException,
                           RepositoryException

      Specified by:
        `move` in interface `Session`
      Throws:
        `ItemExistsException`
        `PathNotFoundException`
        `VersionException`
        `ConstraintViolationException`
        `LockException`
        `RepositoryException`

    - #### save

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

      Specified by:
        `save` in interface `Session`
      Throws:
        `AccessDeniedException`
        `ItemExistsException`
        `ReferentialIntegrityException`
        `ConstraintViolationException`
        `InvalidItemStateException`
        `VersionException`
        `LockException`
        `NoSuchNodeTypeException`
        `RepositoryException`

    - #### refresh

          public void refresh(boolean keepChanges)
                       throws RepositoryException

      Specified by:
        `refresh` in interface `Session`
      Throws:
        `RepositoryException`

    - #### hasPendingChanges

          public boolean hasPendingChanges()
                                    throws RepositoryException

      Specified by:
        `hasPendingChanges` in interface `Session`
      Throws:
        `RepositoryException`

    - #### getValueFactory

          public JcrValueFactory getValueFactory()
                                          throws RepositoryException

      Specified by:
        `getValueFactory` in interface `Session`
      Throws:
        `RepositoryException`

    - #### checkPermission

          public void checkPermission(String path,
                             String actions)

      Specified by:
        `checkPermission` in interface `Session`

    - #### hasPermission

          public boolean hasPermission(String absPath,
                              String actions)
                                throws RepositoryException

      Specified by:
        `hasPermission` in interface `Session`
      Throws:
        `RepositoryException`

    - #### hasCapability

          public boolean hasCapability(String methodName,
                              Object target,
                              Object[] arguments)
                                throws RepositoryException

      Makes a "best effort" determination of whether the given method can be successfully called on the given target with the given arguments. A return value of `false` indicates that the method would not succeed. A return value of `true` indicates that the method might succeed.
      Specified by:
        `hasCapability` in interface `Session`
      Parameters:
        `methodName` - the method to invoke; may not be null
        `target` - the object on which to invoke it; may not be null
        `arguments` - the arguments to pass to the method; varies depending on the method
      Returns:
        true if the given method can be determined to be supported, or false otherwise
      Throws:
        `IllegalArgumentException`
        `RepositoryException`

    - #### getImportContentHandler

          public ContentHandler getImportContentHandler(String parentAbsPath,
                                               int uuidBehavior)
                                                 throws PathNotFoundException,
                                                        ConstraintViolationException,
                                                        VersionException,
                                                        LockException,
                                                        RepositoryException

      Specified by:
        `getImportContentHandler` in interface `Session`
      Throws:
        `PathNotFoundException`
        `ConstraintViolationException`
        `VersionException`
        `LockException`
        `RepositoryException`

    - #### initBaseVersionKeys

          protected void initBaseVersionKeys()

    - #### initOriginalVersionKeys

          protected void initOriginalVersionKeys()

    - #### importXML

          public void importXML(String parentAbsPath,
                       InputStream in,
                       int uuidBehavior)
                         throws IOException,
                                PathNotFoundException,
                                ItemExistsException,
                                ConstraintViolationException,
                                VersionException,
                                InvalidSerializedDataException,
                                LockException,
                                RepositoryException

      Specified by:
        `importXML` in interface `Session`
      Throws:
        `IOException`
        `PathNotFoundException`
        `ItemExistsException`
        `ConstraintViolationException`
        `VersionException`
        `InvalidSerializedDataException`
        `LockException`
        `RepositoryException`

    - #### exportSystemView

          public void exportSystemView(String absPath,
                              ContentHandler contentHandler,
                              boolean skipBinary,
                              boolean noRecurse)
                                throws PathNotFoundException,
                                       SAXException,
                                       RepositoryException

      Specified by:
        `exportSystemView` in interface `Session`
      Throws:
        `PathNotFoundException`
        `SAXException`
        `RepositoryException`

    - #### exportSystemView

          public void exportSystemView(String absPath,
                              OutputStream out,
                              boolean skipBinary,
                              boolean noRecurse)
                                throws IOException,
                                       PathNotFoundException,
                                       RepositoryException

      Specified by:
        `exportSystemView` in interface `Session`
      Throws:
        `IOException`
        `PathNotFoundException`
        `RepositoryException`

    - #### exportDocumentView

          public void exportDocumentView(String absPath,
                                ContentHandler contentHandler,
                                boolean skipBinary,
                                boolean noRecurse)
                                  throws PathNotFoundException,
                                         SAXException,
                                         RepositoryException

      Specified by:
        `exportDocumentView` in interface `Session`
      Throws:
        `PathNotFoundException`
        `SAXException`
        `RepositoryException`

    - #### exportDocumentView

          public void exportDocumentView(String absPath,
                                OutputStream out,
                                boolean skipBinary,
                                boolean noRecurse)
                                  throws IOException,
                                         PathNotFoundException,
                                         RepositoryException

      Specified by:
        `exportDocumentView` in interface `Session`
      Throws:
        `IOException`
        `PathNotFoundException`
        `RepositoryException`

    - #### getNamespacePrefix

          public String getNamespacePrefix(String uri)
                                    throws RepositoryException

      Specified by:
        `getNamespacePrefix` in interface `Session`
      Throws:
        `RepositoryException`

    - #### getNamespacePrefixes

          public String[] getNamespacePrefixes()
                                        throws RepositoryException

      Specified by:
        `getNamespacePrefixes` in interface `Session`
      Throws:
        `RepositoryException`

    - #### getNamespaceURI

          public String getNamespaceURI(String prefix)
                                 throws RepositoryException

      Specified by:
        `getNamespaceURI` in interface `Session`
      Throws:
        `RepositoryException`

    - #### setNamespacePrefix

          public void setNamespacePrefix(String newPrefix,
                                String existingUri)
                                  throws NamespaceException,
                                         RepositoryException

      Specified by:
        `setNamespacePrefix` in interface `Session`
      Throws:
        `NamespaceException`
        `RepositoryException`

    - #### logout

          public void logout()

      Specified by:
        `logout` in interface `Session`

    - #### isLive

          public boolean isLive()

      Specified by:
        `isLive` in interface `Session`

    - #### addLockToken

          public void addLockToken(String lockToken)

      Specified by:
        `addLockToken` in interface `Session`

    - #### getLockTokens

          public String[] getLockTokens()

      Specified by:
        `getLockTokens` in interface `Session`

    - #### removeLockToken

          public void removeLockToken(String lockToken)

      Specified by:
        `removeLockToken` in interface `Session`

    - #### getAccessControlManager

          public AccessControlManager getAccessControlManager()

      Specified by:
        `getAccessControlManager` in interface `Session`

    - #### getRetentionManager

          public RetentionManager getRetentionManager()
                                               throws UnsupportedRepositoryOperationException,
                                                      RepositoryException

      Specified by:
        `getRetentionManager` in interface `Session`
      Throws:
        `UnsupportedRepositoryOperationException`
        `RepositoryException`

    - #### createNodeKeyFromIdentifier

          public static NodeKey createNodeKeyFromIdentifier(String identifier,
                                            NodeKey rootKey)

      Determine if the supplied string represents just the `node's identifier` or whether it is a string representation of a NodeKey. If it is just the node's identifier, then the NodeKey is created by using the same `source key` and `workspace key` from the supplied root node.
      Parameters:
        `identifier` - the identifier string; may not be null
        `rootKey` - the node of the root in the workspace; may not be null
      Returns:
        the node key re-created from the supplied identifier; never null

    - #### isForeignKey

          public static boolean isForeignKey(NodeKey key,
                             NodeKey rootKey)

      Checks if the node given key is foreign by comparing the source key & workspace key against the same keys from this session's root. This method is used for reference resolving.
      Parameters:
        `key` - the node key; may be null
        `rootKey` - the key of the root node in the workspace; may not be null
      Returns:
        true if the node key is considered foreign, false otherwise.

    - #### nodeIdentifier

          public static String nodeIdentifier(NodeKey key,
                              NodeKey rootKey)

      Returns a string representing a node's identifier, based on whether the node is foreign or not.
      Parameters:
        `key` - the node key; may be null
        `rootKey` - the key of the root node in the workspace; may not be null
      Returns:
        the identifier for the node; never null
      See Also:
        `Node.getIdentifier()`

    - #### isForeignKey

          protected final boolean isForeignKey(NodeKey key)

      Checks if the node given key is foreign by comparing the source key & workspace key against the same keys from this session's root. This method is used for reference resolving.
      Parameters:
        `key` - the node key; may be null
      Returns:
        true if the node key is considered foreign, false otherwise.

    - #### nodeIdentifier

          protected final String nodeIdentifier(NodeKey key)

      Returns a string representing a node's identifier, based on whether the node is foreign or not.
      Parameters:
        `key` - the node key; may be null
      Returns:
        the identifier for the node; never null
      See Also:
        `Node.getIdentifier()`

    - #### sequence

          public boolean sequence(String sequencerName,
                         Property inputProperty,
                         Node outputNode)
                           throws RepositoryException

      Description copied from interface: `Session`
      Sequence the specified property using the named sequencer, and place the generated output at the specified location using this session. The output nodes will be transient within the current session, so this session will need to be saved to persist the output.

      It is suggested that this method be used on inputs that the sequencer is not configured to process automatically, otherwise ModeShape will also sequence the same property. If your application is to only manually sequence, simply configure each sequencer without a path expression or with a path expression that will never apply to the manually-sequenced nodes.

      Parameters:
        `sequencerName` - the name of the configured sequencer that should be executed
        `inputProperty` - the property that was changed and that should be used as the input; never null
        `outputNode` - the node that represents the output for the derived information; never null, and will either be `new` if the output is being placed outside of the selected node, or will not be new when the output is to be placed on the selected input node
      Returns:
        true if the sequencer did generate output; false if the sequencer could not process the specified content or if `sequencerName` is null or does not match a configured sequencer
      Throws:
        `RepositoryException` - if there was a problem with the sequencer

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### decode

          public String decode(String localName)

      Description copied from interface: `Session`
      Evaluate a local name and replace any characters that were previously `encoded`.
      Parameters:
        `localName` - the local name to be decoded; can be `null` or empty
      Returns:
        the supplied local name if it contains no encoded characters, or the decoded form of the supplied local name with all encoded characters replaced, or `null` if the input was `null`
      See Also:
        `Session.encode(String)`

    - #### encode

          public String encode(String localName)

      Description copied from interface: `Session`
      Evaluate a local name and replace any characters that are not allowed within the local names of nodes and properties. Such characters include '/', ':', '[', ']', '*', and '|', since these are all important to the rules for qualified names and paths. When such characters are to be used within a local name, the application must escape them using this method before the local name is used.
      Parameters:
        `localName` - the local name to be encoded; can be `null` or empty
      Returns:
        the supplied local name if it contains no illegal characters, or the encoded form of the supplied local name with all illegal characters replaced, or `null` if the input was `null`
      See Also:
        `Session.move(String, String)`, `Node.addNode(String)`, `Node.addNode(String, String)`

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.