sessionimpl.java

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

JAVA
1,456
字号
                // log a warn message, which is not appropriate in this case.                throw new AccessControlException(SET_PROPERTY_ACTION);            }        }    }    /**     * {@inheritDoc}     */    public Workspace getWorkspace() {        return wsp;    }    /**     * {@inheritDoc}     */    public Session impersonate(Credentials otherCredentials)            throws LoginException, RepositoryException {        // check sanity of this session        sanityCheck();        if (!(otherCredentials instanceof SimpleCredentials)) {            String msg = "impersonate failed: incompatible credentials, SimpleCredentials expected";            log.debug(msg);            throw new RepositoryException(msg);        }        // set IMPERSONATOR_ATTRIBUTE attribute of given credentials        // with subject of current session        SimpleCredentials creds = (SimpleCredentials) otherCredentials;        creds.setAttribute(SecurityConstants.IMPERSONATOR_ATTRIBUTE, subject);        try {            return rep.login(otherCredentials, getWorkspace().getName());        } catch (NoSuchWorkspaceException nswe) {            // should never get here...            String msg = "impersonate failed";            log.error(msg, nswe);            throw new RepositoryException(msg, nswe);        } finally {            // make sure IMPERSONATOR_ATTRIBUTE is removed            creds.removeAttribute(SecurityConstants.IMPERSONATOR_ATTRIBUTE);        }    }    /**     * {@inheritDoc}     */    public Node getRootNode() throws RepositoryException {        // check sanity of this session        sanityCheck();        return getItemManager().getRootNode();    }    /**     * {@inheritDoc}     */    public Node getNodeByUUID(String uuid) throws ItemNotFoundException, RepositoryException {        try {            return getNodeByUUID(UUID.fromString(uuid));        } catch (IllegalArgumentException e) {            // Assuming the exception is from UUID.fromString()            throw new RepositoryException("Invalid UUID: " + uuid, e);        }    }    /**     * {@inheritDoc}     */    public Item getItem(String absPath) throws PathNotFoundException, RepositoryException {        // check sanity of this session        sanityCheck();        try {            Path p = getQPath(absPath).getNormalizedPath();            if (!p.isAbsolute()) {                throw new RepositoryException("not an absolute path: " + absPath);            }            return getItemManager().getItem(p);        } catch (AccessDeniedException ade) {            throw new PathNotFoundException(absPath);        } catch (NameException e) {            String msg = "invalid path:" + absPath;            log.debug(msg);            throw new RepositoryException(msg, e);        }    }    /**     * {@inheritDoc}     */    public boolean itemExists(String absPath) throws RepositoryException {        // check sanity of this session        sanityCheck();        try {            Path p = getQPath(absPath).getNormalizedPath();            if (!p.isAbsolute()) {                throw new RepositoryException("not an absolute path: " + absPath);            }            return getItemManager().itemExists(p);        } catch (NameException e) {            String msg = "invalid path:" + absPath;            log.debug(msg);            throw new RepositoryException(msg, e);        }    }    /**     * {@inheritDoc}     */    public void save()            throws AccessDeniedException, ItemExistsException,            ConstraintViolationException, InvalidItemStateException,            VersionException, LockException, NoSuchNodeTypeException,            RepositoryException {        // check sanity of this session        sanityCheck();        getItemManager().getRootNode().save();    }    /**     * {@inheritDoc}     */    public void refresh(boolean keepChanges) throws RepositoryException {        // check sanity of this session        sanityCheck();        if (!keepChanges) {            // optimization            itemStateMgr.disposeAllTransientItemStates();            return;        }        getItemManager().getRootNode().refresh(keepChanges);    }    /**     * {@inheritDoc}     */    public boolean hasPendingChanges() throws RepositoryException {        // check sanity of this session        sanityCheck();        return itemStateMgr.hasAnyTransientItemStates();    }    /**     * {@inheritDoc}     */    public void move(String srcAbsPath, String destAbsPath)            throws ItemExistsException, PathNotFoundException,            VersionException, ConstraintViolationException, LockException,            RepositoryException {        // check sanity of this session        sanityCheck();        // check paths & get node instances        Path srcPath;        Path.PathElement srcName;        Path srcParentPath;        NodeImpl targetNode;        NodeImpl srcParentNode;        try {            srcPath = getQPath(srcAbsPath).getNormalizedPath();            if (!srcPath.isAbsolute()) {                throw new RepositoryException("not an absolute path: " + srcAbsPath);            }            srcName = srcPath.getNameElement();            srcParentPath = srcPath.getAncestor(1);            ItemImpl item = getItemManager().getItem(srcPath);            if (!item.isNode()) {                throw new PathNotFoundException(srcAbsPath);            }            targetNode = (NodeImpl) item;            srcParentNode = (NodeImpl) getItemManager().getItem(srcParentPath);        } catch (AccessDeniedException ade) {            throw new PathNotFoundException(srcAbsPath);        } catch (NameException e) {            String msg = srcAbsPath + ": invalid path";            log.debug(msg);            throw new RepositoryException(msg, e);        }        Path destPath;        Path.PathElement destName;        Path destParentPath;        NodeImpl destParentNode;        try {            destPath = getQPath(destAbsPath).getNormalizedPath();            if (!destPath.isAbsolute()) {                throw new RepositoryException("not an absolute path: " + destAbsPath);            }            if (srcPath.isAncestorOf(destPath)) {                String msg = destAbsPath + ": invalid destination path (cannot be descendant of source path)";                log.debug(msg);                throw new RepositoryException(msg);            }            destName = destPath.getNameElement();            destParentPath = destPath.getAncestor(1);            destParentNode = (NodeImpl) getItemManager().getItem(destParentPath);        } catch (AccessDeniedException ade) {            throw new PathNotFoundException(destAbsPath);        } catch (NameException e) {            String msg = destAbsPath + ": invalid path";            log.debug(msg);            throw new RepositoryException(msg, e);        }        int ind = destName.getIndex();        if (ind > 0) {            // subscript in name element            String msg = destAbsPath + ": invalid destination path (subscript in name element is not allowed)";            log.debug(msg);            throw new RepositoryException(msg);        }        // verify that both source and destination parent nodes are checked-out        if (!srcParentNode.internalIsCheckedOut()) {            String msg = srcAbsPath + ": cannot move a child of a checked-in node";            log.debug(msg);            throw new VersionException(msg);        }        if (!destParentNode.internalIsCheckedOut()) {            String msg = destAbsPath + ": cannot move a target to a checked-in node";            log.debug(msg);            throw new VersionException(msg);        }        // check for name collisions        ItemImpl existing = null;        try {            existing = getItemManager().getItem(destPath);            if (!existing.isNode()) {                // there's already a property with that name                throw new ItemExistsException(existing.safeGetJCRPath());            } else {                // there's already a node with that name:                // check same-name sibling setting of existing node                if (!((NodeImpl) existing).getDefinition().allowsSameNameSiblings()) {                    throw new ItemExistsException(existing.safeGetJCRPath());                }            }        } catch (AccessDeniedException ade) {            // FIXME by throwing ItemExistsException we're disclosing too much information            throw new ItemExistsException(destAbsPath);        } catch (PathNotFoundException pnfe) {            // no name collision since same-name siblings are allowed        }        // check constraints        // get applicable definition of target node at new location        NodeTypeImpl nt = (NodeTypeImpl) targetNode.getPrimaryNodeType();        NodeDefinitionImpl newTargetDef;        try {            newTargetDef = destParentNode.getApplicableChildNodeDefinition(destName.getName(), nt.getQName());        } catch (RepositoryException re) {            String msg = destAbsPath + ": no definition found in parent node's node type for new node";            log.debug(msg);            throw new ConstraintViolationException(msg, re);        }        // if there's already a node with that name also check same-name sibling        // setting of new node; just checking same-name sibling setting on        // existing node is not sufficient since same-name sibling nodes don't        // necessarily have identical definitions        if (existing != null && !newTargetDef.allowsSameNameSiblings()) {            throw new ItemExistsException(existing.safeGetJCRPath());        }        // check protected flag of old & new parent        if (destParentNode.getDefinition().isProtected()) {            String msg = destAbsPath + ": cannot add a child node to a protected node";            log.debug(msg);            throw new ConstraintViolationException(msg);        }        if (srcParentNode.getDefinition().isProtected()) {            String msg = srcAbsPath + ": cannot remove a child node from a protected node";            log.debug(msg);            throw new ConstraintViolationException(msg);        }        // check lock status        srcParentNode.checkLock();        destParentNode.checkLock();        NodeId targetId = targetNode.getNodeId();        int index = srcName.getIndex();        if (index == 0) {            index = 1;        }        if (srcParentNode.isSame(destParentNode)) {            // do rename            destParentNode.renameChildNode(srcName.getName(), index, targetId, destName.getName());        } else {            // do move:            // 1. remove child node entry from old parent            NodeState srcParentState =                    (NodeState) srcParentNode.getOrCreateTransientItemState();            srcParentState.removeChildNodeEntry(srcName.getName(), index);            // 2. re-parent target node            NodeState targetState =                    (NodeState) targetNode.getOrCreateTransientItemState();            targetState.setParentId(destParentNode.getNodeId());            // 3. add child node entry to new parent            NodeState destParentState =                    (NodeState) destParentNode.getOrCreateTransientItemState();            destParentState.addChildNodeEntry(destName.getName(), targetId);        }        // change definition of target        targetNode.onRedefine(newTargetDef.unwrap().getId());    }    /**     * {@inheritDoc}     */    public ContentHandler getImportContentHandler(String parentAbsPath,                                                  int uuidBehavior)            throws PathNotFoundException, ConstraintViolationException,            VersionException, LockException, RepositoryException {        // check sanity of this session        sanityCheck();        Item item;        try {            Path p = getQPath(parentAbsPath).getNormalizedPath();            if (!p.isAbsolute()) {                throw new RepositoryException("not an absolute path: " + parentAbsPath);            }            item = getItemManager().getItem(p);        } catch (NameException e) {            String msg = parentAbsPath + ": invalid path";            log.debug(msg);            throw new RepositoryException(msg, e);        } catch (AccessDeniedException ade) {            throw new PathNotFoundException(parentAbsPath);        }        if (!item.isNode()) {            throw new PathNotFoundException(parentAbsPath);        }        NodeImpl parent = (NodeImpl) item;        // verify that parent node is checked-out        if (!parent.internalIsCheckedOut()) {            String msg = parentAbsPath + ": cannot add a child to a checked-in node";            log.debug(msg);            throw new VersionException(msg);        }        // check protected flag of parent node        if (parent.getDefinition().isProtected()) {            String msg = parentAbsPath + ": cannot add a child to a protected node";            log.debug(msg);            throw new ConstraintViolationException(msg);        }        // check lock status        parent.checkLock();        SessionImporter importer = new SessionImporter(parent, this, uuidBehavior);

⌨️ 快捷键说明

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