@Override Path path() throws RepositoryException { return session().pathFactory().create(node.path(), name); }
@Override Path path() throws RepositoryException { return session().pathFactory().create(node.path(), name); }
private AbstractJcrNode validateReferenceableNode( Node value ) throws RepositoryException { if (!value.isNodeType(JcrMixLexicon.REFERENCEABLE.getString(namespaces))) { throw new RepositoryException(JcrI18n.nodeNotReferenceable.text()); } if (!(value instanceof AbstractJcrNode)) { throw new IllegalArgumentException("Invalid node type (expected a ModeShape node): " + value.getClass().toString()); } AbstractJcrNode node = (AbstractJcrNode)value; if (!node.isInTheSameProcessAs(executionContextProcessId)) { throw new RepositoryException(JcrI18n.nodeNotInTheSameSession.text(node.path())); } return node; }
private AbstractJcrNode validateReferenceableNode( Node value ) throws RepositoryException { if (!value.isNodeType(JcrMixLexicon.REFERENCEABLE.getString(namespaces))) { throw new RepositoryException(JcrI18n.nodeNotReferenceable.text()); } if (!(value instanceof AbstractJcrNode)) { throw new IllegalArgumentException("Invalid node type (expected a ModeShape node): " + value.getClass().toString()); } AbstractJcrNode node = (AbstractJcrNode)value; if (!node.isInTheSameProcessAs(executionContextProcessId)) { throw new RepositoryException(JcrI18n.nodeNotInTheSameSession.text(node.path())); } return node; }
protected final Path correspondingNodePath( String workspaceName ) throws NoSuchWorkspaceException, ItemNotFoundException, RepositoryException { assert workspaceName != null; NamespaceRegistry namespaces = this.context().getNamespaceRegistry(); // Find the closest ancestor (including this node) that is referenceable ... AbstractJcrNode referenceableRoot = this; while (!referenceableRoot.isNodeType(JcrMixLexicon.REFERENCEABLE.getString(namespaces))) { referenceableRoot = referenceableRoot.getParent(); } // Find the relative path from the nearest referenceable node to this node (or null if this node is referenceable) ... Path relativePath = path().equals(referenceableRoot.path()) ? null : path().relativeTo(referenceableRoot.path()); NodeKey key = referenceableRoot.key(); // if the we're looking for a system node, we need to use the system ws name, which is repository-wide String systemWsKey = session.getRepository().systemWorkspaceKey(); String workspaceKey = systemWsKey.equals(key.getWorkspaceKey()) ? systemWsKey : NodeKey.keyForWorkspaceName(workspaceName); NodeKey nodeKey = new NodeKey(key.getSourceKey(), workspaceKey, key.getIdentifier()); return session.getPathForCorrespondingNode(workspaceName, nodeKey, relativePath); }
protected String name() { try { Path path = node().path(); return path.isRoot() ? "" : stringFor(path.getLastSegment()); } catch (Exception e) { throw new SystemFailureException(e); } }
protected String name() { try { Path path = node().path(); return path.isRoot() ? "" : stringFor(path.getLastSegment()); } catch (Exception e) { throw new SystemFailureException(e); } }
@Override public org.modeshape.jcr.api.query.Query getQuery( Node node ) throws InvalidQueryException, RepositoryException { AbstractJcrNode jcrNode = CheckArg.getInstanceOf(node, AbstractJcrNode.class, "node"); // Check the type of the node ... JcrNodeType nodeType = jcrNode.getPrimaryNodeType(); if (!nodeType.getInternalName().equals(JcrNtLexicon.QUERY)) { NamespaceRegistry registry = session.context().getNamespaceRegistry(); throw new InvalidQueryException(JcrI18n.notStoredQuery.text(jcrNode.path().getString(registry))); } // These are both mandatory properties for nodes of nt:query String statement = jcrNode.getProperty(JcrLexicon.STATEMENT).getString(); String language = jcrNode.getProperty(JcrLexicon.LANGUAGE).getString(); return createQuery(statement, language, jcrNode.path(), null); }
final JcrValue valueFrom( javax.jcr.Node value ) throws RepositoryException { if (!(value instanceof AbstractJcrNode)) { throw new IllegalArgumentException("Invalid node type (expected a ModeShape node): " + value.getClass().toString()); } AbstractJcrNode node = (AbstractJcrNode)value; if (!this.isInTheSameProcessAs(node.session().context().getProcessId())) { throw new RepositoryException(JcrI18n.nodeNotInTheSameSession.text(node.path())); } NodeKey key = ((AbstractJcrNode)value).key(); Reference ref = session.context().getValueFactories().getReferenceFactory() .create(key, ((AbstractJcrNode)value).isForeign()); return valueFrom(PropertyType.REFERENCE, ref); }
@Override public org.modeshape.jcr.api.query.Query getQuery( Node node ) throws InvalidQueryException, RepositoryException { AbstractJcrNode jcrNode = CheckArg.getInstanceOf(node, AbstractJcrNode.class, "node"); // Check the type of the node ... JcrNodeType nodeType = jcrNode.getPrimaryNodeType(); if (!nodeType.getInternalName().equals(JcrNtLexicon.QUERY)) { NamespaceRegistry registry = session.context().getNamespaceRegistry(); throw new InvalidQueryException(JcrI18n.notStoredQuery.text(jcrNode.path().getString(registry))); } // These are both mandatory properties for nodes of nt:query String statement = jcrNode.getProperty(JcrLexicon.STATEMENT).getString(); String language = jcrNode.getProperty(JcrLexicon.LANGUAGE).getString(); return createQuery(statement, language, jcrNode.path(), null); }
final JcrValue valueFrom( javax.jcr.Node value ) throws RepositoryException { if (!(value instanceof AbstractJcrNode)) { throw new IllegalArgumentException("Invalid node type (expected a ModeShape node): " + value.getClass().toString()); } AbstractJcrNode node = (AbstractJcrNode)value; if (!this.isInTheSameProcessAs(node.session().context().getProcessId())) { throw new RepositoryException(JcrI18n.nodeNotInTheSameSession.text(node.path())); } NodeKey key = ((AbstractJcrNode)value).key(); Reference ref = session.context().getValueFactories().getReferenceFactory() .create(key, ((AbstractJcrNode)value).isForeign()); return valueFrom(PropertyType.REFERENCE, ref); }
public void unlock( AbstractJcrNode node ) throws PathNotFoundException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException { if (node.isModified()) { throw new InvalidItemStateException(JcrI18n.changedNodeCannotBeUnlocked.text(node.getPath())); } ModeShapeLock lock = lockManager.findLockFor(node.key()); if (lock != null && !lockTokens.contains(lock.getLockToken())) { // Someone else holds the lock, so see if the user has the permission to break someone else's lock ... try { session.checkPermission(session.workspaceName(), node.path(), ModeShapePermissions.UNLOCK_ANY); } catch (AccessDeniedException e) { //expected by the TCK throw new LockException(e); } } // Remove the lock ... String lockToken = lockManager.unlock(session, node.key()); lockTokens.remove(lockToken); }
public void unlock( AbstractJcrNode node ) throws PathNotFoundException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException { if (node.isModified()) { throw new InvalidItemStateException(JcrI18n.changedNodeCannotBeUnlocked.text(node.getPath())); } ModeShapeLock lock = lockManager.findLockFor(node.key()); if (lock != null && !lockTokens.contains(lock.getLockToken())) { // Someone else holds the lock, so see if the user has the permission to break someone else's lock ... try { session.checkPermission(session.workspaceName(), node.path(), ModeShapePermissions.UNLOCK_ANY); } catch (AccessDeniedException e) { //expected by the TCK throw new LockException(e); } } // Remove the lock ... String lockToken = lockManager.unlock(session, node.key()); lockTokens.remove(lockToken); }
@Override Path path() throws ItemNotFoundException, InvalidItemStateException { AbstractJcrNode parent = parent(); CachedNode node = parent.node(); SessionCache cache = session.cache(); ChildReference childRef = node.getChildReferences(cache).getChild(sharedSet.key()); Path parentPath = parent.path(); return session().pathFactory().create(parentPath, childRef.getSegment()); }
final AbstractJcrItem findItem( AbstractJcrNode node, Path relativePath ) throws RepositoryException { assert !relativePath.isAbsolute(); if (relativePath.size() == 1) { Segment last = relativePath.getLastSegment(); if (last.isSelfReference()) return node; if (last.isParentReference()) return node.getParent(); } // Find the path to the referenced node ... Path nodePath = node.path(); Path absolutePath = nodePath.resolve(relativePath); if (absolutePath.isAtOrBelow(nodePath)) { // Find the item starting at 'node' ... } return getItem(absolutePath); }
final AbstractJcrItem findItem( AbstractJcrNode node, Path relativePath ) throws RepositoryException { assert !relativePath.isAbsolute(); if (relativePath.size() == 1) { Segment last = relativePath.getLastSegment(); if (last.isSelfReference()) return node; if (last.isParentReference()) return node.getParent(); } // Find the path to the referenced node ... Path nodePath = node.path(); Path absolutePath = nodePath.resolve(relativePath); if (absolutePath.isAtOrBelow(nodePath)) { // Find the item starting at 'node' ... } return getItem(absolutePath); }
@Override Path path() throws ItemNotFoundException, InvalidItemStateException { AbstractJcrNode parent = parent(); CachedNode node = parent.node(); SessionCache cache = session.cache(); ChildReference childRef = node.getChildReferences(cache).getChild(sharedSet.key()); Path parentPath = parent.path(); return session().pathFactory().create(parentPath, childRef.getSegment()); }
@Override public void restore( Version version, String relPath, boolean removeExisting ) throws PathNotFoundException, ItemExistsException, VersionException, ConstraintViolationException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException { checkNotProtected(); PathFactory pathFactory = session.pathFactory(); Path relPathAsPath = pathFactory.create(relPath); if (relPathAsPath.isAbsolute()) throw new RepositoryException(JcrI18n.invalidRelativePath.text(relPath)); Path actualPath = pathFactory.create(path(), relPathAsPath).getCanonicalPath(); versionManager().restoreAtAbsPath(session.stringFactory().create(actualPath), version, removeExisting, false); }
@Override public void restore( Version version, String relPath, boolean removeExisting ) throws PathNotFoundException, ItemExistsException, VersionException, ConstraintViolationException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException { checkNotProtected(); PathFactory pathFactory = session.pathFactory(); Path relPathAsPath = pathFactory.create(relPath); if (relPathAsPath.isAbsolute()) throw new RepositoryException(JcrI18n.invalidRelativePath.text(relPath)); Path actualPath = pathFactory.create(path(), relPathAsPath).getCanonicalPath(); versionManager().restoreAtAbsPath(session.stringFactory().create(actualPath), version, removeExisting, false); }
private void fireSequencingFailureEvent( AbstractJcrNode sequencedNode, JcrSession inputSession, Throwable cause, String sequencerName ) throws RepositoryException { assert sequencedNode != null; assert inputSession != null; Name primaryType = sequencedNode.getPrimaryTypeName(); Set<Name> mixinTypes = sequencedNode.getMixinTypeNames(); final ExecutionContext context = inputSession.context(); RecordingChanges sequencingChanges = new RecordingChanges(inputSession.sessionId(), context.getProcessId(), inputSession.getRepository().repositoryKey(), inputSession.workspaceName(), inputSession.getRepository() .journalId()); sequencingChanges.nodeSequencingFailure(sequencedNode.key(), sequencedNode.path(), primaryType, mixinTypes, work.getOutputPath(), work.getUserId(), work.getSelectedPath(), sequencerName, cause); repository.changeBus().notify(sequencingChanges); }