Search in sources :

Example 1 with QNodeDefinitionBuilder

use of org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder in project jackrabbit by apache.

the class NodeTypeReader method getChildNodeDef.

/**
     * Returns the child node definition specified by the current element.
     *
     * @return child node definition
     * @throws NameException if the definition contains an illegal name
     * @throws NamespaceException if a namespace is not defined
     */
private QNodeDefinitionBuilder getChildNodeDef() throws NameException, NamespaceException {
    QNodeDefinitionBuilder def = new QNodeDefinitionBuilder();
    String name = walker.getAttribute(Constants.NAME_ATTRIBUTE);
    if (name.equals("*")) {
        def.setName(NameConstants.ANY_NAME);
    } else {
        def.setName(resolver.getQName(name));
    }
    // simple attributes
    def.setAutoCreated(Boolean.valueOf(walker.getAttribute(Constants.AUTOCREATED_ATTRIBUTE)));
    def.setMandatory(Boolean.valueOf(walker.getAttribute(Constants.MANDATORY_ATTRIBUTE)));
    def.setProtected(Boolean.valueOf(walker.getAttribute(Constants.PROTECTED_ATTRIBUTE)));
    def.setOnParentVersion(OnParentVersionAction.valueFromName(walker.getAttribute(Constants.ONPARENTVERSION_ATTRIBUTE)));
    def.setAllowsSameNameSiblings(Boolean.valueOf(walker.getAttribute(Constants.SAMENAMESIBLINGS_ATTRIBUTE)));
    // default primary type
    String type = walker.getAttribute(Constants.DEFAULTPRIMARYTYPE_ATTRIBUTE);
    if (type != null && type.length() > 0) {
        def.setDefaultPrimaryType(resolver.getQName(type));
    }
    // required primary types
    if (walker.enterElement(Constants.REQUIREDPRIMARYTYPES_ELEMENT)) {
        List<Name> types = new ArrayList<Name>();
        while (walker.iterateElements(Constants.REQUIREDPRIMARYTYPE_ELEMENT)) {
            types.add(resolver.getQName(walker.getContent()));
        }
        def.setRequiredPrimaryTypes(types.toArray(new Name[types.size()]));
        walker.leaveElement();
    } else {
    /* Default to nt:base?
            throw new InvalidNodeTypeDefException(
                    "Required primary type(s) not defined for child node "
                    + def.getName() + " of node type "
                    + def.getDeclaringNodeType());
            */
    }
    return def;
}
Also used : QNodeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder) ArrayList(java.util.ArrayList) Name(org.apache.jackrabbit.spi.Name)

Example 2 with QNodeDefinitionBuilder

use of org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder in project jackrabbit by apache.

the class NodeTypeRegistry method createRootNodeDef.

private static QNodeDefinition createRootNodeDef() {
    QNodeDefinitionBuilder def = new QNodeDefinitionBuilder();
    // FIXME need a fake declaring node type:
    // rep:root is not quite correct but better than a non-existing node type
    def.setDeclaringNodeType(NameConstants.REP_ROOT);
    def.setRequiredPrimaryTypes(new Name[] { NameConstants.REP_ROOT });
    def.setDefaultPrimaryType(NameConstants.REP_ROOT);
    def.setMandatory(true);
    def.setProtected(false);
    def.setOnParentVersion(OnParentVersionAction.VERSION);
    def.setAllowsSameNameSiblings(false);
    def.setAutoCreated(true);
    return def.build();
}
Also used : QNodeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder)

Example 3 with QNodeDefinitionBuilder

use of org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder in project jackrabbit by apache.

the class NodeTypeReader method getNodeTypeDef.

/**
     * Returns the node type definition specified by the current element.
     *
     * @return node type definition
     * @throws InvalidNodeTypeDefException if the definition is invalid
     * @throws NameException               if the definition contains an
     *                                     illegal name
     * @throws NamespaceException if a namespace is not defined
     */
private QNodeTypeDefinition getNodeTypeDef() throws InvalidNodeTypeDefException, NameException, NamespaceException {
    QNodeTypeDefinitionBuilder type = new QNodeTypeDefinitionBuilder();
    type.setName(resolver.getQName(walker.getAttribute(Constants.NAME_ATTRIBUTE)));
    type.setMixin(Boolean.valueOf(walker.getAttribute(Constants.ISMIXIN_ATTRIBUTE)));
    type.setOrderableChildNodes(Boolean.valueOf(walker.getAttribute(Constants.HASORDERABLECHILDNODES_ATTRIBUTE)));
    type.setAbstract(Boolean.valueOf(walker.getAttribute(Constants.ISABSTRACT_ATTRIBUTE)));
    if (walker.getAttribute(Constants.ISQUERYABLE_ATTRIBUTE) != null) {
        type.setQueryable(Boolean.valueOf(walker.getAttribute(Constants.ISQUERYABLE_ATTRIBUTE)));
    }
    String primaryItemName = walker.getAttribute(Constants.PRIMARYITEMNAME_ATTRIBUTE);
    if (primaryItemName != null && primaryItemName.length() > 0) {
        type.setPrimaryItemName(resolver.getQName(primaryItemName));
    }
    // supertype declarations
    if (walker.enterElement(Constants.SUPERTYPES_ELEMENT)) {
        List<Name> supertypes = new ArrayList<Name>();
        while (walker.iterateElements(Constants.SUPERTYPE_ELEMENT)) {
            supertypes.add(resolver.getQName(walker.getContent()));
        }
        type.setSupertypes(supertypes.toArray(new Name[supertypes.size()]));
        walker.leaveElement();
    }
    // property definitions
    List<QPropertyDefinition> properties = new ArrayList<QPropertyDefinition>();
    while (walker.iterateElements(Constants.PROPERTYDEFINITION_ELEMENT)) {
        QPropertyDefinitionBuilder def = getPropDef();
        def.setDeclaringNodeType(type.getName());
        properties.add(def.build());
    }
    type.setPropertyDefs(properties.toArray(new QPropertyDefinition[properties.size()]));
    // child node definitions
    List<QNodeDefinition> nodes = new ArrayList<QNodeDefinition>();
    while (walker.iterateElements(Constants.CHILDNODEDEFINITION_ELEMENT)) {
        QNodeDefinitionBuilder def = getChildNodeDef();
        def.setDeclaringNodeType(type.getName());
        nodes.add(def.build());
    }
    type.setChildNodeDefs(nodes.toArray(new QNodeDefinition[nodes.size()]));
    return type.build();
}
Also used : QNodeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder) QPropertyDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QPropertyDefinitionBuilder) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ArrayList(java.util.ArrayList) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) QNodeTypeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder) Name(org.apache.jackrabbit.spi.Name)

