jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jukka Zitting <jukka.zitt...@gmail.com>
Subject Re: [Beginner]New Node Type Definition
Date Fri, 27 Jan 2006 11:58:05 GMT

On 1/21/06, sirène vip <sirene_vip@hotmail.com> wrote:
> I want to create a new node type. It has to be extended from the nt:file
> with few changements like having sameNameSiblings set to true. Nodes of this
> new node type will be versionable.

Sounds like you are looking for something like this:

[yourNodeType] > nt:file, nt:versionable

> 1. I found in the jcr API the Version Interface, but couldn't find any class
> wrapping nt:file. Is there is one as for nt:version. And, if not, which
> class should I use in order to implement my new class? or should I implement
> a class for the nt:file node type?

The JCR node types are not Java classes, and there is no one-to-one
mapping between those. You need to first define and register the node
type in a content repository (see
http://incubator.apache.org/jackrabbit/doc/nodetype/index.html). Then
you can either access nodes of that type directly using the JCR Node
interface, or indirectly by creating a more convenient wrapper class
for the Node interface.

For example a convenience class for accessing nt:file nodes could be:

    public class FileNode {

        private final Node node;

        public FileNode(Node node) {
            this.node = node;

        public String getName() throws RepositoryException {
            return node.getName();

        public String getType() throws RepositoryException {
            try {
                return node.getProperty("jcr:content/jcr:mimeType").getString();
            } catch (PathNotFoundException e) {
                return null; // no mime type defined

        public InputStream getContent() throws RepositoryException {
            try {
                return node.getProperty("jcr:content/jcr:data").getStream();
            } catch (PathNotFoundException e) {
                return null; // no content available


> 2. Antoher confusing issue is on ChildNodeDefinition, which in the case of
> nt:file, is a  jcr:content. I thought of implementing it as an inner class,
> but I don't know if I'm on the right way. To my knowledge, a
> propertyDefinition should be implemented as an attribute, and a
> NodeDefinition as a  class.

There is no simple one-to-one mapping so the best solution depends on
the actual node type in case.


Jukka Zitting

Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftmanship, JCR consulting, and Java development
View raw message