Uploaded image for project: 'Jackrabbit Content Repository'
  1. Jackrabbit Content Repository
  2. JCR-493

Primary item inheritance or redefinition in CND

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.0.1
    • None
    • nodetype
    • None

    Description

      Jackrabbit does not support primary item inheritance among node types. The JCR spec does not require this, although I think it would be correct. From object methodology's point of view, a subtype should have all features of its supertype, but currently a subtype of a node type that has a primary item defined (e.g. nt:resource) has NO primary item, therefore the subtype can not be used in generic procedures written for its supertype, which breaks the rules of object orientation. (There may also be other properties besides primary item which are not inherited.)

      Because the JCR spec (section 6.7.8) does not specify exactly how inheritance (especially of multiple types) should be handled, there is another possible solution to this problem, which is more Jackrabbit specific: to simply redefine the primary item in each subtype. This works well if the primary item is set directly thorough NoteTypeDef.setPrimaryItemName() method. But it produces an error if the subtype's is defined, together with the primary item, in a CND file and imported with CompactNodeTypeDefReader.

      A CND like the following produces "ambigous property definition" exception (EffectiveNodeType.internalMerge(), line 1051):
      ...
      [foo:myResource] > nt:resource

      • jcr:data (binary) mandatory
        ...

      It would be nice if it was possible to define node types like this entirely in CND, not having to add the primary items manually. Even better would be if there was proper node type inheritance, but since this is not a JCR requirement, you just do what you think is best.

      I created a simple solution for myself, which provides me node type inheritance (not handling potential conflicts among multiple supertypes):

      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) {}
      }
      }

      I call this during the CND import procedure for every imported node type .

      Attachments

        Activity

          People

            Unassigned Unassigned
            jjaksic Jaka Jaksic
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: