/** {@inheritDoc} */ public boolean isAbstract() throws RemoteException { return type.isAbstract(); }
private Collection<NodeType> getDescendentNodeTypes(NodeType nt) { Collection<NodeType> result = new HashSet<NodeType>(); NodeTypeIterator subNodeTypes = nt.getDeclaredSubtypes(); while (subNodeTypes.hasNext()) { NodeType subNodeType = subNodeTypes.nextNodeType(); if (!subNodeType.isAbstract()) { result.add(subNodeType); } result.addAll(getDescendentNodeTypes(subNodeType)); } return result; }
private Collection<NodeType> getDescendantNodeTypes(NodeType nt) { Collection<NodeType> result = new HashSet<>(); NodeTypeIterator subNodeTypes = nt.getDeclaredSubtypes(); while (subNodeTypes.hasNext()) { NodeType subNodeType = subNodeTypes.nextNodeType(); if (!subNodeType.isAbstract()) { result.add(subNodeType); } result.addAll(getDescendantNodeTypes(subNodeType)); } return result; }
private boolean isNotAbstractNodeType(final String type) { try { final NodeTypeManager nodeTypeManager = getSession().getJcrSession().getWorkspace().getNodeTypeManager(); if (nodeTypeManager.hasNodeType(type)) { return !nodeTypeManager.getNodeType(type).isAbstract(); } } catch (RepositoryException e) { log.error("Exception determining whether type " + type + " is abstract", e); } return true; } }
/** * Determines whether this effective node type supports adding * the specified mixin. * @param mixin name of mixin type * @return {@code true} if the mixin type is supported, otherwise {@code false} */ @Override public boolean supportsMixin(String mixin) { if (includesNodeType(mixin)) { return true; } NodeType mixinType = null; try { mixinType = ntMgr.internalGetNodeType(mixin); if (!mixinType.isMixin() || mixinType.isAbstract()) { return false; } } catch (NoSuchNodeTypeException e) { log.debug("Unknown mixin type " + mixin); } return true; }
/** * Determines whether this effective node type supports adding * the specified mixin. * @param mixin name of mixin type * @return {@code true} if the mixin type is supported, otherwise {@code false} */ @Override public boolean supportsMixin(String mixin) { if (includesNodeType(mixin)) { return true; } NodeType mixinType = null; try { mixinType = ntMgr.internalGetNodeType(mixin); if (!mixinType.isMixin() || mixinType.isAbstract()) { return false; } } catch (NoSuchNodeTypeException e) { log.debug("Unknown mixin type " + mixin); } return true; }
/** * Determines whether this effective node type supports adding * the specified mixin. * @param mixin name of mixin type * @return {@code true} if the mixin type is supported, otherwise {@code false} */ @Override public boolean supportsMixin(String mixin) { if (includesNodeType(mixin)) { return true; } NodeType mixinType = null; try { mixinType = ntMgr.internalGetNodeType(mixin); if (!mixinType.isMixin() || mixinType.isAbstract()) { return false; } } catch (NoSuchNodeTypeException e) { log.debug("Unknown mixin type " + mixin); } return true; }
/** * Tests if addNode() throws a ConstraintViolationException in case * of an abstract node type. */ public void testAbstractNodeType() throws RepositoryException { NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager(); NodeTypeIterator nts = ntMgr.getPrimaryNodeTypes(); while (nts.hasNext()) { NodeType nt = nts.nextNodeType(); if (nt.isAbstract()) { try { testRootNode.addNode(nodeName1, nt.getName()); superuser.save(); fail("Expected ConstraintViolationException."); } catch (ConstraintViolationException e) { // correct. } finally { superuser.refresh(false); } } } }
/** * Tests if <code>Node.setPrimaryType(String)</code> throws a * <code>ConstraintViolationException</code> if the * name of a mixin type is passed */ public void testSetAbstractAsPrimaryType() throws RepositoryException { Session session = testRootNode.getSession(); NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator nts = manager.getPrimaryNodeTypes(); while (nts.hasNext()) { NodeType nt = nts.nextNodeType(); if (nt.isAbstract()) { try { Node node = testRootNode.addNode(nodeName1, testNodeType); node.setPrimaryType(nt.getName()); fail("Node.setPrimaryType(String) must throw ConstraintViolationException if the specified node type name refers to an abstract node type."); } catch (ConstraintViolationException e) { // success } finally { // reset the changes. session.refresh(false); } } } }
@Override public boolean canAddChildNode(String childNodeName, String nodeTypeName) { NodeType type; try { type = getManager().getNodeType(nodeTypeName); if (type.isAbstract()) { return false; } } catch (NoSuchNodeTypeException e) { return false; } catch (RepositoryException e) { log.warn("Unable to access node type " + nodeTypeName, e); return false; } // FIXME: properly calculate matching definition for (NodeDefinition definition : getChildNodeDefinitions()) { String name = definition.getName(); if (matches(childNodeName, name) || RESIDUAL_NAME.equals(name)) { if (definition.isProtected()) { return false; } for (String required : definition.getRequiredPrimaryTypeNames()) { if (type.isNodeType(required)) { return true; } } } } return false; }
@Override public boolean canAddChildNode(String childNodeName, String nodeTypeName) { NodeType type; try { type = getManager().getNodeType(nodeTypeName); if (type.isAbstract()) { return false; } } catch (NoSuchNodeTypeException e) { return false; } catch (RepositoryException e) { log.warn("Unable to access node type " + nodeTypeName, e); return false; } // FIXME: properly calculate matching definition for (NodeDefinition definition : getChildNodeDefinitions()) { String name = definition.getName(); if (matches(childNodeName, name) || RESIDUAL_NAME.equals(name)) { if (definition.isProtected()) { return false; } for (String required : definition.getRequiredPrimaryTypeNames()) { if (type.isNodeType(required)) { return true; } } } } return false; }
/** * Creates a new rest node type. * * @param nodeType the {@code non-null} JCR {@link NodeType}. * @param baseUrl the {@code non-null} root url, which is used to construct urls to the children and properties of the node type */ public RestNodeType( NodeType nodeType, String baseUrl ) { this.name = nodeType.getName(); this.isMixin = nodeType.isMixin(); this.isAbstract = nodeType.isAbstract(); this.isQueryable = nodeType.isQueryable(); this.hasOrderableChildNodes = nodeType.hasOrderableChildNodes(); this.superTypesLinks = new TreeSet<String>(); for (NodeType superType : nodeType.getDeclaredSupertypes()) { String superTypeLink = RestHelper.urlFrom(baseUrl, RestHelper.NODE_TYPES_METHOD_NAME, RestHelper.URL_ENCODER.encode(superType.getName())); this.superTypesLinks.add(superTypeLink); } this.subTypesLinks = new TreeSet<String>(); for (NodeTypeIterator subTypeIterator = nodeType.getDeclaredSubtypes(); subTypeIterator.hasNext(); ) { String subTypeLink = RestHelper.urlFrom(baseUrl, RestHelper.NODE_TYPES_METHOD_NAME, RestHelper.URL_ENCODER.encode(subTypeIterator.nextNodeType().getName())); this.subTypesLinks.add(subTypeLink); } this.propertyTypes = new ArrayList<RestPropertyType>(); for (PropertyDefinition propertyDefinition : nodeType.getDeclaredPropertyDefinitions()) { this.propertyTypes.add(new RestPropertyType(propertyDefinition)); } }
/** * @see javax.jcr.Node#setPrimaryType(String) */ public void setPrimaryType(String nodeTypeName) throws RepositoryException { checkStatus(); if (getNodeState().isRoot()) { String msg = "The primary type of the root node may not be changed."; log.debug(msg); throw new RepositoryException(msg); } Name ntName = getQName(nodeTypeName); if (ntName.equals(getPrimaryNodeTypeName())) { log.debug("Changing the primary type has no effect: '" + nodeTypeName + "' already is the primary node type."); return; } NodeTypeManagerImpl ntMgr = session.getNodeTypeManager(); NodeType nt = ntMgr.getNodeType(ntName); if (nt.isMixin() || nt.isAbstract()) { throw new ConstraintViolationException("Cannot change the primary type: '" + nodeTypeName + "' is a mixin type or abstract."); } // perform the operation Operation op = SetPrimaryType.create(getNodeState(), ntName); session.getSessionItemStateManager().execute(op); }
/** * @see javax.jcr.Node#setPrimaryType(String) */ public void setPrimaryType(String nodeTypeName) throws RepositoryException { checkStatus(); if (getNodeState().isRoot()) { String msg = "The primary type of the root node may not be changed."; log.debug(msg); throw new RepositoryException(msg); } Name ntName = getQName(nodeTypeName); if (ntName.equals(getPrimaryNodeTypeName())) { log.debug("Changing the primary type has no effect: '" + nodeTypeName + "' already is the primary node type."); return; } NodeTypeManagerImpl ntMgr = session.getNodeTypeManager(); NodeType nt = ntMgr.getNodeType(ntName); if (nt.isMixin() || nt.isAbstract()) { throw new ConstraintViolationException("Cannot change the primary type: '" + nodeTypeName + "' is a mixin type or abstract."); } // perform the operation Operation op = SetPrimaryType.create(getNodeState(), ntName); session.getSessionItemStateManager().execute(op); }
private EffectiveNodeTypeImpl loadEffectiveNodeType(NodeType nodeType) throws RepositoryException { EffectiveNodeTypeImpl ent = types.get(nodeType.getName()); if (ent == null) { ent = new EffectiveNodeTypeImpl(nodeType.getName(), version); ent.setMixin(nodeType.isMixin()); ent.setAbstract(nodeType.isAbstract()); ent.setOrdered(nodeType.hasOrderableChildNodes()); ent.setPrimaryItemName(nodeType.getPrimaryItemName()); types.put(ent.getName(), ent); // ensure all super types are also loaded for (NodeType superType : nodeType.getSupertypes()) { ent.getSuperTypes().add(loadEffectiveNodeType(superType).getName()); } loadChildNodeDefinitions(nodeType, ent); loadPropertyDefinitions(nodeType, ent); } return ent; }
private void internalSetPrimaryType(final String nodeTypeName) throws RepositoryException { // TODO: figure out the right place for this check NodeType nt = getNodeTypeManager().getNodeType(nodeTypeName); // throws on not found if (nt.isAbstract() || nt.isMixin()) { throw new ConstraintViolationException(getNodePath()); } // TODO: END PropertyState state = PropertyStates.createProperty( JCR_PRIMARYTYPE, getOakName(nodeTypeName), NAME); dlg.setProperty(state, true, true); dlg.setOrderableChildren(nt.hasOrderableChildNodes()); }
private void internalSetPrimaryType(final String nodeTypeName) throws RepositoryException { // TODO: figure out the right place for this check NodeType nt = getNodeTypeManager().getNodeType(nodeTypeName); // throws on not found if (nt.isAbstract() || nt.isMixin()) { throw new ConstraintViolationException(getNodePath()); } // TODO: END PropertyState state = PropertyStates.createProperty( JCR_PRIMARYTYPE, getOakName(nodeTypeName), NAME); dlg.setProperty(state, true, true); dlg.setOrderableChildren(nt.hasOrderableChildNodes()); }
private void internalSetPrimaryType(final String nodeTypeName) throws RepositoryException { // TODO: figure out the right place for this check NodeType nt = getNodeTypeManager().getNodeType(nodeTypeName); // throws on not found if (nt.isAbstract() || nt.isMixin()) { throw new ConstraintViolationException(getNodePath()); } // TODO: END PropertyState state = PropertyStates.createProperty( JCR_PRIMARYTYPE, getOakName(nodeTypeName), NAME); dlg.setProperty(state, true, true); dlg.setOrderableChildren(nt.hasOrderableChildNodes()); }
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code> * returns true if <code>childNodeName</code> does not match the <code>NodeDef</code> * but <code>nodeTypeName</code> matches the node type of a residual <code>NodeDef</code>. */ public void testResidualAndLegalType() throws NotExecutableException, RepositoryException { String type = null; NodeType nodeType = null; for (NodeDefinition nodeDef : NodeTypeUtil.locateAllChildNodeDef( session, false, false, true)) { for (NodeType nt : nodeDef.getRequiredPrimaryTypes()) { if (!nt.isAbstract()) { nodeType = nodeDef.getDeclaringNodeType(); type = nt.getName(); } } } if (nodeType == null || type == null) { throw new NotExecutableException( "No testable residual child node def."); } String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType); assertTrue("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return true for a not defined childNodeName if nodeTypeName " + "matches the type of a residual child node def", nodeType.canAddChildNode(undefinedName, type)); }
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code> * returns false if <code>nodeTypeName</code> represents an abstract node type. */ public void testCanAddAbstractType() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false); if (nodeDef == null) { throw new NotExecutableException("No testable node type found."); } NodeType nodeType = nodeDef.getDeclaringNodeType(); String childNodeName = nodeDef.getName(); String abstractName = null; NodeTypeIterator it = manager.getPrimaryNodeTypes(); while (it.hasNext() && abstractName == null) { NodeType nt = it.nextNodeType(); if (nt.isAbstract()) { abstractName = nt.getName(); } } if (abstractName == null) { throw new NotExecutableException("No abstract type found."); } assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if nodeTypeName represents an abstract node type.", nodeType.canAddChildNode(childNodeName, abstractName)); } /**