/** * Determine if the {@link #getPrimaryType() primary type} or any of the {@link #getMixinTypes() mixin types} of the changed * node exactly matches at least one of the supplied node types. * * @param nodeTypeName the name of the node types to be considered; may not be null * @param nodeTypes the immutable snapshot of node types; may not be null * @return true if the changed node is of the supplied node type or one of its supertypes, or false if none match */ public boolean isType( Name nodeTypeName, NodeTypes nodeTypes ) { return nodeTypes.isTypeOrSubtype(types, nodeTypeName); }
/** * Determine if the {@link #getPrimaryType() primary type} or any of the {@link #getMixinTypes() mixin types} of the changed * node exactly matches at least one of the supplied node types. * * @param nodeTypeName the name of the node types to be considered; may not be null * @param nodeTypes the immutable snapshot of node types; may not be null * @return true if the changed node is of the supplied node type or one of its supertypes, or false if none match */ public boolean isType( Name nodeTypeName, NodeTypes nodeTypes ) { return nodeTypes.isTypeOrSubtype(types, nodeTypeName); }
/** * Determine whether at least one of the node's given node types matches or extends the node type with the supplied name. * * @param nodeTypeNames the names of the node types of a node; may not be null * @param candidateSupertypeName the name of the potential supertype node type; may not be null * @return true if the node type does extend or match the node type given by at least one of the supplied names, or false * otherwise */ public boolean isTypeOrSubtype( Set<Name> nodeTypeNames, Name candidateSupertypeName ) { for (Name nodeTypeName : nodeTypeNames) { if (isTypeOrSubtype(nodeTypeName, candidateSupertypeName)) return true; } return false; }
/** * Determine whether at least one of the node's given node types matches or extends the node type with the supplied name. * * @param nodeTypeNames the names of the node types of a node; may not be null * @param candidateSupertypeName the name of the potential supertype node type; may not be null * @return true if the node type does extend or match the node type given by at least one of the supplied names, or false * otherwise */ public boolean isTypeOrSubtype( Set<Name> nodeTypeNames, Name candidateSupertypeName ) { for (Name nodeTypeName : nodeTypeNames) { if (isTypeOrSubtype(nodeTypeName, candidateSupertypeName)) return true; } return false; }
/** * Determine whether at least one of the node's given node types matches or extends the node type with the supplied name. * * @param nodeTypeNames the names of the node types of a node; may not be null * @param candidateSupertypeName the name of the potential supertype node type; may not be null * @return true if the node type does extend or match the node type given by at least one of the supplied names, or false * otherwise */ public boolean isTypeOrSubtype( Name[] nodeTypeNames, Name candidateSupertypeName ) { for (Name nodeTypeName : nodeTypeNames) { if (isTypeOrSubtype(nodeTypeName, candidateSupertypeName)) return true; } return false; }
/** * Determine whether at least one of the node's given node types matches or extends the node type with the supplied name. * * @param nodeTypeNames the names of the node types of a node; may not be null * @param candidateSupertypeName the name of the potential supertype node type; may not be null * @return true if the node type does extend or match the node type given by at least one of the supplied names, or false * otherwise */ public boolean isTypeOrSubtype( Name[] nodeTypeNames, Name candidateSupertypeName ) { for (Name nodeTypeName : nodeTypeNames) { if (isTypeOrSubtype(nodeTypeName, candidateSupertypeName)) return true; } return false; }
/** * Determine the length of a bucket ID for an unordered collection, based on its type and possible mixins. * * @param nodeTypeName the primary type of the collection; may not be null. * @param mixinTypes the mixin type names; may be null or empty * @return the order of magnitude, as a power of 16 */ public int getBucketIdLengthForUnorderedCollection( Name nodeTypeName, Set<Name> mixinTypes ) { Set<Name> allTypes = new LinkedHashSet<>(); allTypes.add(nodeTypeName); if (mixinTypes != null && !mixinTypes.isEmpty()) { allTypes.addAll(mixinTypes); } for (Name typeName : allTypes) { if (isTypeOrSubtype(typeName, ModeShapeLexicon.TINY_UNORDERED_COLLECTION)) { return 1; } else if (isTypeOrSubtype(typeName, ModeShapeLexicon.SMALL_UNORDERED_COLLECTION)) { return 2; } else if (isTypeOrSubtype(typeName, ModeShapeLexicon.LARGE_UNORDERED_COLLECTION)) { return 3; } else if (isTypeOrSubtype(typeName, ModeShapeLexicon.HUGE_UNORDERED_COLLECTION)) { return 4; } } throw new IllegalArgumentException("None of the node types are known unordered collection types: " + allTypes); }
/** * Determine the length of a bucket ID for an unordered collection, based on its type and possible mixins. * * @param nodeTypeName the primary type of the collection; may not be null. * @param mixinTypes the mixin type names; may be null or empty * @return the order of magnitude, as a power of 16 */ public int getBucketIdLengthForUnorderedCollection( Name nodeTypeName, Set<Name> mixinTypes ) { Set<Name> allTypes = new LinkedHashSet<>(); allTypes.add(nodeTypeName); if (mixinTypes != null && !mixinTypes.isEmpty()) { allTypes.addAll(mixinTypes); } for (Name typeName : allTypes) { if (isTypeOrSubtype(typeName, ModeShapeLexicon.TINY_UNORDERED_COLLECTION)) { return 1; } else if (isTypeOrSubtype(typeName, ModeShapeLexicon.SMALL_UNORDERED_COLLECTION)) { return 2; } else if (isTypeOrSubtype(typeName, ModeShapeLexicon.LARGE_UNORDERED_COLLECTION)) { return 3; } else if (isTypeOrSubtype(typeName, ModeShapeLexicon.HUGE_UNORDERED_COLLECTION)) { return 4; } } throw new IllegalArgumentException("None of the node types are known unordered collection types: " + allTypes); }
private void collectNodeType( StaticOperand operand ) { if (operand instanceof Literal) { // Get the literal value, which should be a node type ... Literal literal = (Literal)operand; String nodeType = strings.create(literal.value()); Name nodeTypeName = nameFactory.create(nodeType); boolean shouldAddNodeType = true; // we should only keep the type if it's a super-type because the ReplaceViews rule could have added all // subtypes in the types constraints as well and index matching should be done based on strict type matching for (Iterator<String> nodeTypesIterator = nodeTypeNames.iterator(); nodeTypesIterator.hasNext();) { String collectedType = nodeTypesIterator.next(); Name collectedNodeTypeName = nameFactory.create(collectedType); // check if we haven't already added a super type, in which case we won't be adding the sub type if (nodeTypes.isTypeOrSubtype(nodeTypeName, collectedNodeTypeName)) { shouldAddNodeType = false; break; } else if (nodeTypes.isTypeOrSubtype(collectedNodeTypeName, nodeTypeName)) { // we've already collected a subtype of the type so we'll remove it from the list because // we should only be keeping super-types nodeTypesIterator.remove(); } } if (shouldAddNodeType) { nodeTypeNames.add(nodeType); } } } });
private void collectNodeType( StaticOperand operand ) { if (operand instanceof Literal) { // Get the literal value, which should be a node type ... Literal literal = (Literal)operand; String nodeType = strings.create(literal.value()); Name nodeTypeName = nameFactory.create(nodeType); boolean shouldAddNodeType = true; // we should only keep the type if it's a super-type because the ReplaceViews rule could have added all // subtypes in the types constraints as well and index matching should be done based on strict type matching for (Iterator<String> nodeTypesIterator = nodeTypeNames.iterator(); nodeTypesIterator.hasNext();) { String collectedType = nodeTypesIterator.next(); Name collectedNodeTypeName = nameFactory.create(collectedType); // check if we haven't already added a super type, in which case we won't be adding the sub type if (nodeTypes.isTypeOrSubtype(nodeTypeName, collectedNodeTypeName)) { shouldAddNodeType = false; break; } else if (nodeTypes.isTypeOrSubtype(collectedNodeTypeName, nodeTypeName)) { // we've already collected a subtype of the type so we'll remove it from the list because // we should only be keeping super-types nodeTypesIterator.remove(); } } if (shouldAddNodeType) { nodeTypeNames.add(nodeType); } } } });
/** * Determine whether this node's primary type or any of the mixins are or extend the node type with the supplied name. This * method is semantically equivalent to but slightly more efficient than the {@link #isNodeType(String) equivalent in the JCR * API}, especially when the node type name is already a {@link Name} object. * * @param nodeTypeName the name of the node type * @return true if this node is of the node type given by the supplied name, or false otherwise * @throws RepositoryException if there is an exception */ public final boolean isNodeType( Name nodeTypeName ) throws RepositoryException { checkSession(); SessionCache cache = sessionCache(); NodeTypes nodeTypes = session().nodeTypes(); try { CachedNode node = node(); // Check the primary type ... Name primaryTypeName = node.getPrimaryType(cache); if (nodeTypes.isTypeOrSubtype(primaryTypeName, nodeTypeName)) return true; // Check the mixins ... Set<Name> mixinTypes = node.getMixinTypes(cache); if (nodeTypes.isTypeOrSubtype(mixinTypes, nodeTypeName)) return true; } catch (ItemNotFoundException e) { // The node has been removed, so do nothing } return false; }
/** * Determine whether this node's primary type or any of the mixins are or extend the node type with the supplied name. This * method is semantically equivalent to but slightly more efficient than the {@link #isNodeType(String) equivalent in the JCR * API}, especially when the node type name is already a {@link Name} object. * * @param nodeTypeName the name of the node type * @return true if this node is of the node type given by the supplied name, or false otherwise * @throws RepositoryException if there is an exception */ public final boolean isNodeType( Name nodeTypeName ) throws RepositoryException { checkSession(); SessionCache cache = sessionCache(); NodeTypes nodeTypes = session().nodeTypes(); try { CachedNode node = node(); // Check the primary type ... Name primaryTypeName = node.getPrimaryType(cache); if (nodeTypes.isTypeOrSubtype(primaryTypeName, nodeTypeName)) return true; // Check the mixins ... Set<Name> mixinTypes = node.getMixinTypes(cache); if (nodeTypes.isTypeOrSubtype(mixinTypes, nodeTypeName)) return true; } catch (ItemNotFoundException e) { // The node has been removed, so do nothing } return false; }
private boolean matchesType( IndexDefinition defn, IndexCostCalculator calculator, QueryContext context ) { final NodeTypes nodeTypes = context.getNodeTypes(); final NameFactory nameFactory = context.getExecutionContext().getValueFactories().getNameFactory(); // check of the node type of the index defn matches the request node type(s) from the query String indexedNodeType = defn.getNodeTypeName(); Name indexedNodeTypeName = nameFactory.create(indexedNodeType); Set<String> selectedNodeTypes = calculator.selectedNodeTypes(); assert !selectedNodeTypes.isEmpty(); for (String nodeTypeOrAlias : selectedNodeTypes) { Name selectedNodeTypeName = nameFactory.create(nodeTypeOrAlias); if (nodeTypes.isTypeOrSubtype(selectedNodeTypeName, indexedNodeTypeName)) { return true; } } return false; }
private boolean matchesType( IndexDefinition defn, IndexCostCalculator calculator, QueryContext context ) { final NodeTypes nodeTypes = context.getNodeTypes(); final NameFactory nameFactory = context.getExecutionContext().getValueFactories().getNameFactory(); // check of the node type of the index defn matches the request node type(s) from the query String indexedNodeType = defn.getNodeTypeName(); Name indexedNodeTypeName = nameFactory.create(indexedNodeType); Set<String> selectedNodeTypes = calculator.selectedNodeTypes(); assert !selectedNodeTypes.isEmpty(); for (String nodeTypeOrAlias : selectedNodeTypes) { Name selectedNodeTypeName = nameFactory.create(nodeTypeOrAlias); if (nodeTypes.isTypeOrSubtype(selectedNodeTypeName, indexedNodeTypeName)) { return true; } } return false; }
if (nodeTypes.isTypeOrSubtype(nodeTypeNames, parentPrimaryType)) { return true; } else if (parentMixinTypes != null) { for (Name parentMixin : parentMixinTypes) { if (nodeTypes.isTypeOrSubtype(nodeTypeNames, parentMixin)) { return true;
if (nodeTypes.isTypeOrSubtype(nodeTypeNames, parentPrimaryType)) { return true; } else if (parentMixinTypes != null) { for (Name parentMixin : parentMixinTypes) { if (nodeTypes.isTypeOrSubtype(nodeTypeNames, parentMixin)) { return true;