nodeimpl.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 1,586 行 · 第 1/5 页
JAVA
1,586 行
// mix:referenceable node type if (name.equals(QName.JCR_UUID)) { // jcr:uuid property genValues = new InternalValue[]{ InternalValue.create(thisState.getNodeId().getUUID().toString()) }; }/* todo consolidate version history creation code (currently in ItemImpl.initVersionHistories) } else if (nt.getQName().equals(MIX_VERSIONABLE)) { // mix:versionable node type VersionHistory hist = session.getVersionManager().getOrCreateVersionHistory(this); if (name.equals(JCR_VERSIONHISTORY)) { // jcr:versionHistory property genValues = new InternalValue[]{InternalValue.create(new UUID(hist.getUUID()))}; } else if (name.equals(JCR_BASEVERSION)) { // jcr:baseVersion property genValues = new InternalValue[]{InternalValue.create(new UUID(hist.getRootVersion().getUUID()))}; } else if (name.equals(JCR_ISCHECKEDOUT)) { // jcr:isCheckedOut property genValues = new InternalValue[]{InternalValue.create(true)}; } else if (name.equals(JCR_PREDECESSORS)) { // jcr:predecessors property genValues = new InternalValue[]{InternalValue.create(new UUID(hist.getRootVersion().getUUID()))}; }*/ } else if (nt.getQName().equals(QName.NT_HIERARCHYNODE)) { // nt:hierarchyNode node type if (name.equals(QName.JCR_CREATED)) { // jcr:created property genValues = new InternalValue[]{InternalValue.create(Calendar.getInstance())}; } } else if (nt.getQName().equals(QName.NT_RESOURCE)) { // nt:resource node type if (name.equals(QName.JCR_LASTMODIFIED)) { // jcr:lastModified property genValues = new InternalValue[]{InternalValue.create(Calendar.getInstance())}; } } else if (nt.getQName().equals(QName.NT_VERSION)) { // nt:version node type if (name.equals(QName.JCR_CREATED)) { // jcr:created property genValues = new InternalValue[]{InternalValue.create(Calendar.getInstance())}; } } else if (nt.getQName().equals(QName.NT_BASE)) { // nt:base node type if (name.equals(QName.JCR_PRIMARYTYPE)) { // jcr:primaryType property genValues = new InternalValue[]{InternalValue.create(primaryTypeName)}; } else if (name.equals(QName.JCR_MIXINTYPES)) { // jcr:mixinTypes property Set mixins = thisState.getMixinTypeNames(); ArrayList values = new ArrayList(mixins.size()); Iterator iter = mixins.iterator(); while (iter.hasNext()) { values.add(InternalValue.create((QName) iter.next())); } genValues = (InternalValue[]) values.toArray(new InternalValue[values.size()]); } } return genValues; } /** * @param name * @param type * @param multiValued * @param exactTypeMatch * @param status * @return * @throws ConstraintViolationException if no applicable property definition * could be found * @throws RepositoryException if another error occurs */ protected PropertyImpl getOrCreateProperty(String name, int type, boolean multiValued, boolean exactTypeMatch, BitSet status) throws ConstraintViolationException, RepositoryException { try { return getOrCreateProperty( session.getQName(name), type, multiValued, exactTypeMatch, status); } catch (NameException e) { throw new RepositoryException("invalid property name: " + name, e); } } /** * @param name * @param type * @param multiValued * @param exactTypeMatch * @param status * @return * @throws ConstraintViolationException if no applicable property definition * could be found * @throws RepositoryException if another error occurs */ protected synchronized PropertyImpl getOrCreateProperty(QName name, int type, boolean multiValued, boolean exactTypeMatch, BitSet status) throws ConstraintViolationException, RepositoryException { status.clear(); if (isNew() && !hasProperty(name)) { // this is a new node and the property does not exist yet // -> no need to check item manager PropertyDefinitionImpl def = getApplicablePropertyDefinition( name, type, multiValued, exactTypeMatch); PropertyImpl prop = createChildProperty(name, type, def); status.set(CREATED); return prop; } /* * Please note, that this implementation does not win a price for beauty * or speed. It's never a good idea to use exceptions for semantical * control flow. * However, compared to the previous version, this one is thread save * and makes the test/get block atomic in respect to transactional * commits. the test/set can still fail. * * Old Version: NodeState thisState = (NodeState) state; if (thisState.hasPropertyName(name)) { /** * the following call will throw ItemNotFoundException if the * current session doesn't have read access / return getProperty(name); } [...create block...] */ try { PropertyId propId = new PropertyId(getNodeId(), name); return (PropertyImpl) itemMgr.getItem(propId); } catch (AccessDeniedException ade) { throw new ItemNotFoundException(name.toString()); } catch (ItemNotFoundException e) { // does not exist yet: // find definition for the specified property and create property PropertyDefinitionImpl def = getApplicablePropertyDefinition( name, type, multiValued, exactTypeMatch); PropertyImpl prop = createChildProperty(name, type, def); status.set(CREATED); return prop; } } protected synchronized PropertyImpl createChildProperty(QName name, int type, PropertyDefinitionImpl def) throws RepositoryException { // check for name collisions with existing child nodes if (((NodeState) state).hasChildNodeEntry(name)) { String msg = "there's already a child node with name " + name; log.debug(msg); throw new RepositoryException(msg); } // create a new property state PropertyState propState; try { propState = stateMgr.createTransientPropertyState(getNodeId(), name, ItemState.STATUS_NEW); propState.setType(type); propState.setMultiValued(def.isMultiple()); propState.setDefinitionId(def.unwrap().getId()); // compute system generated values if necessary InternalValue[] genValues = computeSystemGeneratedPropertyValues(name, def); InternalValue[] defValues = def.unwrap().getDefaultValues(); if (genValues != null) { propState.setValues(genValues); } else if (defValues != null) { propState.setValues(defValues); } } catch (ItemStateException ise) { String msg = "failed to add property " + name + " to " + safeGetJCRPath(); log.debug(msg); throw new RepositoryException(msg, ise); } // create Property instance wrapping new property state PropertyImpl prop = itemMgr.createPropertyInstance(propState, def); // modify the state of 'this', i.e. the parent node NodeState thisState = (NodeState) getOrCreateTransientItemState(); // add new property entry thisState.addPropertyName(name); return prop; } protected synchronized NodeImpl createChildNode(QName name, NodeDefinitionImpl def, NodeTypeImpl nodeType, NodeId id) throws RepositoryException { // create a new node state NodeState nodeState; try { if (id == null) { id = new NodeId(UUID.randomUUID()); } nodeState = stateMgr.createTransientNodeState(id, nodeType.getQName(), getNodeId(), ItemState.STATUS_NEW); nodeState.setDefinitionId(def.unwrap().getId()); } catch (ItemStateException ise) { String msg = "failed to add child node " + name + " to " + safeGetJCRPath(); log.debug(msg); throw new RepositoryException(msg, ise); } // create Node instance wrapping new node state NodeImpl node; try { node = itemMgr.createNodeInstance(nodeState, def); } catch (RepositoryException re) { // something went wrong stateMgr.disposeTransientItemState(nodeState); // re-throw throw re; } // modify the state of 'this', i.e. the parent node NodeState thisState = (NodeState) getOrCreateTransientItemState(); // add new child node entry thisState.addChildNodeEntry(name, nodeState.getNodeId()); // add 'auto-create' properties defined in node type PropertyDefinition[] pda = nodeType.getAutoCreatedPropertyDefinitions(); for (int i = 0; i < pda.length; i++) { PropertyDefinitionImpl pd = (PropertyDefinitionImpl) pda[i]; node.createChildProperty(pd.getQName(), pd.getRequiredType(), pd); } // recursively add 'auto-create' child nodes defined in node type NodeDefinition[] nda = nodeType.getAutoCreatedNodeDefinitions(); for (int i = 0; i < nda.length; i++) { NodeDefinitionImpl nd = (NodeDefinitionImpl) nda[i]; node.createChildNode(nd.getQName(), nd, (NodeTypeImpl) nd.getDefaultPrimaryType(), null); } return node; } protected void renameChildNode(QName oldName, int index, NodeId id, QName newName) throws RepositoryException { // modify the state of 'this', i.e. the parent node NodeState thisState = (NodeState) getOrCreateTransientItemState(); thisState.renameChildNodeEntry(oldName, index, newName); } protected void removeChildProperty(String propName) throws RepositoryException { try { removeChildProperty(session.getQName(propName)); } catch (NameException e) { throw new RepositoryException( "invalid property name: " + propName, e); } } protected void removeChildProperty(QName propName) throws RepositoryException { // modify the state of 'this', i.e. the parent node NodeState thisState = (NodeState) getOrCreateTransientItemState(); // remove the property entry if (!thisState.removePropertyName(propName)) { String msg = "failed to remove property " + propName + " of " + safeGetJCRPath(); log.debug(msg); throw new RepositoryException(msg); } // remove property PropertyId propId = new PropertyId(thisState.getNodeId(), propName); itemMgr.getItem(propId).setRemoved(); } protected void removeChildNode(QName nodeName, int index) throws RepositoryException { // modify the state of 'this', i.e. the parent node NodeState thisState = (NodeState) getOrCreateTransientItemState(); if (index == 0) { index = 1; } NodeState.ChildNodeEntry entry = thisState.getChildNodeEntry(nodeName, index); if (entry == null) { String msg = "failed to remove child " + nodeName + " of " + safeGetJCRPath(); log.debug(msg); throw new RepositoryException(msg); } // notify target of removal NodeId childId = entry.getId(); NodeImpl childNode = (NodeImpl) itemMgr.getItem(childId); childNode.onRemove(); // remove the child node entry if (!thisState.removeChildNodeEntry(nodeName, index)) { String msg = "failed to remove child " + nodeName + " of " + safeGetJCRPath(); log.debug(msg); throw new RepositoryException(msg);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?