jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stefan Guggisberg" <stefan.guggisb...@gmail.com>
Subject Re: Primary item inheritance
Date Thu, 20 Jul 2006 13:58:18 GMT
hi jaka

On 7/20/06, Jaka Jaksic <jaka.jaksic@telemach.net> wrote:
> Hi!
>
> We define our repository structure using a CND file. In it we override
> several built-in node types, namely nt:file and nt:resource. The problem is
> that the subtypes don't inherit the primary item definition, so the
> resulting types have no primary item. And we can't simply redefine the
> primary item property because of an "ambigous definition" error.

strange, i quickly tested this with the following code snippet:

            NodeTypeRegistry ntReg = ((NodeTypeManagerImpl)
wsp.getNodeTypeManager()).getNodeTypeRegistry();
            NodeTypeDef ntd = new NodeTypeDef();
            ntd.setName(new QName("", "myResource"));
            ntd.setSupertypes(new QName[]{QName.NT_RESOURCE});
            ntd.setPrimaryItemName(QName.JCR_MIMETYPE);
            List ntDefs = new ArrayList();
            ntDefs.add(ntd);
            ntReg.registerNodeTypes(ntDefs);

            Node n = root.addNode("foo", "myResource");
            n.setProperty("jcr:mimeType", "application/octet-stream");
            Item pi = n.getPrimaryItem();  // -> returns /foo/jcr/mimeType

i.e. i was able to register and use a subtype of nt:resource that specifies
a custom primary item (jcr:mimeType).

please provide a simple test case that demonstrates your issue.

>
> Is this a bug or by desing? How are primary item definitions supposed to be
> inherited, if at all? If they are supposed to be inherited, what would
> happen in case of multiple inheritance, if more than one supertype defines
> the primary item?

see "6.7.8 Inheritance Among Node Types" in the jsr 170 specification
version 1.0.1:

<quote>
[...] Other than this, the specification does not define how conflicts
between multiple
supertypes are resolved or how these three top level attributes are
inherited. For example,
the question of whether the orderable child nodes setting of a node
type is inherited by its
subtypes is left up to the particular implementation. [...]
</quote>

the above statement also applies to the 'primaryItem' attribute.

jackrabbit currently does not support inheritance of the primaryItem attribute.

cheers
stefan

>
> For a workaround I call the following method during CND import to achieve
> primary item inheritance:
>
>     private static void inheritPrimaryItemName(final NodeTypeDef ntd, final
> NodeTypeRegistry ntReg) {
>         if (ntd.getPrimaryItemName() != null) return;
>         for (QName superNodeTypeName : ntd.getSupertypes()) {
>             try {
>                 NodeTypeDef superNtd =
> ntReg.getNodeTypeDef(superNodeTypeName);
>                 QName piName = superNtd.getPrimaryItemName();
>                 if (piName != null) {
>                     ntd.setPrimaryItemName(piName);
>                     return;
>                 }
>             } catch (NoSuchNodeTypeException e) {}
>         }
>     }
>
>
> Regards,
> Jaka
>
>

Mime
View raw message