nodeimpl.java

来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 1,586 行 · 第 1/5 页

JAVA
1,586
字号
    }    /**     * Checks various pre-conditions that are common to all     * <code>setProperty()</code> methods. The checks performed are:     * <ul>     * <li>this node must be checked-out</li>     * <li>this node must not be locked by somebody else</li>     * </ul>     * Note that certain checks are performed by the respective     * <code>Property.setValue()</code> methods.     *     * @throws VersionException    if this node is not checked-out     * @throws LockException       if this node is locked by somebody else     * @throws RepositoryException if another error occurs     * @see javax.jcr.Node#setProperty     */    protected void checkSetProperty()            throws VersionException, LockException, RepositoryException {        // make sure this node is checked-out        if (!internalIsCheckedOut()) {            String msg = safeGetJCRPath()                    + ": cannot set property of a checked-in node";            log.debug(msg);            throw new VersionException(msg);        }        // check lock status        checkLock();    }    /**     * Sets the internal value of a property without checking any constraints.     * <p/>     * Note that no type conversion is being performed, i.e. it's the caller's     * responsibility to make sure that the type of the given value is compatible     * with the specified property's definition.     * @param name     * @param value     * @return     * @throws ValueFormatException     * @throws RepositoryException     */    protected Property internalSetProperty(QName name, InternalValue value)            throws ValueFormatException, RepositoryException {        int type;        if (value == null) {            type = PropertyType.UNDEFINED;        } else {            type = value.getType();        }        BitSet status = new BitSet();        PropertyImpl prop = getOrCreateProperty(name, type, false, true, status);        try {            if (value == null) {                prop.internalSetValue(null, type);            } else {                prop.internalSetValue(new InternalValue[]{value}, type);            }        } catch (RepositoryException re) {            if (status.get(CREATED)) {                // setting value failed, get rid of newly created property                removeChildProperty(name);            }            // rethrow            throw re;        }        return prop;    }    /**     * Sets the internal value of a property without checking any constraints.     * <p/>     * Note that no type conversion is being performed, i.e. it's the caller's     * responsibility to make sure that the type of the given values is compatible     * with the specified property's definition.     *     * @param name     * @param values     * @return     * @throws ValueFormatException     * @throws RepositoryException     */    protected Property internalSetProperty(QName name, InternalValue[] values)            throws ValueFormatException, RepositoryException {        int type;        if (values == null || values.length == 0                || values[0] == null) {            type = PropertyType.UNDEFINED;        } else {            type = values[0].getType();        }        return internalSetProperty(name, values, type);    }    /**     * Sets the internal value of a property without checking any constraints.     * <p/>     * Note that no type conversion is being performed, i.e. it's the caller's     * responsibility to make sure that the type of the given values is compatible     * with the specified property's definition.     *     * @param name     * @param values     * @param type     * @return     * @throws ValueFormatException     * @throws RepositoryException     */    protected Property internalSetProperty(QName name, InternalValue[] values,                                           int type)            throws ValueFormatException, RepositoryException {        BitSet status = new BitSet();        PropertyImpl prop = getOrCreateProperty(name, type, true, true, status);        try {            prop.internalSetValue(values, type);        } catch (RepositoryException re) {            if (status.get(CREATED)) {                // setting value failed, get rid of newly created property                removeChildProperty(name);            }            // rethrow            throw re;        }        return prop;    }    /**     * Returns the child node of <code>this</code> node with the specified     * <code>name</code>.     *     * @param name The qualified name of the child node to retrieve.     * @return The child node with the specified <code>name</code>.     * @throws ItemNotFoundException If no child node exists with the     *                               specified name.     * @throws RepositoryException   If another error occurs.     */    public NodeImpl getNode(QName name) throws ItemNotFoundException, RepositoryException {        return getNode(name, 1);    }    /**     * Returns the child node of <code>this</code> node with the specified     * <code>name</code>.     *     * @param name  The qualified name of the child node to retrieve.     * @param index The index of the child node to retrieve (in the case of same-name siblings).     * @return The child node with the specified <code>name</code>.     * @throws ItemNotFoundException If no child node exists with the     *                               specified name.     * @throws RepositoryException   If another error occurs.     */    public NodeImpl getNode(QName name, int index)            throws ItemNotFoundException, RepositoryException {        // check state of this instance        sanityCheck();        NodeState thisState = (NodeState) state;        if (index == 0) {            index = 1;        }        NodeState.ChildNodeEntry cne = thisState.getChildNodeEntry(name, index);        if (cne == null) {            throw new ItemNotFoundException();        }        try {            return (NodeImpl) itemMgr.getItem(cne.getId());        } catch (AccessDeniedException ade) {            throw new ItemNotFoundException();        }    }    /**     * Indicates whether a child node with the specified <code>name</code> exists.     * Returns <code>true</code> if the child node exists and <code>false</code>     * otherwise.     *     * @param name The qualified name of the child node.     * @return <code>true</code> if the child node exists; <code>false</code> otherwise.     * @throws RepositoryException If an unspecified error occurs.     */    public boolean hasNode(QName name) throws RepositoryException {        return hasNode(name, 1);    }    /**     * Indicates whether a child node with the specified <code>name</code> exists.     * Returns <code>true</code> if the child node exists and <code>false</code>     * otherwise.     *     * @param name  The qualified name of the child node.     * @param index The index of the child node (in the case of same-name siblings).     * @return <code>true</code> if the child node exists; <code>false</code> otherwise.     * @throws RepositoryException If an unspecified error occurs.     */    public boolean hasNode(QName name, int index) throws RepositoryException {        // check state of this instance        sanityCheck();        NodeState thisState = (NodeState) state;        if (index == 0) {            index = 1;        }        NodeState.ChildNodeEntry cne = thisState.getChildNodeEntry(name, index);        if (cne == null) {            return false;        }        return itemMgr.itemExists(cne.getId());    }    /**     * Returns the property of <code>this</code> node with the specified     * <code>name</code>.     *     * @param name The qualified name of the property to retrieve.     * @return The property with the specified <code>name</code>.     * @throws ItemNotFoundException If no property exists with the     *                               specified name.     * @throws RepositoryException   If another error occurs.     */    public PropertyImpl getProperty(QName name)            throws ItemNotFoundException, RepositoryException {        // check state of this instance        sanityCheck();        PropertyId propId = new PropertyId(getNodeId(), name);        try {            return (PropertyImpl) itemMgr.getItem(propId);        } catch (AccessDeniedException ade) {            throw new ItemNotFoundException(name.toString());        }    }    /**     * Indicates whether a property with the specified <code>name</code> exists.     * Returns <code>true</code> if the property exists and <code>false</code>     * otherwise.     *     * @param name The qualified name of the property.     * @return <code>true</code> if the property exists; <code>false</code> otherwise.     * @throws RepositoryException If an unspecified error occurs.     */    public boolean hasProperty(QName name) throws RepositoryException {        // check state of this instance        sanityCheck();        NodeState thisState = (NodeState) state;        if (!thisState.hasPropertyName(name)) {            return false;        }        PropertyId propId = new PropertyId(thisState.getNodeId(), name);        return itemMgr.itemExists(propId);    }    /**     * Same as <code>{@link Node#addNode(String, String)}</code> except that     * this method takes <code>QName</code> arguments instead of     * <code>String</code>s and has an additional <code>uuid</code> argument.     * <p/>     * <b>Important Notice:</b> This method is for internal use only! Passing     * already assigned uuid's might lead to unexpected results and     * data corruption in the worst case.     *     * @param nodeName     name of the new node     * @param nodeTypeName name of the new node's node type or <code>null</code>     *                     if it should be determined automatically     * @param uuid         uuid of the new node or <code>null</code> if a new     *                     uuid should be assigned     * @return the newly added node     * @throws ItemExistsException     * @throws NoSuchNodeTypeException     * @throws VersionException     * @throws ConstraintViolationException     * @throws LockException     * @throws RepositoryException     */    public synchronized NodeImpl addNode(QName nodeName, QName nodeTypeName,                                         UUID uuid)            throws ItemExistsException, NoSuchNodeTypeException, VersionException,            ConstraintViolationException, LockException, RepositoryException {        // check state of this instance        sanityCheck();        // make sure this node is checked-out        if (!internalIsCheckedOut()) {            String msg = safeGetJCRPath() + ": cannot add node to a checked-in node";            log.debug(msg);            throw new VersionException(msg);        }        // check lock status        checkLock();        NodeTypeImpl nt = null;        if (nodeTypeName != null) {            nt = session.getNodeTypeManager().getNodeType(nodeTypeName);        }        return internalAddChildNode(nodeName, nt, uuid == null ? null : new NodeId(uuid));    }    /**     * Same as <code>{@link Node#setProperty(String, Value[])}</code> except that     * this method takes a <code>QName</code> name argument instead of a     * <code>String</code>.     *     * @param name     * @param values     * @return     * @throws ValueFormatException     * @throws VersionException     * @throws LockException

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?