nodeimpl.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 1,586 行 · 第 1/5 页
JAVA
1,586 行
} } protected void onRedefine(NodeDefId defId) throws RepositoryException { NodeDefinitionImpl newDef = session.getNodeTypeManager().getNodeDefinition(defId); // modify the state of 'this', i.e. the target node NodeState thisState = (NodeState) getOrCreateTransientItemState(); // set id of new definition thisState.setDefinitionId(defId); definition = newDef; } protected void onRemove() throws RepositoryException { // modify the state of 'this', i.e. the target node NodeState thisState = (NodeState) getOrCreateTransientItemState(); if (thisState.hasChildNodeEntries()) { // remove child nodes // use temp array to avoid ConcurrentModificationException ArrayList tmp = new ArrayList(thisState.getChildNodeEntries()); // remove from tail to avoid problems with same-name siblings for (int i = tmp.size() - 1; i >= 0; i--) { NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) tmp.get(i); // recursively remove child node NodeId childId = entry.getId(); NodeImpl childNode = (NodeImpl) itemMgr.getItem(childId); childNode.onRemove(); // remove the child node entry thisState.removeChildNodeEntry(entry.getName(), entry.getIndex()); } } // remove properties // use temp set to avoid ConcurrentModificationException HashSet tmp = new HashSet(thisState.getPropertyNames()); for (Iterator iter = tmp.iterator(); iter.hasNext();) { QName propName = (QName) iter.next(); // remove the property entry thisState.removePropertyName(propName); // remove property PropertyId propId = new PropertyId(thisState.getNodeId(), propName); itemMgr.getItem(propId).setRemoved(); } // finally remove this node thisState.setParentId(null); itemMgr.getItem(id).setRemoved(); } protected NodeImpl internalAddNode(String relPath, NodeTypeImpl nodeType) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException { return internalAddNode(relPath, nodeType, null); } protected NodeImpl internalAddNode(String relPath, NodeTypeImpl nodeType, NodeId id) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException { Path nodePath; QName nodeName; Path parentPath; try { nodePath = Path.create(getPrimaryPath(), session.getQPath(relPath), false) .getCanonicalPath(); if (nodePath.getNameElement().getIndex() != 0) { String msg = "illegal subscript specified: " + nodePath; log.debug(msg); throw new RepositoryException(msg); } nodeName = nodePath.getNameElement().getName(); parentPath = nodePath.getAncestor(1); } catch (NameException e) { String msg = "failed to resolve path " + relPath + " relative to " + safeGetJCRPath(); log.debug(msg); throw new RepositoryException(msg, e); } NodeImpl parentNode; try { Item parent = itemMgr.getItem(parentPath); if (!parent.isNode()) { String msg = "cannot add a node to property " + parentPath; log.debug(msg); throw new ConstraintViolationException(msg); } parentNode = (NodeImpl) parent; } catch (AccessDeniedException ade) { throw new PathNotFoundException(relPath); } // make sure that parent node is checked-out if (!parentNode.internalIsCheckedOut()) { String msg = safeGetJCRPath() + ": cannot add a child to a checked-in node"; log.debug(msg); throw new VersionException(msg); } // check lock status parentNode.checkLock(); // delegate the creation of the child node to the parent node return parentNode.internalAddChildNode(nodeName, nodeType, id); } protected NodeImpl internalAddChildNode(QName nodeName, NodeTypeImpl nodeType) throws ItemExistsException, ConstraintViolationException, RepositoryException { return internalAddChildNode(nodeName, nodeType, null); } protected NodeImpl internalAddChildNode(QName nodeName, NodeTypeImpl nodeType, NodeId id) throws ItemExistsException, ConstraintViolationException, RepositoryException { Path nodePath; try { nodePath = Path.create(getPrimaryPath(), nodeName, true); } catch (MalformedPathException e) { // should never happen String msg = "internal error: invalid path " + safeGetJCRPath(); log.debug(msg); throw new RepositoryException(msg, e); } NodeDefinitionImpl def; try { QName nodeTypeName = null; if (nodeType != null) { nodeTypeName = nodeType.getQName(); } def = getApplicableChildNodeDefinition(nodeName, nodeTypeName); } catch (RepositoryException re) { String msg = "no definition found in parent node's node type for new node"; log.debug(msg); throw new ConstraintViolationException(msg, re); } if (nodeType == null) { // use default node type nodeType = (NodeTypeImpl) def.getDefaultPrimaryType(); } // check for name collisions NodeState thisState = (NodeState) state; if (thisState.hasPropertyName(nodeName)) { // there's already a property with that name throw new ItemExistsException(itemMgr.safeGetJCRPath(nodePath)); } NodeState.ChildNodeEntry cne = thisState.getChildNodeEntry(nodeName, 1); if (cne != null) { // there's already a child node entry with that name; // check same-name sibling setting of new node if (!def.allowsSameNameSiblings()) { throw new ItemExistsException(itemMgr.safeGetJCRPath(nodePath)); } // check same-name sibling setting of existing node NodeId newId = cne.getId(); if (!((NodeImpl) itemMgr.getItem(newId)).getDefinition().allowsSameNameSiblings()) { throw new ItemExistsException(itemMgr.safeGetJCRPath(nodePath)); } } // check protected flag of parent (i.e. this) node if (definition.isProtected()) { String msg = safeGetJCRPath() + ": cannot add a child to a protected node"; log.debug(msg); throw new ConstraintViolationException(msg); } // now do create the child node return createChildNode(nodeName, def, nodeType, id); } private void setMixinTypesProperty(Set mixinNames) throws RepositoryException { NodeState thisState = (NodeState) state; // get or create jcr:mixinTypes property PropertyImpl prop; if (thisState.hasPropertyName(QName.JCR_MIXINTYPES)) { prop = (PropertyImpl) itemMgr.getItem(new PropertyId(thisState.getNodeId(), QName.JCR_MIXINTYPES)); } else { // find definition for the jcr:mixinTypes property and create property PropertyDefinitionImpl def = getApplicablePropertyDefinition( QName.JCR_MIXINTYPES, PropertyType.NAME, true, true); prop = createChildProperty(QName.JCR_MIXINTYPES, PropertyType.NAME, def); } if (mixinNames.isEmpty()) { // purge empty jcr:mixinTypes property removeChildProperty(QName.JCR_MIXINTYPES); return; } // call internalSetValue for setting the jcr:mixinTypes property // to avoid checking of the 'protected' flag InternalValue[] vals = new InternalValue[mixinNames.size()]; Iterator iter = mixinNames.iterator(); int cnt = 0; while (iter.hasNext()) { vals[cnt++] = InternalValue.create((QName) iter.next()); } prop.internalSetValue(vals, PropertyType.NAME); } /** * Returns the <code>QName</code>s of this node's mixin types. * * @return a set of the <code>QName</code>s of this node's mixin types. */ public Set getMixinTypeNames() { return ((NodeState) state).getMixinTypeNames(); } /** * Returns the effective (i.e. merged and resolved) node type representation * of this node's primary and mixin node types. * * @return the effective node type * @throws RepositoryException if an error occurs */ public EffectiveNodeType getEffectiveNodeType() throws RepositoryException { return getEffectiveNodeType(((NodeState) state).getMixinTypeNames()); } /** * Small optimization to void double call for mixin types. * * @param mixins the set of mixins * @return the effective node type * @throws RepositoryException if an error occurs */ private EffectiveNodeType getEffectiveNodeType(Set mixins) throws RepositoryException { // build effective node type of mixins & primary type NodeTypeRegistry ntReg = session.getNodeTypeManager().getNodeTypeRegistry(); QName[] types = new QName[mixins.size() + 1]; mixins.toArray(types); // primary type types[types.length - 1] = primaryTypeName; try { return ntReg.getEffectiveNodeType(types); } catch (NodeTypeConflictException ntce) { String msg = "internal error: failed to build effective node type for node " + safeGetJCRPath(); log.debug(msg); throw new RepositoryException(msg, ntce); } } /** * Returns the applicable child node definition for a child node with the * specified name and node type. * * @param nodeName * @param nodeTypeName * @return * @throws ConstraintViolationException if no applicable child node definition * could be found * @throws RepositoryException if another error occurs */ protected NodeDefinitionImpl getApplicableChildNodeDefinition(QName nodeName, QName nodeTypeName) throws ConstraintViolationException, RepositoryException { NodeTypeManagerImpl ntMgr = session.getNodeTypeManager(); NodeDef cnd = getEffectiveNodeType().getApplicableChildNodeDef( nodeName, nodeTypeName, ntMgr.getNodeTypeRegistry()); return ntMgr.getNodeDefinition(cnd.getId()); } /** * Returns the applicable property definition for a property with the * specified name and type. * * @param propertyName * @param type * @param multiValued * @param exactTypeMatch * @return * @throws ConstraintViolationException if no applicable property definition * could be found * @throws RepositoryException if another error occurs */ protected PropertyDefinitionImpl getApplicablePropertyDefinition(QName propertyName, int type, boolean multiValued, boolean exactTypeMatch) throws ConstraintViolationException, RepositoryException { PropDef pd; if (exactTypeMatch || type == PropertyType.UNDEFINED) { pd = getEffectiveNodeType().getApplicablePropertyDef( propertyName, type, multiValued); } else { try { // try to find a definition with matching type first pd = getEffectiveNodeType().getApplicablePropertyDef( propertyName, type, multiValued); } catch (ConstraintViolationException cve) { // none found, now try by ignoring the type pd = getEffectiveNodeType().getApplicablePropertyDef( propertyName, PropertyType.UNDEFINED, multiValued); } } return session.getNodeTypeManager().getPropertyDefinition(pd.getId()); } protected void makePersistent() throws InvalidItemStateException { if (!isTransient()) { log.debug(safeGetJCRPath() + " (" + id + "): there's no transient state to persist"); return; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?