Search in sources :

Example 11 with NodeTypeRegistry

use of org.apache.jackrabbit.core.nodetype.NodeTypeRegistry in project jackrabbit by apache.

the class LostFromCacheIssueTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    Workspace workspace = superuser.getWorkspace();
    NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
    NodeTypeManager ntmgr = workspace.getNodeTypeManager();
    NodeTypeRegistry nodetypeRegistry = ((NodeTypeManagerImpl) ntmgr).getNodeTypeRegistry();
    try {
        namespaceRegistry.registerNamespace(NAMESPACE_PREFIX, NAMESPACE_URI);
    } catch (NamespaceException ignore) {
    //already exists
    }
    QNodeTypeDefinition nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_1), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
    try {
        nodetypeRegistry.registerNodeType(nodeTypeDefinition);
    } catch (InvalidNodeTypeDefException ignore) {
    //already exists
    }
    nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_2), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
    try {
        nodetypeRegistry.registerNodeType(nodeTypeDefinition);
    } catch (InvalidNodeTypeDefException ignore) {
    //already exists
    }
    getOrCreate(superuser.getRootNode(), TESTNODE_PATH);
    superuser.save();
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) InvalidNodeTypeDefException(org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NamespaceRegistry(javax.jcr.NamespaceRegistry) NamespaceException(javax.jcr.NamespaceException) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) NodeTypeManagerImpl(org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl) Workspace(javax.jcr.Workspace) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)

Example 12 with NodeTypeRegistry

use of org.apache.jackrabbit.core.nodetype.NodeTypeRegistry in project jackrabbit by apache.

the class RepositoryCopier method copyNodeTypes.

private void copyNodeTypes() throws RepositoryException {
    NodeTypeRegistry sourceRegistry = source.getNodeTypeRegistry();
    NodeTypeRegistry targetRegistry = target.getNodeTypeRegistry();
    logger.info("Copying registered node types");
    Collection<Name> existing = Arrays.asList(targetRegistry.getRegisteredNodeTypes());
    Collection<QNodeTypeDefinition> register = new ArrayList<QNodeTypeDefinition>();
    for (Name name : sourceRegistry.getRegisteredNodeTypes()) {
        // TODO: what about modified node types?
        if (!existing.contains(name)) {
            register.add(sourceRegistry.getNodeTypeDef(name));
        }
    }
    try {
        targetRegistry.registerNodeTypes(register);
    } catch (InvalidNodeTypeDefException e) {
        throw new RepositoryException("Unable to copy node types", e);
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) InvalidNodeTypeDefException(org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException) ArrayList(java.util.ArrayList) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 13 with NodeTypeRegistry

use of org.apache.jackrabbit.core.nodetype.NodeTypeRegistry in project jackrabbit-oak by apache.

the class RepositoryUpgrade method copyNodeTypes.

private void copyNodeTypes(NodeTypeManager ntMgr, ValueFactory valueFactory) throws RepositoryException {
    NodeTypeRegistry sourceRegistry = source.getNodeTypeRegistry();
    List<NodeTypeTemplate> templates = Lists.newArrayList();
    for (Name name : sourceRegistry.getRegisteredNodeTypes()) {
        String oakName = getOakName(name);
        // skip built-in nodetypes (OAK-1235)
        if (!ntMgr.hasNodeType(oakName)) {
            QNodeTypeDefinition def = sourceRegistry.getNodeTypeDef(name);
            templates.add(createNodeTypeTemplate(valueFactory, ntMgr, oakName, def));
        }
    }
    ntMgr.registerNodeTypes(templates.toArray(new NodeTypeTemplate[templates.size()]), true);
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) Name(org.apache.jackrabbit.spi.Name)

Aggregations

NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)13 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)10 Name (org.apache.jackrabbit.spi.Name)10 RepositoryException (javax.jcr.RepositoryException)9 NodeTypeConflictException (org.apache.jackrabbit.core.nodetype.NodeTypeConflictException)9 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)7 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)6 NodeState (org.apache.jackrabbit.core.state.NodeState)6 HashSet (java.util.HashSet)5 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)5 InvalidItemStateException (javax.jcr.InvalidItemStateException)4 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)4 NodeDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl)4 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)4 ArrayList (java.util.ArrayList)3 Value (javax.jcr.Value)3 ValueFormatException (javax.jcr.ValueFormatException)3 PropertyId (org.apache.jackrabbit.core.id.PropertyId)3 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)3 PropertyState (org.apache.jackrabbit.core.state.PropertyState)3