Example 4 with QNodeDefinitionBuilder

use of org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder in project jackrabbit by apache.

the class CyclicNodeTypeRegistrationTest method testRegisterSimpleMissingNodeTypes.

/**
     * A simple check, if a missing node type is found
     */
public void testRegisterSimpleMissingNodeTypes() {
    /**
         * Constructs node types with the following structure:
         * [foo]
         * + myNTInFoo (I_am_an_invalid_required_primary_type)
         *
         */
    final QNodeTypeDefinitionBuilder foo = new QNodeTypeDefinitionBuilder();
    foo.setName(nameFactory.create("", "foo"));
    foo.setSupertypes(new Name[] { NameConstants.NT_BASE });
    QNodeDefinitionBuilder myBarInFoo = new QNodeDefinitionBuilder();
    myBarInFoo.setRequiredPrimaryTypes(new Name[] { nameFactory.create("", "I_am_an_invalid_required_primary_type") });
    myBarInFoo.setName(nameFactory.create("", "myNTInFoo"));
    myBarInFoo.setDeclaringNodeType(foo.getName());
    foo.setChildNodeDefs(new QNodeDefinition[] { myBarInFoo.build() });
    ntDefCollection = new LinkedList<QNodeTypeDefinition>();
    ntDefCollection.add(foo.build());
    try {
        ntreg.registerNodeTypes(ntDefCollection);
        assertFalse("Missing node type not found", true);
    } catch (InvalidNodeTypeDefException e) {
        assertTrue(true);
    } catch (RepositoryException e) {
        assertFalse("Wrong Exception thrown on missing node type.", true);
        e.printStackTrace();
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) QNodeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder) RepositoryException(javax.jcr.RepositoryException) QNodeTypeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder)

Example 5 with QNodeDefinitionBuilder

use of org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder in project jackrabbit by apache.

the class CyclicNodeTypeRegistrationTest method testRegisterCyclicChildNodeTypes.

/**
     * Tests, if it is possible to register node types with simple
     * cyclic dependencies.
     */
public void testRegisterCyclicChildNodeTypes() {
    /**
         * Constructs node types with the following structure:
         * [foo]
         * + myBarInFoo (bar)
         *
         * [bar]
         * + myFooInBar (foo)
         */
    final QNodeTypeDefinitionBuilder foo = new QNodeTypeDefinitionBuilder();
    foo.setName(nameFactory.create("", "foo"));
    foo.setSupertypes(new Name[] { NameConstants.NT_BASE });
    final QNodeTypeDefinitionBuilder bar = new QNodeTypeDefinitionBuilder();
    bar.setName(nameFactory.create("", "bar"));
    bar.setSupertypes(new Name[] { NameConstants.NT_BASE });
    QNodeDefinitionBuilder myBarInFoo = new QNodeDefinitionBuilder();
    myBarInFoo.setRequiredPrimaryTypes(new Name[] { bar.getName() });
    myBarInFoo.setName(nameFactory.create("", "myBarInFoo"));
    myBarInFoo.setDeclaringNodeType(foo.getName());
    QNodeDefinitionBuilder myFooInBar = new QNodeDefinitionBuilder();
    myFooInBar.setRequiredPrimaryTypes(new Name[] { foo.getName() });
    myFooInBar.setName(nameFactory.create("", "myFooInBar"));
    myFooInBar.setDeclaringNodeType(bar.getName());
    foo.setChildNodeDefs(new QNodeDefinition[] { myBarInFoo.build() });
    bar.setChildNodeDefs(new QNodeDefinition[] { myFooInBar.build() });
    ntDefCollection = new LinkedList<QNodeTypeDefinition>();
    ntDefCollection.add(foo.build());
    ntDefCollection.add(bar.build());
    try {
        ntreg.registerNodeTypes(ntDefCollection);
    } catch (InvalidNodeTypeDefException e) {
        assertFalse(e.getMessage(), true);
        e.printStackTrace();
    } catch (RepositoryException e) {
        assertFalse(e.getMessage(), true);
        e.printStackTrace();
    }
    boolean allNTsAreRegistered = ntreg.isRegistered(foo.getName()) && ntreg.isRegistered(bar.getName());
    assertTrue(allNTsAreRegistered);
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) QNodeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder) RepositoryException(javax.jcr.RepositoryException) QNodeTypeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder)

Aggregations

QNodeDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder)7 RepositoryException (javax.jcr.RepositoryException)4 QNodeTypeDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder)4 Name (org.apache.jackrabbit.spi.Name)3 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)3 ArrayList (java.util.ArrayList)2 QPropertyDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QPropertyDefinitionBuilder)2 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)1 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)1 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)1 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)1 Element (org.w3c.dom.Element)1