Search in sources :

Example 1 with NodeTypeDefDiff

use of org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeDefDiff in project jackrabbit-oak by apache.

the class NodeTypeRegistryTest method registerNodeType.

@Test
public void registerNodeType() throws Exception {
    registerNodeType(root, "oak6440-1.cnd");
    NodeTypeManager readOnlyNtMgr = new ReadOnlyNodeTypeManager() {

        private Root r = session.getLatestRoot();

        @Override
        protected Tree getTypes() {
            return r.getTree(NODE_TYPES_PATH);
        }
    };
    NodeTypeManager ntMgr = new ReadWriteNodeTypeManager() {

        @Override
        protected Tree getTypes() {
            return root.getTree(NODE_TYPES_PATH);
        }

        @Nonnull
        @Override
        protected Root getWriteRoot() {
            return root;
        }
    };
    ValueFactory valueFactory = new ValueFactoryImpl(root, new NamePathMapperImpl(new GlobalNameMapper(root)));
    NamespaceRegistry nsRegistry = new ReadOnlyNamespaceRegistry(root);
    DefinitionBuilderFactory<NodeTypeTemplate, NamespaceRegistry> factory = new TemplateBuilderFactory(ntMgr, valueFactory, nsRegistry);
    InputStream in = NodeTypeRegistryTest.class.getResourceAsStream("oak6440-2.cnd");
    List<NodeTypeTemplate> templates;
    try {
        CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry> reader = new CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry>(new InputStreamReader(in, UTF_8), "oak6440-2.cnd", factory);
        templates = reader.getNodeTypeDefinitions();
    } finally {
        in.close();
    }
    for (NodeTypeTemplate t : templates) {
        NodeTypeTemplateImpl template;
        if (t instanceof NodeTypeTemplateImpl) {
            template = (NodeTypeTemplateImpl) t;
        } else {
            template = new NodeTypeTemplateImpl(new GlobalNameMapper(root), t);
        }
        template.writeTo(root.getTree(NODE_TYPES_PATH), true);
    }
    NodeTypeDefinition beforeDef = readOnlyNtMgr.getNodeType("foo");
    NodeTypeDefinition afterDef = ntMgr.getNodeType("foo");
    NodeTypeDefDiff diff = NodeTypeDefDiff.create(beforeDef, afterDef);
    assertFalse(diff.isMajor());
}
Also used : ReadOnlyNodeTypeManager(org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) Root(org.apache.jackrabbit.oak.api.Root) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ValueFactoryImpl(org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl) TemplateBuilderFactory(org.apache.jackrabbit.commons.cnd.TemplateBuilderFactory) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) ReadOnlyNodeTypeManager(org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager) ValueFactory(javax.jcr.ValueFactory) ReadOnlyNamespaceRegistry(org.apache.jackrabbit.oak.plugins.name.ReadOnlyNamespaceRegistry) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl) NamespaceRegistry(javax.jcr.NamespaceRegistry) ReadOnlyNamespaceRegistry(org.apache.jackrabbit.oak.plugins.name.ReadOnlyNamespaceRegistry) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) GlobalNameMapper(org.apache.jackrabbit.oak.namepath.impl.GlobalNameMapper) CompactNodeTypeDefReader(org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader) NodeTypeDefDiff(org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeDefDiff) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 NamespaceRegistry (javax.jcr.NamespaceRegistry)1 ValueFactory (javax.jcr.ValueFactory)1 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)1 CompactNodeTypeDefReader (org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader)1 TemplateBuilderFactory (org.apache.jackrabbit.commons.cnd.TemplateBuilderFactory)1 Root (org.apache.jackrabbit.oak.api.Root)1 GlobalNameMapper (org.apache.jackrabbit.oak.namepath.impl.GlobalNameMapper)1 NamePathMapperImpl (org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl)1 ReadOnlyNamespaceRegistry (org.apache.jackrabbit.oak.plugins.name.ReadOnlyNamespaceRegistry)1 NodeTypeDefDiff (org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeDefDiff)1 ReadOnlyNodeTypeManager (org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager)1 ValueFactoryImpl (org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl)1 Test (org.junit.Test)1