Hello all
I stumbled over a behavior in Resource#getResourceSuperType() that is
unexpected to me. I would like to clarify the contract of this method.
The JavaDoc for Resource#getResourceSuperType() states "Returns the
super type of the type of the resource or null if the
getResourceType() has no supertype.". I'll illustrate my understanding
of this contract with a simple example.
/content/resource [sling:resourceType="type"]
/apps/type [sling:resourceSuperType="super"]
/apps/super
Now if I have an instance of the Resource at /content/resource and
call ist getResourceSuperType() method, I'd expect to get the string
"super" as the return value ("the super type of the type of the
resource").
However, the JcrNodeResource[0], and possibly more importantly its
test cases[1] (specifically testResourceSuperType()), implement a
behavior that differs from my understanding of the documented
contract. In the above scenario,
JcrNodeResource#getResourceSuperType() would return null, while the
scenario below would yield "super".
/content/resource [sling:resourceType="type", sling:resourceSuperType="super"]
/apps/type
/apps/super
To me the documented contract is more intuitive, as that is how
inheritance generally works in my experience (i.e. my grandmother can
only be my grandmother transiently via one of my parents). However,
I'm curious to see whether others have other opinions.
BTW, MongoDBResource#getResourceSuperType() seems to implement the
same contract that JcrNodeResource does. Additionally, also
ResourceUtil#findResourceSuperType() supports the logic implemented in
JcrNodeResource.
I noticed this while implementing a possible fix for SLING-2708, which
is concerned with the ResourceUtil#isA() and Resource#isResourceType()
methods. Depending on the implementation of those methods (whether
they rely on Resource#getResourceSuperType() or not), they may yield
different results.
Thank you for your comments.
Regards
Julian
[0]
http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.jcr.resource-2.2.0/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
[1]
http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.jcr.resource-2.2.0/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java