@Override public NodeTypeIterator getAllNodeTypes() throws RepositoryException { return delegate.getAllNodeTypes(); }
private String[] expand(final String[] ofTypes, final Session session) throws QueryException { try { Set<String> expanded = new LinkedHashSet<>(); NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager(); for (String ofType : ofTypes) { expanded.addAll(getSelfPlusSubTypes(ofType, ntMgr.getAllNodeTypes())); } return expanded.toArray(new String[expanded.size()]); } catch (RepositoryException e) { throw new QueryException("Exception while expanding node types", e); } }
private synchronized LinkedHashSet<QNodeTypeDefinition> getNodeTypes(String namespacePrefix) throws RepositoryException { NodeTypeIterator it = ntMgr.getAllNodeTypes(); TreeMap<String, NodeType> typesMap = new TreeMap<>(); while (it.hasNext()) { NodeType nt = it.nextNodeType(); if (nt.getName().startsWith(namespacePrefix)) { typesMap.put(nt.getName(), nt); } } LinkedHashSet<QNodeTypeDefinition> result = new LinkedHashSet<>(); for (NodeType type : typesMap.values()) { visit(namespacePrefix, type, new HashSet<>(), result); } return result; }
@Override public List<NodeType> nodeTypes() throws RepositoryException { LocalSession localSession = getLocalSession(); List<NodeType> types = new ArrayList<NodeType>(); NodeTypeIterator its = localSession.getSession().getWorkspace().getNodeTypeManager().getAllNodeTypes(); while (its.hasNext()) { types.add((NodeType)its.next()); } return types; }
private Set<String> getSelfPlusSubTypes(final String primaryNodeType) throws RepositoryException { Set<String> subTypes = new LinkedHashSet<>(); NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator allTypes = ntMgr.getAllNodeTypes(); while (allTypes.hasNext()) { NodeType nt = allTypes.nextNodeType(); if (nt.isNodeType(primaryNodeType)) { subTypes.add(nt.getName()); } } return subTypes; }
@Override public List<NodeType> nodeTypes() throws RepositoryException { LocalSession localSession = getLocalSession(); List<NodeType> types = new ArrayList<NodeType>(); NodeTypeIterator its = localSession.getSession().getWorkspace().getNodeTypeManager().getAllNodeTypes(); while (its.hasNext()) { types.add((NodeType)its.next()); } return types; }
@Override public List<String> getAvailableNodeTypes() throws SerializedException { List<String> availableNodeTypeList; try { availableNodeTypeList = new ArrayList<String>(); NodeTypeIterator nodeTypeIterator = getJcrSession().getWorkspace().getNodeTypeManager().getAllNodeTypes(); for (int j = 0; j < nodeTypeIterator.getSize(); j++) { NodeType nodeType = nodeTypeIterator.nextNodeType(); availableNodeTypeList.add(nodeType.getName()); } } catch (Exception e) { log.error("Failed fetching available node types. ", e); throw new SerializedException(e.getMessage()); } return availableNodeTypeList; }
/** {@inheritDoc} */ public RemoteIterator getAllNodeTypes() throws RepositoryException, RemoteException { try { return getFactory().getRemoteNodeTypeIterator( manager.getAllNodeTypes()); } catch (RepositoryException ex) { throw getRepositoryException(ex); } }
@Override public List<String> getMixinNodeTypes() throws SerializedException { List<String> mixinNodeTypeList; try { mixinNodeTypeList = new ArrayList<String>(); NodeTypeIterator nodeTypeIterator = getJcrSession().getWorkspace().getNodeTypeManager().getAllNodeTypes(); for (int j = 0; j < nodeTypeIterator.getSize(); j++) { NodeType nodeType = nodeTypeIterator.nextNodeType(); if (nodeType.isMixin()) mixinNodeTypeList.add(nodeType.getName()); } } catch (Exception e) { log.error("Failed fetching available node types. ", e); throw new SerializedException(e.getMessage()); } return mixinNodeTypeList; }
/** * 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()))); } }
/** * Tests that the information from getRequiredPrimaryTypeNames() * matches getRequiredPrimaryTypes(). * * @since JCR 2.0 */ public void testGetRequiredPrimaryTypeNames() throws RepositoryException { // loop all node types for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) { NodeType type = types.nextNodeType(); NodeDefinition defs[] = type.getChildNodeDefinitions(); for (int i = 0; i < defs.length; i++) { NodeType requiredPrimaryTypes[] = defs[i].getRequiredPrimaryTypes(); Set<String> rptnames = new HashSet<String>(); for (int j = 0; j < requiredPrimaryTypes.length; j++) { rptnames.add(requiredPrimaryTypes[j].getName()); } Set<String> rptnames2 = new HashSet<String>(Arrays.asList(defs[i].getRequiredPrimaryTypeNames())); assertEquals("names returned from getRequiredPrimaryTypeNames should match types returned from getRequiredPrimaryTypes", rptnames, rptnames2); } } }
/** * Return a {@link NodeTypeDefinition} list where the metaData child node definition has been removed. */ @Override public List<NodeTypeDefinition> getNodeTypesToRegister(NodeTypeManager nodeTypeManager) { List<NodeTypeDefinition> list = new ArrayList<NodeTypeDefinition>(); try { NodeTypeIterator iterator = nodeTypeManager.getAllNodeTypes(); while (iterator.hasNext()) { NodeType nodeType = iterator.nextNodeType(); if (nodeType.getDeclaredChildNodeDefinitions() != null) { // check if this type define metaData as child List<NodeDefinition> childNodeDefinition = Arrays.asList(nodeType.getDeclaredChildNodeDefinitions()); for (NodeDefinition nodeDefinition : childNodeDefinition) { if (nodeDefinition.getDefaultPrimaryType() != null && NodeTypes.MetaData.NAME.equals(nodeDefinition.getDefaultPrimaryType().getName())) { NodeTypeTemplate newNodeType = createNodeTypeWithoutMetaData(nodeTypeManager, nodeType, nodeDefinition); log.info("Add the following NodeType '{}' that currently defined a metaData nodeType as child node to the list.", newNodeType.getName()); list.add(newNodeType); break; } } } } } catch (RepositoryException e) { log.error("Could not create a List of existing NodeTpe declaring metaData as childNodeDefinition", e); } return list; }
/** * {@inheritDoc} */ public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo) throws RepositoryException { SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo); NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager(); List<QNodeTypeDefinition> nodeTypes = new ArrayList<QNodeTypeDefinition>(); try { for (NodeTypeIterator it = ntMgr.getAllNodeTypes(); it.hasNext(); ) { NodeType nt = it.nextNodeType(); nodeTypes.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory())); } } catch (NameException e) { throw new RepositoryException(e); } return nodeTypes.iterator(); }
/** * Test if getNodeType(String nodeTypeName) returns the expected NodeType and * if a NoSuchTypeException is thrown if no according node type is existing */ public void testGetNodeType() throws RepositoryException { NodeType type = manager.getAllNodeTypes().nextNodeType(); assertEquals("getNodeType(String nodeTypeName) does not return correct " + "NodeType", manager.getNodeType(type.getName()).getName(), type.getName()); StringBuffer notExistingName = new StringBuffer("X"); NodeTypeIterator types = manager.getAllNodeTypes(); while (types.hasNext()) { // build a name which is for sure not existing // (":" of namespace prefix will be replaced later on) notExistingName.append(types.nextNodeType().getName()); } try { manager.getNodeType(notExistingName.toString().replaceAll(":", "")); fail("getNodeType(String nodeTypeName) must throw a " + "NoSuchNodeTypeException if no according NodeType " + "does exist"); } catch (NoSuchNodeTypeException e) { // success } }
/** * {@inheritDoc} */ public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo) throws RepositoryException { SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo); NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager(); List<QNodeTypeDefinition> nodeTypes = new ArrayList<QNodeTypeDefinition>(); try { for (NodeTypeIterator it = ntMgr.getAllNodeTypes(); it.hasNext(); ) { NodeType nt = it.nextNodeType(); nodeTypes.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory())); } } catch (NameException e) { throw new RepositoryException(e); } return nodeTypes.iterator(); }
/** * Tests if auto create nodes are not a residual set definition (getName() * does not return "*") */ public void testIsAutoCreate() throws RepositoryException { NodeTypeIterator types = manager.getAllNodeTypes(); // loop all node types while (types.hasNext()) { NodeType type = types.nextNodeType(); NodeDefinition defs[] = type.getChildNodeDefinitions(); for (int i = 0; i < defs.length; i++) { if (defs[i].isAutoCreated()) { assertFalse("An auto create node must not be a " + "residual set definition.", defs[i].getName().equals("*")); } } } }
private void loadEffectiveNodeTypes(Session session, boolean allowRetry) throws RepositoryException { try { NodeTypeIterator nodeTypes = session.getWorkspace().getNodeTypeManager().getAllNodeTypes(); // load all jcr node types (recursively if needed) while (nodeTypes.hasNext()) { loadEffectiveNodeType(nodeTypes.nextNodeType()); } } catch (RepositoryException re) { if (allowRetry) { // for now only do and support retrying once loadEffectiveNodeTypes(session, false); return; } throw re; } // lock down seal(); }
/** * Test if getAllNodeTypes() returns all primary and mixin node types */ public void testGetAllNodeTypes() throws RepositoryException { long sizeAll = getSize(manager.getAllNodeTypes()); long sizePrimary = getSize(manager.getPrimaryNodeTypes()); long sizeMixin = getSize(manager.getMixinNodeTypes()); assertEquals("sizeAll() must return all primary and mixin node types:", sizePrimary + sizeMixin, sizeAll); }
/** * Tests if auto create properties are not a residual set definition * (getName() does not return "*") */ public void testIsAutoCreate() throws RepositoryException { NodeTypeIterator types = manager.getAllNodeTypes(); // loop all node types while (types.hasNext()) { NodeType type = types.nextNodeType(); PropertyDefinition defs[] = type.getPropertyDefinitions(); for (int i = 0; i < defs.length; i++) { if (defs[i].isAutoCreated()) { assertFalse("An auto create property must not be a " + "residual set definition.", defs[i].getName().equals("*")); } } } }
/** * Tests if getRequiredPrimaryTypes() does not return an empty array. Test * runs for all existing node types. */ public void testGetRequiredPrimaryTypes() throws RepositoryException { // loop all node types for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) { NodeType type = types.nextNodeType(); NodeDefinition defs[] = type.getChildNodeDefinitions(); for (int i = 0; i < defs.length; i++) { assertTrue("getRequiredPrimaryTypes() must never return an " + "empty array.", defs[i].getRequiredPrimaryTypes().length > 0); } } }