@Override public NodeType[] getSupertypes() { Map<String, NodeType> supertypes = Maps.newLinkedHashMap(); addSupertypes(definition, supertypes); return supertypes.values().toArray(NO_NODE_TYPES); }
@Override public boolean isMixin() { return getBoolean(JCR_ISMIXIN); }
@Override public boolean canRemoveItem(String itemName) { List<ItemDefinition> definitions = Lists.newArrayList(); definitions.addAll(Arrays.asList(getChildNodeDefinitions())); definitions.addAll(Arrays.asList(getPropertyDefinitions())); return internalCanRemoveItem(itemName, definitions); }
@Override public boolean canRemoveNode(String nodeName) { return internalCanRemoveItem(nodeName, Arrays.asList(getChildNodeDefinitions())); }
Collection<NodeDefinition> internalGetChildDefinitions() { // TODO distinguish between additive and overriding node definitions. See 3.7.6.8 Item Definitions in Subtypes Collection<NodeDefinition> definitions = new ArrayList<NodeDefinition>(); definitions.addAll(Arrays.asList(getDeclaredChildNodeDefinitions())); for (NodeType type : getSupertypes()) { definitions.addAll(Arrays.asList(type.getDeclaredChildNodeDefinitions())); } return definitions; }
@Override public boolean canSetProperty(String propertyName, Value value) { if (value == null) { return canRemoveProperty(propertyName); } try { EffectiveNodeTypeImpl effective = new EffectiveNodeTypeImpl(this, getManager()); PropertyDefinition def = effective.getPropertyDefinition( propertyName, false, value.getType(), false); return !def.isProtected() && meetsTypeConstraints(value, def.getRequiredType()) && meetsValueConstraints(value, def.getValueConstraints()); } catch (RepositoryException e) { // TODO don't use exceptions for flow control. Use internal method in ReadOnlyNodeTypeManager instead. log.debug(e.getMessage()); 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; }
private void addSubtypes( String typeName, Map<String, NodeType> subtypes, Tree root, Map<String, Set<String>> inheritance) { Set<String> subnames = inheritance.get(typeName); if (subnames != null) { for (String subname : subnames) { if (!subtypes.containsKey(subname)) { Tree tree = root.getChild(subname); subtypes.put(subname, new NodeTypeImpl(tree, mapper)); } } } }
@Override public boolean canAddChildNode(String childNodeName) { // FIXME: properly calculate matching definition for (NodeDefinition definition : getChildNodeDefinitions()) { String name = definition.getName(); if (matches(childNodeName, name) || RESIDUAL_NAME.equals(name)) { return !definition.isProtected() && definition.getDefaultPrimaryType() != null; } } return false; }
private void addSupertypes(Tree type, Map<String, NodeType> supertypes) { PropertyState property = type.getProperty(JCR_SUPERTYPES); if (property != null) { Tree root = definition.getParent(); for (String oakName : property.getValue(Type.NAMES)) { if (!supertypes.containsKey(oakName)) { Tree supertype = root.getChild(oakName); checkState(supertype.exists()); supertypes.put( oakName, new NodeTypeImpl(supertype, mapper)); addSupertypes(supertype, supertypes); } } } }
@Override public NodeType[] getDeclaredSupertypes() { NodeType[] supertypes = NO_NODE_TYPES; String[] oakNames = getNames(JCR_SUPERTYPES); if (oakNames != null && oakNames.length > 0) { supertypes = new NodeType[oakNames.length]; Tree root = definition.getParent(); for (int i = 0; i < oakNames.length; i++) { Tree type = root.getChild(oakNames[i]); checkState(type.exists()); supertypes[i] = new NodeTypeImpl(type, mapper); } } return supertypes; }
@Override public NodeTypeIterator getDeclaredSubtypes() { List<NodeType> subtypes = Lists.newArrayList(); String oakName = getOakName(); Tree root = definition.getParent(); for (Tree child : root.getChildren()) { PropertyState supertypes = child.getProperty(JCR_SUPERTYPES); if (supertypes != null) { for (String name : supertypes.getValue(Type.NAMES)) { if (oakName.equals(name)) { subtypes.add(new NodeTypeImpl(child, mapper)); break; } } } } return new NodeTypeIteratorAdapter(subtypes); }
@Override public NodeTypeIterator getSubtypes() { Map<String, Set<String>> inheritance = Maps.newHashMap(); Tree root = definition.getParent(); for (Tree child : root.getChildren()) { String oakName = getOakName(child); PropertyState supertypes = child.getProperty(JCR_SUPERTYPES); if (supertypes != null) { for (String supername : supertypes.getValue(Type.NAMES)) { Set<String> subtypes = inheritance.get(supername); if (subtypes == null) { subtypes = Sets.newHashSet(); inheritance.put(supername, subtypes); } subtypes.add(oakName); } } } Map<String, NodeType> subtypes = Maps.newHashMap(); addSubtypes(getOakName(), subtypes, root, inheritance); return new NodeTypeIteratorAdapter(subtypes.values()); }
@Override public Iterable<NodeDefinition> apply(NodeTypeImpl input) { return input.getDeclaredNamedNodeDefinitions(oakName); } }));
/** * Return all property definitions that match the specified oak name. * * @param oakName An internal oak name. * @return All property definitions that match the given internal oak name. */ @Override @NotNull public Iterable<PropertyDefinition> getNamedPropertyDefinitions( String oakName) { List<PropertyDefinition> definitions = newArrayList(); for (NodeTypeImpl type : nodeTypes.values()) { definitions.addAll(type.getDeclaredNamedPropertyDefinitions(oakName)); } return definitions; }
@Override public boolean canSetProperty(String propertyName, Value value) { if (value == null) { return canRemoveProperty(propertyName); } try { EffectiveNodeTypeImpl effective = new EffectiveNodeTypeImpl(this, getManager()); PropertyDefinition def = effective.getPropertyDefinition( propertyName, false, value.getType(), false); return !def.isProtected() && meetsTypeConstraints(value, def.getRequiredType()) && meetsValueConstraints(value, def.getValueConstraints()); } catch (RepositoryException e) { // TODO don't use exceptions for flow control. Use internal method in ReadOnlyNodeTypeManager instead. log.debug(e.getMessage()); 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; }
private void addSubtypes( String typeName, Map<String, NodeType> subtypes, Tree root, Map<String, Set<String>> inheritance) { Set<String> subnames = inheritance.get(typeName); if (subnames != null) { for (String subname : subnames) { if (!subtypes.containsKey(subname)) { Tree tree = root.getChild(subname); subtypes.put(subname, new NodeTypeImpl(tree, mapper)); } } } }
@Override public boolean canAddChildNode(String childNodeName) { // FIXME: properly calculate matching definition for (NodeDefinition definition : getChildNodeDefinitions()) { String name = definition.getName(); if (matches(childNodeName, name) || RESIDUAL_NAME.equals(name)) { return !definition.isProtected() && definition.getDefaultPrimaryType() != null; } } return false; }