/** {@inheritDoc} */ public RemoteNodeType[] getSupertypes() throws RemoteException { return getRemoteNodeTypeArray(type.getSupertypes()); }
/** * Helper method to logs a list of node types and their properties in a human readable way. * @param nodeTypes * the node types to be logged. */ private void logNodeTypes(final NodeType... nodeTypes) { if(LOG.isDebugEnabled()){ StringBuilder buf = new StringBuilder(32); buf.append("[\n"); for(NodeType nt : nodeTypes){ buf.append(nt.getName()).append(" > "); for(NodeType st : nt.getSupertypes()){ buf.append(st.getName()).append(", "); } buf.append('\n'); for(PropertyDefinition pd : nt.getPropertyDefinitions()){ buf.append("\t").append(pd.getName()).append(" (") .append(PropertyType.nameFromValue(pd.getRequiredType())) .append(")\n"); } } buf.append(']'); LOG.debug("Registered NodeTypes: {}",buf.toString()); } }
public PrimaryTypeInfo(NodeType nodeType, Set<NodeTypeInfo> superTypes) { super(nodeType); // if (nodeType.isMixin()) { throw new IllegalArgumentException(); } // Set<String> mixinNames = new HashSet<String>(); for (NodeType superType : nodeType.getSupertypes()) { if (superType.isMixin()) { mixinNames.add(superType.getName()); } } // Map<String, NodeTypeInfo> superTypesMap = new HashMap<String, NodeTypeInfo>(); for (NodeTypeInfo superType : superTypes) { superTypesMap.put(superType.getName(), superType); } // this.mixinNames = Collections.unmodifiableSet(mixinNames); this.superTypes = superTypes; this.superTypesMap = Collections.unmodifiableMap(superTypesMap); }
while (allNodeTypes.hasNext()) { NodeType nodeType = allNodeTypes.nextNodeType(); NodeType[] superTypes = nodeType.getSupertypes(); if (superTypes != null && superTypes.length > 0) { stringWriter.append(nodeType.getName()).append(" => ");
private Collection<String> getInheritedMixinTypes(final Node node) throws RepositoryException { final List<String> result = new ArrayList<String>(); for (NodeType nodeType : node.getMixinNodeTypes()) { for (NodeType superType : nodeType.getSupertypes()) { if (superType.isMixin()) { result.add(superType.getName()); } } } for (NodeType nodeType : node.getPrimaryNodeType().getSupertypes()) { if (nodeType.isMixin()) { result.add(nodeType.getName()); } } return result; }
/** * Test if an inherited mixin could be added. * * @throws RepositoryException * @since JCR 2.0 */ public void testAddInheritedMixin() throws RepositoryException { Session session = testRootNode.getSession(); Node node = testRootNode.addNode(nodeName1, testNodeType); session.save(); NodeType nt = node.getPrimaryNodeType(); NodeType[] superTypes = nt.getSupertypes(); for (int i = 0; i < superTypes.length; i++) { if (superTypes[i].isMixin()) { String mixinName = superTypes[i].getName(); // adding again must be possible (though it has no effect) assertTrue(node.canAddMixin(mixinName)); } } }
/** * Checks whether the given mixin node type is in effect for the given node. * * @param node the node * @param mixinType the mixin node type * @return <code>true</code> when the mixin node type is present, <code>false</code> instead. */ public static boolean hasMixinType(Node node, String mixinType) throws RepositoryException { for (NodeType nodeType : node.getMixinNodeTypes()) { if (nodeType.getName().equals(mixinType)) { return true; } } NodeType[] types = node.getPrimaryNodeType().getSupertypes(); if (types != null) { for (NodeType nt : types) { if (nt.getName().equals(mixinType)) { return true; } } } return false; }
/** * Returns true if defaultType or one of its supertypes is of the same * NodeType as requiredType. * * @param requiredType one of the required primary types of a NodeDef * @param defaultType the default primary type of a NodeDef */ private boolean compareWithRequiredType(NodeType requiredType, NodeType defaultType) { // if (defaultType == requiredType) return true; // rather use: if (defaultType.getName().equals(requiredType.getName())) { return true; } NodeType superTypes[] = defaultType.getSupertypes(); for (int i = 0; i < superTypes.length; i++) { // if (superTypes[i] == requiredType) return true; // rather use: if (superTypes[i].getName().equals(requiredType.getName())) { return true; } } return false; }
/** * Test if all node types returned by getDeclaredSupertypes() are also * returned by getSupertypes(). All existing node types are tested. */ public void testGetDeclaredSupertypes() throws RepositoryException { for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) { NodeType type = types.nextNodeType(); Set<String> declaredSupertypeNames = asSetOfNames(type.getDeclaredSupertypes()); Set<String> supertypeNames = asSetOfNames(type.getSupertypes()); assertTrue("all declared supertypes must be supertypes: " + (new HashSet<String>(declaredSupertypeNames).removeAll(supertypeNames)), supertypeNames.containsAll(declaredSupertypeNames)); assertEquals("getDeclaredSuperTypes and getDeclaredSuperTypeNames must be consistent", declaredSupertypeNames, new HashSet<String>(Arrays.asList(type.getDeclaredSupertypeNames()))); } }
/** * Node types compatibility check. * * @param nodeType * target node type * @param descriptor * descriptor containing source node type * @return <tt>true</tt> if nodes are considered compatible, * <tt>false</tt> otherwise */ private boolean checkCompatibleNodeTypes(NodeType nodeType, ClassDescriptor descriptor) { //return true if node type is not used if (descriptor.getJcrType() == null || descriptor.getJcrType().equals("")) { return true; } if (nodeType.getName().equals(descriptor.getJcrType())) { return true; } NodeType[] superTypes = nodeType.getSupertypes(); for (int i = 0; i < superTypes.length; i++) { if (superTypes[i].getName().equals(descriptor.getJcrType())) { return true; } } return false; }
/** * Node types compatibility check. * * @param nodeType * target node type * @param descriptor * descriptor containing source node type * @return <tt>true</tt> if nodes are considered compatible, * <tt>false</tt> otherwise */ private boolean checkCompatibleNodeTypes(NodeType nodeType, ClassDescriptor descriptor) { //return true if node type is not used if (descriptor.getJcrType() == null || descriptor.getJcrType().equals("")) { return true; } if (nodeType.getName().equals(descriptor.getJcrType())) { return true; } NodeType[] superTypes = nodeType.getSupertypes(); for (int i = 0; i < superTypes.length; i++) { if (superTypes[i].getName().equals(descriptor.getJcrType())) { return true; } } return false; }
@Override public boolean isNodeType(String nodeTypeName) { if (primaryType.equals(nodeTypeName)) { return true; } for (NodeType nodeType : getPrimaryNodeType().getSupertypes()) { if (nodeTypeName.equals(nodeType.getName())) { return true; } } for (String mixin : mixins) { if (mixin.equals(nodeTypeName)) { return true; } } return false; }
/** * Test if adding an inherited mixin type has no effect. * * @throws RepositoryException * @since JCR 2.0 */ public void testAddInheritedMixin() throws RepositoryException, NotExecutableException { Session session = testRootNode.getSession(); Node node = testRootNode.addNode(nodeName1, testNodeType); session.save(); String inheritedMixin = null; NodeType nt = node.getPrimaryNodeType(); NodeType[] superTypes = nt.getSupertypes(); for (int i = 0; i < superTypes.length && inheritedMixin == null; i++) { if (superTypes[i].isMixin()) { inheritedMixin = superTypes[i].getName(); } } if (inheritedMixin != null) { node.addMixin(inheritedMixin); assertFalse(node.isModified()); } else { throw new NotExecutableException("Primary node type does not have a mixin supertype"); } }
private String getPrimaryItemName(final Node document) throws RepositoryException { NodeType primaryType = document.getPrimaryNodeType(); String primaryItemName = primaryType.getPrimaryItemName(); while (primaryItemName == null && !NT_BASE.equals(primaryType.getName())) { for (NodeType nt : primaryType.getSupertypes()) { if (nt.getPrimaryItemName() != null) { primaryItemName = nt.getPrimaryItemName(); break; } if (nt.isNodeType(NT_BASE)) { primaryType = nt; } } } return primaryItemName; }
/** * Returns a node type that is nor legalType nor a sub type of of */ public static String getIllegalChildNodeType(NodeTypeManager manager, String legalType) throws RepositoryException { NodeTypeIterator types = manager.getAllNodeTypes(); while (types.hasNext()) { NodeType type = types.nextNodeType(); if (!type.getName().equals(legalType)) { NodeType superTypes[] = type.getSupertypes(); boolean isSubType = false; for (int i = 0; i < superTypes.length; i++) { String name = superTypes[i].getName(); if (name.equals(legalType)) { isSubType = true; break; } } if (!isSubType) { return type.getName(); } } } return null; }
private Item getPrimaryItem(Node node) throws Exception { NodeType primaryType = node.getPrimaryNodeType(); String primaryItemName = primaryType.getPrimaryItemName(); while (primaryItemName == null && !"nt:base".equals(primaryType.getName())) { for (NodeType nt : primaryType.getSupertypes()) { if (nt.getPrimaryItemName() != null) { primaryItemName = nt.getPrimaryItemName(); break; } if (nt.isNodeType("nt:base")) { primaryType = nt; } } } if (primaryItemName == null) { throw new ItemNotFoundException("No primary item definition found in type hierarchy"); } return node.getSession().getItem(node.getPath() + "/" + primaryItemName); }
private void visit(String namespacePrefix, NodeType nt, HashSet<String> visited, LinkedHashSet<QNodeTypeDefinition> result) { if (visited.contains(nt.getName())) { return; } visited.add(nt.getName()); for (NodeType superType : nt.getSupertypes()) { visit(namespacePrefix, superType, visited, result); } for (NodeDefinition nd : nt.getChildNodeDefinitions()) { for (NodeType childType : nd.getRequiredPrimaryTypes()) { visit(namespacePrefix, childType, visited, result); } NodeType defaultPriType = nd.getDefaultPrimaryType(); if (defaultPriType != null) { visit(namespacePrefix, defaultPriType, visited, result); } } if (nt.getName().startsWith(namespacePrefix + ":")) { result.add(((AbstractNodeType)nt).getDefinition()); } }
/** * {@inheritDoc} */ public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodetypeNames) throws RepositoryException { SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo); NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager(); List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>(); for (Name nodetypeName : nodetypeNames) { try { String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeName); NodeType nt = ntMgr.getNodeType(ntName); defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory())); // in addition pack all supertypes into the return value NodeType[] supertypes = nt.getSupertypes(); for (NodeType supertype : supertypes) { defs.add(new QNodeTypeDefinitionImpl(supertype, sInfo.getNamePathResolver(), getQValueFactory())); } } catch (NameException e) { throw new RepositoryException(e); } } return defs.iterator(); }
private void writeNodeType(NodeType nt, CNDWriter w, Set<String> written) throws IOException, RepositoryException { if (nt != null && !written.contains(nt.getName())) { written.add(nt.getName()); w.write(nt); for (NodeType s: nt.getSupertypes()) { writeNodeType(s, w, written); } for (NodeDefinition n: nt.getChildNodeDefinitions()) { writeNodeType(n.getDefaultPrimaryType(), w, written); if (n.getRequiredPrimaryTypes() != null) { for (NodeType r: n.getRequiredPrimaryTypes()) { writeNodeType(r, w, written); } } } } }
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; }