batcheditemoperations.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 1,596 行 · 第 1/5 页
JAVA
1,596 行
QName nodeTypeName, QName[] mixinNames, NodeId id) throws ItemExistsException, ConstraintViolationException, RepositoryException, IllegalStateException { // check precondition if (!stateMgr.inEditMode()) { throw new IllegalStateException("not in edit mode"); } NodeDef def = findApplicableNodeDefinition(nodeName, nodeTypeName, parent); return createNodeState(parent, nodeName, nodeTypeName, mixinNames, id, def); } /** * Creates a new node based on the given definition. * <p/> * Note that access rights are <b><i>not</i></b> enforced! * <p/> * <b>Precondition:</b> the state manager needs to be in edit mode. * * @param parent * @param nodeName * @param nodeTypeName * @param mixinNames * @param id * @param def * @return * @throws ItemExistsException * @throws ConstraintViolationException * @throws RepositoryException * @throws IllegalStateException */ public NodeState createNodeState(NodeState parent, QName nodeName, QName nodeTypeName, QName[] mixinNames, NodeId id, NodeDef def) throws ItemExistsException, ConstraintViolationException, RepositoryException, IllegalStateException { // check for name collisions with existing properties if (parent.hasPropertyName(nodeName)) { String msg = "there's already a property with name " + nodeName; log.debug(msg); throw new RepositoryException(msg); } // check for name collisions with existing nodes if (!def.allowsSameNameSiblings() && parent.hasChildNodeEntry(nodeName)) { NodeId errorId = parent.getChildNodeEntry(nodeName, 1).getId(); throw new ItemExistsException(safeGetJCRPath(errorId)); } if (id == null) { // create new id id = new NodeId(UUID.randomUUID()); } if (nodeTypeName == null) { // no primary node type specified, // try default primary type from definition nodeTypeName = def.getDefaultPrimaryType(); if (nodeTypeName == null) { String msg = "an applicable node type could not be determined for " + nodeName; log.debug(msg); throw new ConstraintViolationException(msg); } } NodeState node = stateMgr.createNew(id, nodeTypeName, parent.getNodeId()); if (mixinNames != null && mixinNames.length > 0) { node.setMixinTypeNames(new HashSet(Arrays.asList(mixinNames))); } node.setDefinitionId(def.getId()); // now add new child node entry to parent parent.addChildNodeEntry(nodeName, id); EffectiveNodeType ent = getEffectiveNodeType(node); if (!node.getMixinTypeNames().isEmpty()) { // create jcr:mixinTypes property PropDef pd = ent.getApplicablePropertyDef(QName.JCR_MIXINTYPES, PropertyType.NAME, true); createPropertyState(node, pd.getName(), pd.getRequiredType(), pd); } // add 'auto-create' properties defined in node type PropDef[] pda = ent.getAutoCreatePropDefs(); for (int i = 0; i < pda.length; i++) { PropDef pd = pda[i]; createPropertyState(node, pd.getName(), pd.getRequiredType(), pd); } // recursively add 'auto-create' child nodes defined in node type NodeDef[] nda = ent.getAutoCreateNodeDefs(); for (int i = 0; i < nda.length; i++) { NodeDef nd = nda[i]; createNodeState(node, nd.getName(), nd.getDefaultPrimaryType(), null, null, nd); } // store node stateMgr.store(node); // store parent stateMgr.store(parent); return node; } /** * Creates a new property. * <p/> * Note that access rights are <b><i>not</i></b> enforced! * <p/> * <b>Precondition:</b> the state manager needs to be in edit mode. * * @param parent * @param propName * @param type * @param numValues * @return * @throws ItemExistsException * @throws ConstraintViolationException * @throws RepositoryException * @throws IllegalStateException if the state mananger is not in edit mode */ public PropertyState createPropertyState(NodeState parent, QName propName, int type, int numValues) throws ItemExistsException, ConstraintViolationException, RepositoryException, IllegalStateException { // check precondition if (!stateMgr.inEditMode()) { throw new IllegalStateException("not in edit mode"); } // find applicable definition PropDef def; // multi- or single-valued property? if (numValues == 1) { // could be single- or multi-valued (n == 1) try { // try single-valued def = findApplicablePropertyDefinition(propName, type, false, parent); } catch (ConstraintViolationException cve) { // try multi-valued def = findApplicablePropertyDefinition(propName, type, true, parent); } } else { // can only be multi-valued (n == 0 || n > 1) def = findApplicablePropertyDefinition(propName, type, true, parent); } return createPropertyState(parent, propName, type, def); } /** * Creates a new property based on the given definition. * <p/> * Note that access rights are <b><i>not</i></b> enforced! * <p/> * <b>Precondition:</b> the state manager needs to be in edit mode. * * @param parent * @param propName * @param type * @param def * @return * @throws ItemExistsException * @throws RepositoryException */ public PropertyState createPropertyState(NodeState parent, QName propName, int type, PropDef def) throws ItemExistsException, RepositoryException { // check for name collisions with existing child nodes if (parent.hasChildNodeEntry(propName)) { String msg = "there's already a child node with name " + propName; log.debug(msg); throw new RepositoryException(msg); } // check for name collisions with existing properties if (parent.hasPropertyName(propName)) { PropertyId errorId = new PropertyId(parent.getNodeId(), propName); throw new ItemExistsException(safeGetJCRPath(errorId)); } // create property PropertyState prop = stateMgr.createNew(propName, parent.getNodeId()); prop.setDefinitionId(def.getId()); if (def.getRequiredType() != PropertyType.UNDEFINED) { prop.setType(def.getRequiredType()); } else if (type != PropertyType.UNDEFINED) { prop.setType(type); } else { prop.setType(PropertyType.STRING); } prop.setMultiValued(def.isMultiple()); // compute system generated values if necessary InternalValue[] genValues = computeSystemGeneratedPropertyValues(parent, def); if (genValues != null) { prop.setValues(genValues); } else if (def.getDefaultValues() != null) { prop.setValues(def.getDefaultValues()); } // now add new property entry to parent parent.addPropertyName(propName); // store parent stateMgr.store(parent); return prop; } /** * Unlinks the specified node state from its parent and recursively * removes it including its properties and child nodes. * <p/> * Note that no checks (access rights etc.) are performed on the specified * target node state. Those checks have to be performed beforehand by the * caller. However, the (recursive) removal of target node's child nodes are * subject to the following checks: access rights, locking, versioning. * * @param target * @throws RepositoryException if an error occurs */ public void removeNodeState(NodeState target) throws RepositoryException { NodeId parentId = target.getParentId(); if (parentId == null) { String msg = "root node cannot be removed"; log.debug(msg); throw new RepositoryException(msg); } // remove target recursiveRemoveNodeState(target); // remove child node entry from parent NodeState parent = getNodeState(parentId); parent.removeChildNodeEntry(target.getNodeId()); // store parent stateMgr.store(parent); } /** * Retrieves the state of the node at the given path. * <p/> * Note that access rights are <b><i>not</i></b> enforced! * * @param nodePath * @return * @throws PathNotFoundException * @throws RepositoryException */ public NodeState getNodeState(Path nodePath) throws PathNotFoundException, RepositoryException { return getNodeState(stateMgr, hierMgr, nodePath); } /** * Retrieves the state of the node with the given id. * <p/> * Note that access rights are <b><i>not</i></b> enforced! * * @param id * @return * @throws ItemNotFoundException * @throws RepositoryException */ public NodeState getNodeState(NodeId id) throws ItemNotFoundException, RepositoryException { return (NodeState) getItemState(stateMgr, id); } /** * Retrieves the state of the property with the given id. * <p/> * Note that access rights are <b><i>not</i></b> enforced! * * @param id * @return * @throws ItemNotFoundException * @throws RepositoryException */ public PropertyState getPropertyState(PropertyId id) throws ItemNotFoundException, RepositoryException { return (PropertyState) getItemState(stateMgr, id); } /** * Retrieves the state of the item with the given id. * <p/> * Note that access rights are <b><i>not</i></b> enforced! * * @param id * @return * @throws ItemNotFoundException * @throws RepositoryException */ public ItemState getItemState(ItemId id) throws ItemNotFoundException, RepositoryException { return getItemState(stateMgr, id); } //----------------------------------------------------< protected methods > /** * Verifies that the node at <code>nodePath</code> is checked-out; throws a * <code>VersionException</code> if that's not the case. * <p/> * A node is considered <i>checked-out</i> if it is versionable and
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?