Hello Jukka,
Thank you for your reply. It has clarified some confusions I had.
But still, I would to be sure about one more thing.
I have been doing tests on creating nodes of type nt:file,
nt:unstructured....And I was having all the time weired errors like,
"mandatory property.....created does not exist". And I thought it was
strange, as property created of nt:hierarchyNode is not mandatory...And
other similar errors.
So I just want to be sure of one more thing. Even for predefined nodes, it
is not possible to define a node of a certain type, through JCR Node
Interface.
I want to add a node of type nt:file with jcr:content of nt:resource type.
For doing so, I have to create a convenience class.
And for creating a node of a custom new node type, I have to follow one of
the two possibilities you have just mentioned.
What is most interesting for me at the moment is to know why I am getting
these "strange" errors when creating a simple nt:file.
This is very important. Thank you in advance.
Best Regards
From: Jukka Zitting <[EMAIL PROTECTED]>
Reply-To: [email protected]
To: [email protected]
Subject: Re: [Beginner]New Node Type Definition
Date: Fri, 27 Jan 2006 13:58:05 +0200
Hi,
On 1/21/06, sirène vip <[EMAIL PROTECTED]> 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
multiple
> 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.
BR,
Jukka Zitting
--
Yukatan - http://yukatan.fi/ - [EMAIL PROTECTED]
Software craftmanship, JCR consulting, and Java development
_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to
get there! http://lifeevents.msn.com/category.aspx?cid=Retirement