@Test(expected = InvalidNodeTypeDefinitionException.class) public void shouldNotAllowOverridingChildNodeIfRequiredTypesDoNotNarrow() throws Exception { /* * testNode declares No-SNS childNode testChildNode requiring type nt:hierarchy * testNodeB extends testNode with No-SNS childNode testChildNode requiring type nt:base -> ILLEGAL */ ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames( new String[] { "nt:base", }); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); child.setRequiredPrimaryTypeNames(new String[] {"nt:hierarchyNode"}); child.setSameNameSiblings(false); ntTemplate.getNodeDefinitionTemplates().add(child); JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); child.setSameNameSiblings(false); nodeBTemplate.getNodeDefinitionTemplates().add(child); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate, nodeBTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test(expected = InvalidNodeTypeDefinitionException.class) public void shouldNotAllowOverridingPropertyIfTypeDoesNotNarrow() throws Exception { /* * testNode declares SV property testProperty of type BOOLEAN * testNodeB extends testNode with SV property testProperty of type DOUBLE -> ILLEGAL */ ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames( new String[] { "nt:base", }); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); prop.setRequiredType(PropertyType.BOOLEAN); prop.setMultiple(false); ntTemplate.getPropertyDefinitionTemplates().add(prop); JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); prop.setRequiredType(PropertyType.DOUBLE); prop.setMultiple(false); nodeBTemplate.getPropertyDefinitionTemplates().add(prop); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate, nodeBTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test public void shouldAllowTypeWithMultipleChildNodes() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); child.setSameNameSiblings(true); ntTemplate.getNodeDefinitionTemplates().add(child); child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); child.setRequiredPrimaryTypeNames(new String[] {"nt:unstructured"}); child.setSameNameSiblings(false); ntTemplate.getNodeDefinitionTemplates().add(child); child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME + "2"); child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); child.setSameNameSiblings(true); ntTemplate.getNodeDefinitionTemplates().add(child); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test public void shouldAllowOverridingPropertyIfTypeNarrows() throws Exception { /* * testNode declares SV property testProperty of type UNDEFINED * testNodeB extends testNode with SV property testProperty of type STRING -> LEGAL */ ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames( new String[] { "nt:base", }); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); prop.setRequiredType(PropertyType.UNDEFINED); prop.setMultiple(false); ntTemplate.getPropertyDefinitionTemplates().add(prop); JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); prop.setRequiredType(PropertyType.STRING); prop.setMultiple(false); nodeBTemplate.getPropertyDefinitionTemplates().add(prop); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate, nodeBTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@SuppressWarnings("unchecked") @Test public void shouldAllowUnregisteringUnusedTypesWithMutualDependencies() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); JcrNodeDefinitionTemplate childNode = new JcrNodeDefinitionTemplate(this.context); childNode.setDefaultPrimaryTypeName(TEST_TYPE_NAME2); ntTemplate.getNodeDefinitionTemplates().add(childNode); NodeTypeTemplate ntTemplate2 = new JcrNodeTypeTemplate(this.context); ntTemplate2.setName(TEST_TYPE_NAME2); JcrNodeDefinitionTemplate childNode2 = new JcrNodeDefinitionTemplate(this.context); childNode2.setDefaultPrimaryTypeName(TEST_TYPE_NAME); ntTemplate2.getNodeDefinitionTemplates().add(childNode2); try { repoTypeManager.registerNodeTypes( Arrays.asList(new NodeTypeDefinition[] {ntTemplate, ntTemplate2})); } catch (Exception ex) { fail(ex.getMessage()); } Name typeNameAsName = nameFactory.create(TEST_TYPE_NAME); Name type2NameAsName = nameFactory.create(TEST_TYPE_NAME2); int nodeTypeCount = nodeTypes().getAllNodeTypes().size(); repoTypeManager.unregisterNodeType( Arrays.asList(new Name[] {typeNameAsName, type2NameAsName}), true); assertThat(nodeTypes().getAllNodeTypes().size(), is(nodeTypeCount - 2)); assertThat(nodeTypes().getNodeType(typeNameAsName), is(nullValue())); assertThat(nodeTypes().getNodeType(type2NameAsName), is(nullValue())); }
@Test(expected = InvalidNodeTypeDefinitionException.class) public void shouldNotAllowOverridingProtectedProperty() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(JcrLexicon.PRIMARY_TYPE.getString(registry)); prop.setRequiredType(PropertyType.NAME); ntTemplate.getPropertyDefinitionTemplates().add(prop); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test public void shouldAllowDefinitionWithAProperty() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setRequiredType(PropertyType.LONG); ntTemplate.getPropertyDefinitionTemplates().add(prop); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test public void shouldAllowDefinitionWithSupertypesFromTypesRegisteredInSameCall() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeTypeTemplate ntTemplate2 = new JcrNodeTypeTemplate(context); ntTemplate2.setName(TEST_TYPE_NAME2); ntTemplate2.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate, ntTemplate2}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test(expected = InvalidNodeTypeDefinitionException.class) public void shouldNotAllowOverridingProtectedChildNode() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames(new String[] {"mode:root", "mix:referenceable"}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(JcrLexicon.SYSTEM.getString(registry)); child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); ntTemplate.getNodeDefinitionTemplates().add(child); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test(expected = InvalidNodeTypeDefinitionException.class) public void shouldNotAllowMandatoryResidualChildNode() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(JcrNodeType.RESIDUAL_ITEM_NAME); child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); child.setMandatory(true); ntTemplate.getNodeDefinitionTemplates().add(child); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test(expected = InvalidNodeTypeDefinitionException.class) public void shouldNotAllowAutocreatedChildNodeWithNoDefaultPrimaryType() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); child.setAutoCreated(true); ntTemplate.getNodeDefinitionTemplates().add(child); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test(expected = InvalidNodeTypeDefinitionException.class) public void shouldNotAllowAutocreatedResidualProperty() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(JcrNodeType.RESIDUAL_ITEM_NAME); prop.setRequiredType(PropertyType.UNDEFINED); prop.setAutoCreated(true); ntTemplate.getPropertyDefinitionTemplates().add(prop); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test(expected = InvalidNodeTypeDefinitionException.class) public void shouldNotAllowDefinitionWithSupertypesFromTypesRegisteredInSameCallInWrongOrder() throws Exception { // Try to register the supertype AFTER the class that registers it ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeTypeTemplate ntTemplate2 = new JcrNodeTypeTemplate(context); ntTemplate2.setName(TEST_TYPE_NAME2); ntTemplate2.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); repoTypeManager.registerNodeTypes( Arrays.asList(new NodeTypeDefinition[] {ntTemplate2, ntTemplate})); }
/** * Registers or updates the specified Collection of {@code NodeTypeDefinition} objects. This * method is used to register or update a set of node types with mutual dependencies. Returns an * iterator over the resulting {@code NodeType} objects. * * <p>The effect of the method is "all or nothing"; if an error occurs, no node types are * registered or updated. * * @param templates the new node types to register * @param allowUpdates this flag is not used * @return the {@code newly created node types} * @throws InvalidNodeTypeDefinitionException if a {@code NodeTypeDefinition} within the * collection is invalid * @throws NodeTypeExistsException if {@code allowUpdate} is false and a {@code * NodeTypeDefinition} within the collection specifies a node type name that already exists * @throws UnsupportedRepositoryOperationException if {@code allowUpdate} is true; ModeShape does * not allow updating node types at this time. * @throws AccessDeniedException if the current session does not have the {@link * ModeShapePermissions#REGISTER_TYPE register type permission}. * @throws RepositoryException if another error occurs */ public NodeTypeIterator registerNodeTypes( Collection<NodeTypeDefinition> templates, boolean allowUpdates) throws InvalidNodeTypeDefinitionException, NodeTypeExistsException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException { session.checkLive(); try { session.checkPermission((Path) null, ModeShapePermissions.REGISTER_TYPE); } catch (AccessControlException ace) { throw new AccessDeniedException(ace); } return new JcrNodeTypeIterator( repositoryTypeManager.registerNodeTypes(templates, !allowUpdates, false, true)); }
@FixFor("MODE-826") @Test public void shouldAllowRegisteringNodeTypeWithOnlyResidualChildNodeDefinition() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); // Create the residual child node definition ... JcrNodeDefinitionTemplate childNode = new JcrNodeDefinitionTemplate(this.context); childNode.setDefaultPrimaryTypeName(TEST_TYPE_NAME2); childNode.setName("*"); ntTemplate.getNodeDefinitionTemplates().add(childNode); // And register it ... repoTypeManager.registerNodeTypes(Arrays.asList(new NodeTypeDefinition[] {ntTemplate})); }
@Test(expected = InvalidNodeTypeDefinitionException.class) public void shouldNotAllowSingleValuedPropertyWithMultipleDefaults() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); prop.setRequiredType(PropertyType.STRING); prop.setAutoCreated(true); prop.setDefaultValues(valuesFrom("<default>", "too many values")); ntTemplate.getPropertyDefinitionTemplates().add(prop); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
/** * Refresh the node types from the stored representation. * * @return true if there was at least one node type found, or false if there were none */ protected boolean refreshFromSystem() { this.nodeTypesLock.writeLock().lock(); try { // Re-read and re-register all of the node types ... SessionCache systemCache = repository.createSystemSession(context, true); SystemContent system = new SystemContent(systemCache); Collection<NodeTypeDefinition> nodeTypes = system.readAllNodeTypes(); if (nodeTypes.isEmpty()) return false; registerNodeTypes(nodeTypes, false, false, false); return true; } catch (Throwable e) { logger.error(e, JcrI18n.errorRefreshingNodeTypes, repository.name()); return false; } finally { this.nodeTypesLock.writeLock().unlock(); } }
@FixFor("MODE-826") @Test public void shouldAllowRegisteringNodeTypeWithPrimaryItemNameAndOnlyNonResidualChildNodeDefinition() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); // Set the primary item name to be a name that DOES match the child node definition ... ntTemplate.setPrimaryItemName(TEST_CHILD_NODE_NAME); // Create the residual child node definition ... JcrNodeDefinitionTemplate childNode = new JcrNodeDefinitionTemplate(this.context); childNode.setDefaultPrimaryTypeName(TEST_TYPE_NAME2); childNode.setName(TEST_CHILD_NODE_NAME); ntTemplate.getNodeDefinitionTemplates().add(childNode); // And register it ... repoTypeManager.registerNodeTypes(Arrays.asList(new NodeTypeDefinition[] {ntTemplate})); }
@FixFor("MODE-826") @Test public void shouldAllowRegisteringNodeTypeWithPrimaryItemNameAndOnlyNonResidualPropertyNodeDefinition() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); // Set the primary item name to be a name that DOES match the property definition ... ntTemplate.setPrimaryItemName(TEST_PROPERTY_NAME); // Create the residual property definition ... JcrPropertyDefinitionTemplate propertyDefn = new JcrPropertyDefinitionTemplate(this.context); propertyDefn.setRequiredType(PropertyType.STRING); propertyDefn.setName(TEST_PROPERTY_NAME); ntTemplate.getPropertyDefinitionTemplates().add(propertyDefn); // And register it ... repoTypeManager.registerNodeTypes(Arrays.asList(new NodeTypeDefinition[] {ntTemplate})); }
@Test(expected = InvalidNodeTypeDefinitionException.class) public void shouldNotAllowOverridingPropertyFromDifferentAncestors() throws Exception { /* * testNode * testNodeB extends testNode and declares prop testProperty * testNodeC extends testNode and declares prop testProperty * testNodeD extends testNodeB and testNodeC and overrides testProperty --> ILLEGAL */ ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames( new String[] { "nt:base", }); JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); prop.setRequiredType(PropertyType.UNDEFINED); nodeBTemplate.getPropertyDefinitionTemplates().add(prop); JcrNodeTypeTemplate nodeCTemplate = new JcrNodeTypeTemplate(this.context); nodeCTemplate.setName(TEST_TYPE_NAME + "C"); nodeCTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); prop.setRequiredType(PropertyType.UNDEFINED); nodeCTemplate.getPropertyDefinitionTemplates().add(prop); JcrNodeTypeTemplate nodeDTemplate = new JcrNodeTypeTemplate(this.context); nodeDTemplate.setName(TEST_TYPE_NAME + "D"); nodeDTemplate.setDeclaredSuperTypeNames( new String[] {nodeBTemplate.getName(), nodeCTemplate.getName()}); List<NodeTypeDefinition> templates = Arrays.asList( new NodeTypeDefinition[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test(expected = InvalidNodeTypeDefinitionException.class) public void shouldNotAllowOverridingChildNodeFromDifferentAncestors() throws Exception { /* * testNode * testNodeB extends testNode and declares node testChildNode * testNodeC extends testNode and declares node testChildNode * testNodeD extends testNodeB and testNodeC and overrides testChildNode --> ILLEGAL */ ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames( new String[] { "nt:base", }); JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(JcrLexicon.SYSTEM.getString(registry)); child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); nodeBTemplate.getNodeDefinitionTemplates().add(child); JcrNodeTypeTemplate nodeCTemplate = new JcrNodeTypeTemplate(this.context); nodeCTemplate.setName(TEST_TYPE_NAME + "C"); nodeCTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); child = new JcrNodeDefinitionTemplate(this.context); child.setName(JcrLexicon.SYSTEM.getString(registry)); child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); nodeCTemplate.getNodeDefinitionTemplates().add(child); JcrNodeTypeTemplate nodeDTemplate = new JcrNodeTypeTemplate(this.context); nodeDTemplate.setName(TEST_TYPE_NAME + "D"); nodeDTemplate.setDeclaredSuperTypeNames( new String[] {nodeBTemplate.getName(), nodeCTemplate.getName()}); List<NodeTypeDefinition> templates = Arrays.asList( new NodeTypeDefinition[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Test public void shouldAllowExtendingPropertyIfMultipleChanges() throws Exception { /* * testNode declares SV property testProperty * testNodeB extends testNode with MV property testProperty with incompatible type -> LEGAL * testNodeC extends testNode, testNodeB -> LEGAL */ ntTemplate.setName(TEST_TYPE_NAME); ntTemplate.setDeclaredSuperTypeNames( new String[] { "nt:base", }); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); prop.setRequiredType(PropertyType.DOUBLE); prop.setMultiple(false); ntTemplate.getPropertyDefinitionTemplates().add(prop); JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); prop.setRequiredType(PropertyType.BOOLEAN); prop.setMultiple(true); nodeBTemplate.getPropertyDefinitionTemplates().add(prop); JcrNodeTypeTemplate nodeCTemplate = new JcrNodeTypeTemplate(this.context); nodeCTemplate.setName(TEST_TYPE_NAME + "C"); nodeCTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME, nodeBTemplate.getName()}); List<NodeTypeDefinition> templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate, nodeBTemplate, nodeCTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates)); }
@Override public void notify(ChangeSet changeSet) { if (!systemWorkspaceName.equals(changeSet.getWorkspaceName())) { // The change does not affect the 'system' workspace, so skip it ... return; } if (context.getProcessId().equals(changeSet.getProcessKey())) { // We generated these changes, so skip them ... return; } // Now process the changes ... Set<Name> nodeTypesToRefresh = new HashSet<Name>(); Set<Name> nodeTypesToDelete = new HashSet<Name>(); for (Change change : changeSet) { if (change instanceof NodeAdded) { NodeAdded added = (NodeAdded) change; Path addedPath = added.getPath(); if (nodeTypesPath.isAncestorOf(addedPath)) { // Get the name of the node type ... Name nodeTypeName = addedPath.getSegment(2).getName(); nodeTypesToRefresh.add(nodeTypeName); } } else if (change instanceof NodeRemoved) { NodeRemoved removed = (NodeRemoved) change; Path removedPath = removed.getPath(); if (nodeTypesPath.isAncestorOf(removedPath)) { // Get the name of the node type ... Name nodeTypeName = removedPath.getSegment(2).getName(); if (removedPath.size() == 3) { nodeTypesToDelete.add(nodeTypeName); } else { // It's a child defn or property defn ... if (!nodeTypesToDelete.contains(nodeTypeName)) { // The child defn or property defn is being removed but the node type is not ... nodeTypesToRefresh.add(nodeTypeName); } } } } else if (change instanceof PropertyChanged) { PropertyChanged propChanged = (PropertyChanged) change; Path changedPath = propChanged.getPathToNode(); if (nodeTypesPath.isAncestorOf(changedPath)) { // Get the name of the node type ... Name nodeTypeName = changedPath.getSegment(2).getName(); nodeTypesToRefresh.add(nodeTypeName); } } // we don't care about node moves (don't happen) or property added/removed (handled by node // add/remove) } if (nodeTypesToRefresh.isEmpty() && nodeTypesToDelete.isEmpty()) { // No changes return; } // There were at least some changes ... this.nodeTypesLock.writeLock().lock(); try { // Re-register the node types that were changed or added ... SessionCache systemCache = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemCache); Collection<NodeTypeDefinition> nodeTypes = system.readNodeTypes(nodeTypesToRefresh); registerNodeTypes(nodeTypes, false, false, false); // Unregister those that were removed ... unregisterNodeType(nodeTypesToDelete, false); } catch (Throwable e) { logger.error(e, JcrI18n.errorRefreshingNodeTypes, repository.name()); } finally { this.nodeTypesLock.writeLock().unlock(); } }