/** * Verifies that this node is either not versionable or that it is versionable but checked out. * * @throws VersionException if the node is versionable but is checked in and cannot be modified * @throws RepositoryException if there is an error accessing the repository */ protected final void checkForCheckedOut() throws VersionException, RepositoryException { if (!isCheckedOut()) { throw new VersionException(JcrI18n.nodeIsCheckedIn.text(location())); } }
/** * Verifies that this node is either not versionable or that it is versionable but checked out. * * @throws VersionException if the node is versionable but is checked in and cannot be modified * @throws RepositoryException if there is an error accessing the repository */ protected final void checkForCheckedOut() throws VersionException, RepositoryException { if (!isCheckedOut()) { throw new VersionException(JcrI18n.nodeIsCheckedIn.text(location())); } }
@Override public String toString() { try { StringBuilder sb = new StringBuilder(); String versionableId = getVersionableIdentifier(); sb.append("Version history for " + session.getNonSystemNodeByIdentifier(versionableId).location() + " (" + versionableId + ") stored at " + location() + ":\n"); VersionIterator iter = getAllLinearVersions(); while (iter.hasNext()) { Version v = iter.nextVersion(); sb.append(" - " + v.getName() + "\n"); } return sb.toString(); } catch (RepositoryException e) { return super.toString(); } }
@Override public String toString() { try { StringBuilder sb = new StringBuilder(); String versionableId = getVersionableIdentifier(); sb.append("Version history for " + session.getNonSystemNodeByIdentifier(versionableId).location() + " (" + versionableId + ") stored at " + location() + ":\n"); VersionIterator iter = getAllLinearVersions(); while (iter.hasNext()) { Version v = iter.nextVersion(); sb.append(" - " + v.getName() + "\n"); } return sb.toString(); } catch (RepositoryException e) { return super.toString(); } }
/** * Checks that this node is not already locked by another session. If the node is not locked or the node is locked but the * lock is owned by this {@code Session}, this method completes silently. If the node is locked (either directly or as part of * a deep lock from an ancestor), this method throws a {@code LockException}. * * @throws LockException if this node is locked (that is, if {@code isLocked() == true && getLock().getLockToken() == null}). * @throws RepositoryException if any other error occurs * @see Node#isLocked() * @see Lock#getLockToken() */ protected final void checkForLock() throws LockException, RepositoryException { Lock lock = getLockIfExists(); if (lock != null && !lock.isLockOwningSession() && lock.getLockToken() == null) { throw new LockException(JcrI18n.lockTokenNotHeld.text(location())); } }
/** * Checks that this node is not already locked by another session. If the node is not locked or the node is locked but the * lock is owned by this {@code Session}, this method completes silently. If the node is locked (either directly or as part of * a deep lock from an ancestor), this method throws a {@code LockException}. * * @throws LockException if this node is locked (that is, if {@code isLocked() == true && getLock().getLockToken() == null}). * @throws RepositoryException if any other error occurs * @see Node#isLocked() * @see Lock#getLockToken() */ protected final void checkForLock() throws LockException, RepositoryException { Lock lock = getLockIfExists(); if (lock != null && !lock.isLockOwningSession() && lock.getLockToken() == null) { throw new LockException(JcrI18n.lockTokenNotHeld.text(location())); } }
/** * Checks that this property's parent node is not already locked by another session. If the parent node is not locked or the * parent node is locked but the lock is owned by this {@code Session}, this method completes silently. If the parent node is * locked (either directly or as part of a deep lock from an ancestor), this method throws a {@code LockException}. * * @throws LockException if the parent node of this property is locked (that is, if {@code getParent().isLocked() == true && * getParent().getLock().getLockToken() == null}. * @throws RepositoryException if any other error occurs * @see Node#isLocked() * @see Lock#getLockToken() */ protected final void checkForLock() throws LockException, RepositoryException { if (getParent().isLockedByAnotherSession()) { Lock parentLock = this.getParent().getLock(); if (parentLock != null && parentLock.getLockToken() == null) { throw new LockException(JcrI18n.lockTokenNotHeld.text(node.location())); } } }
/** * Checks that this property's parent node is not already locked by another session. If the parent node is not locked or the * parent node is locked but the lock is owned by this {@code Session}, this method completes silently. If the parent node is * locked (either directly or as part of a deep lock from an ancestor), this method throws a {@code LockException}. * * @throws LockException if the parent node of this property is locked (that is, if {@code getParent().isLocked() == true && * getParent().getLock().getLockToken() == null}. * @throws RepositoryException if any other error occurs * @see Node#isLocked() * @see Lock#getLockToken() */ protected final void checkForLock() throws LockException, RepositoryException { if (getParent().isLockedByAnotherSession()) { Lock parentLock = this.getParent().getLock(); if (parentLock != null && parentLock.getLockToken() == null) { throw new LockException(JcrI18n.lockTokenNotHeld.text(node.location())); } } }
private void checkAllValuesHaveTheSameType( Value[] values, Name name ) throws ValueFormatException { int valueType = -1; for (Value value : values) { if (value == null) { continue; } if (valueType == -1) { valueType = value.getType(); } else if (value.getType() != valueType) { // Make sure the type of each value is the same, as per Javadoc in section 10.4.2.6 of the JCR 2.0 spec String msg = JcrI18n.allPropertyValuesMustHaveSameType.text(readable(name), values, org.modeshape.jcr.api.PropertyType.nameFromValue(valueType), location(), workspaceName()); throw new javax.jcr.ValueFormatException(msg); } } }
private void checkAllValuesHaveTheSameType( Value[] values, Name name ) throws ValueFormatException { int valueType = -1; for (Value value : values) { if (value == null) { continue; } if (valueType == -1) { valueType = value.getType(); } else if (value.getType() != valueType) { // Make sure the type of each value is the same, as per Javadoc in section 10.4.2.6 of the JCR 2.0 spec String msg = JcrI18n.allPropertyValuesMustHaveSameType.text(readable(name), values, org.modeshape.jcr.api.PropertyType.nameFromValue(valueType), location(), workspaceName()); throw new javax.jcr.ValueFormatException(msg); } } }
@Override public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException { checkSession(); // Get the primary item name from this node's type ... NodeType primaryType = getPrimaryNodeType(); String primaryItemNameString = primaryType.getPrimaryItemName(); if (primaryItemNameString == null) { I18n msg = JcrI18n.noPrimaryItemNameDefinedOnPrimaryType; throw new ItemNotFoundException(msg.text(primaryType.getName(), location(), workspaceName())); } try { Path primaryItemPath = context().getValueFactories().getPathFactory().create(primaryItemNameString); if (primaryItemPath.size() == 1 && !primaryItemPath.isAbsolute()) { try { return session.node(node(), primaryItemPath); } catch (PathNotFoundException e) { // Must not be any child by that name, so now look for a property on the parent node ... return getProperty(primaryItemPath.getLastSegment().getName()); } } I18n msg = JcrI18n.primaryItemNameForPrimaryTypeIsNotValid; throw new ItemNotFoundException(msg.text(primaryType.getName(), primaryItemNameString, location(), workspaceName())); } catch (ValueFormatException error) { I18n msg = JcrI18n.primaryItemNameForPrimaryTypeIsNotValid; throw new ItemNotFoundException(msg.text(primaryType.getName(), primaryItemNameString, location(), workspaceName())); } catch (PathNotFoundException error) { I18n msg = JcrI18n.primaryItemDoesNotExist; throw new ItemNotFoundException(msg.text(primaryType.getName(), primaryItemNameString, location(), workspaceName())); } }
@Override public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException { checkSession(); // Get the primary item name from this node's type ... NodeType primaryType = getPrimaryNodeType(); String primaryItemNameString = primaryType.getPrimaryItemName(); if (primaryItemNameString == null) { I18n msg = JcrI18n.noPrimaryItemNameDefinedOnPrimaryType; throw new ItemNotFoundException(msg.text(primaryType.getName(), location(), workspaceName())); } try { Path primaryItemPath = context().getValueFactories().getPathFactory().create(primaryItemNameString); if (primaryItemPath.size() == 1 && !primaryItemPath.isAbsolute()) { try { return session.node(node(), primaryItemPath); } catch (PathNotFoundException e) { // Must not be any child by that name, so now look for a property on the parent node ... return getProperty(primaryItemPath.getLastSegment().getName()); } } I18n msg = JcrI18n.primaryItemNameForPrimaryTypeIsNotValid; throw new ItemNotFoundException(msg.text(primaryType.getName(), primaryItemNameString, location(), workspaceName())); } catch (ValueFormatException error) { I18n msg = JcrI18n.primaryItemNameForPrimaryTypeIsNotValid; throw new ItemNotFoundException(msg.text(primaryType.getName(), primaryItemNameString, location(), workspaceName())); } catch (PathNotFoundException error) { I18n msg = JcrI18n.primaryItemDoesNotExist; throw new ItemNotFoundException(msg.text(primaryType.getName(), primaryItemNameString, location(), workspaceName())); } }
AbstractJcrNode getNode( Name childName ) throws PathNotFoundException, RepositoryException { // It's just a name, so look for a child ... ChildReference ref = node().getChildReferences(sessionCache()).getChild(childName); if (ref == null) { String msg = JcrI18n.childNotFoundUnderNode.text(readable(childName), location(), session.workspaceName()); throw new PathNotFoundException(msg); } return session().node(ref.getKey(), null, key()); }
AbstractJcrNode getNode( Name childName ) throws PathNotFoundException, RepositoryException { // It's just a name, so look for a child ... ChildReference ref = node().getChildReferences(sessionCache()).getChild(childName); if (ref == null) { String msg = JcrI18n.childNotFoundUnderNode.text(readable(childName), location(), session.workspaceName()); throw new PathNotFoundException(msg); } return session().node(ref.getKey(), null, key()); }
/** * Get the JCR node for the named child. * * @param name the child name; may not be null * @param expectedType the expected implementation type for the node, or null if it is not known * @return the JCR node; never null * @throws PathNotFoundException if there is no child with the supplied name * @throws ItemNotFoundException if this node or the referenced child no longer exist or cannot be found * @throws InvalidItemStateException if this node has been removed in this session's transient state */ protected final AbstractJcrNode childNode( Name name, Type expectedType ) throws PathNotFoundException, ItemNotFoundException, InvalidItemStateException { ChildReference ref = node().getChildReferences(sessionCache()).getChild(name); if (ref == null) { String msg = JcrI18n.childNotFoundUnderNode.text(readable(name), location(), session.workspaceName()); throw new PathNotFoundException(msg); } return session().node(ref.getKey(), expectedType, key()); }
/** * Get the JCR node for the named child. * * @param segment the child name and SNS index; may not be null * @param expectedType the expected implementation type for the node, or null if it is not known * @return the JCR node; never null * @throws PathNotFoundException if there is no child with the supplied name * @throws ItemNotFoundException if this node or the referenced child cannot be found * @throws InvalidItemStateException if this node has been removed in this session's transient state */ protected final AbstractJcrNode childNode( Segment segment, Type expectedType ) throws PathNotFoundException, ItemNotFoundException, InvalidItemStateException { ChildReference ref = node().getChildReferences(sessionCache()).getChild(segment); if (ref == null) { String msg = JcrI18n.childNotFoundUnderNode.text(readable(segment), location(), session.workspaceName()); throw new PathNotFoundException(msg); } return session().node(ref.getKey(), expectedType, key()); }
/** * Get the JCR node for the named child. * * @param name the child name; may not be null * @param expectedType the expected implementation type for the node, or null if it is not known * @return the JCR node; never null * @throws PathNotFoundException if there is no child with the supplied name * @throws ItemNotFoundException if this node or the referenced child no longer exist or cannot be found * @throws InvalidItemStateException if this node has been removed in this session's transient state */ protected final AbstractJcrNode childNode( Name name, Type expectedType ) throws PathNotFoundException, ItemNotFoundException, InvalidItemStateException { ChildReference ref = node().getChildReferences(sessionCache()).getChild(name); if (ref == null) { String msg = JcrI18n.childNotFoundUnderNode.text(readable(name), location(), session.workspaceName()); throw new PathNotFoundException(msg); } return session().node(ref.getKey(), expectedType, key()); }
/** * Get the JCR node for the named child. * * @param segment the child name and SNS index; may not be null * @param expectedType the expected implementation type for the node, or null if it is not known * @return the JCR node; never null * @throws PathNotFoundException if there is no child with the supplied name * @throws ItemNotFoundException if this node or the referenced child cannot be found * @throws InvalidItemStateException if this node has been removed in this session's transient state */ protected final AbstractJcrNode childNode( Segment segment, Type expectedType ) throws PathNotFoundException, ItemNotFoundException, InvalidItemStateException { ChildReference ref = node().getChildReferences(sessionCache()).getChild(segment); if (ref == null) { String msg = JcrI18n.childNotFoundUnderNode.text(readable(segment), location(), session.workspaceName()); throw new PathNotFoundException(msg); } return session().node(ref.getKey(), expectedType, key()); }
String loc = location(); if (defn != null) { I18n msg = JcrI18n.propertyNoLongerSatisfiesConstraints;
void addSharedNode( AbstractJcrNode shareableNode, Name newNodeName ) throws RepositoryException { assert session == shareableNode.session; session.checkPermission(this, ModeShapePermissions.ADD_NODE); if (isLockedByAnotherSession()) { throw new LockException(JcrI18n.lockTokenNotHeld.text(location())); } // Determine the node type based upon this node's type information ... SessionCache cache = sessionCache(); MutableCachedNode node = mutable(); // validate there is an appropriate child node definition JcrNodeDefinition childDefn = validateChildNodeDefinition(newNodeName, shareableNode.getPrimaryTypeName(), true); // See if this node is checked in. If so, then we can only create children if the child // node definition has an OPV of 'ignore'. See Section 15.2.2 of the JSR-283 spec for details ... if (!isCheckedOut() && childDefn.getOnParentVersion() != OnParentVersionAction.IGNORE) { // The OPV is not 'ignore', so we can't create the new node ... Path parentPath = path(); String parentPathStr = readable(parentPath); int numExistingSns = node.getChildReferences(cache).getChildCount(newNodeName); int sns = numExistingSns + 1; String segment = readable(session.pathFactory().createSegment(newNodeName, sns)); String opv = OnParentVersionAction.nameFromValue(childDefn.getOnParentVersion()); I18n msg = JcrI18n.cannotCreateChildOnCheckedInNodeSinceOpvOfChildDefinitionIsNotIgnore; throw new VersionException(msg.text(segment, readable(parentPathStr), childDefn.getName(), opv)); } // We can create the shared node ... NodeKey childKey = shareableNode.key(); node.linkChild(cache, childKey, newNodeName); }