You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Subash Chaturanga <su...@gmail.com> on 2010/06/15 06:47:07 UTC

How to use Node and Property DefinitionTemplates to create a NodeTypeTemplate

Hi All ,

In JCR 2 ; javax.jcr.nodetype package

When NodeTypeManager wants to register a NodeType ,it needs a
NodeTypeTemplate to be passed to registerNodeType method.

In NodeTypeManager.createNodeTypeTemplate(NodeTypeDefinition
nodeTypeDefinition)  we can set the template according to the given
definition.

But NodeTypeManager.createNodeTypeTemplate() returns an empty template.
Also NodeTypeManagercan createNodeDefinitionTemplate
,createPropertyDefinitionTemplate .

In the JSR 283 spec , it says when creating  NodeDefinitionTemplate and
PropertyDefinitionTemplate they can be attached to the NodeTypeTemplate.
How we should attach those to NodeTypeTemplate? I mean is it the user's
responsible to set the NodeTypeTemplate after acquiring Node and Property
DefinitionTemplates ?

It will be great if  anyone can  make me clear about this ?

Thank you
Subash

Re: How to use Node and Property DefinitionTemplates to create a NodeTypeTemplate

Posted by Subash Chaturanga <su...@gmail.com>.
Hi ,Thanks Alex
Though i might not able to communicate my problem to you , I was able to
get  exactly what i wanted by the piece of code you gave me .It
worked.Thanks a lot

Regards
/Subash

Re: How to use Node and Property DefinitionTemplates to create a NodeTypeTemplate

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Jun 15, 2010 at 13:27, Subash Chaturanga <su...@gmail.com> wrote:
> Yes ,but my prob is where should I keep the list.Lists asks from NodeTypeTemplate .
> NodeTypeManager can create any number of NodeTypeTemplates(with or with out a definition) .
> If i maintain a List in   NodeTypeManager then how can i return Definition List asked from NodeTypeTemplate.getNodeDefinitionTemplates() which should be specific to that particular NodeTypeTemplate ?

Sorry, I don't understand. If you want to define a new custom node
type, this is what you do (beware, untested code):

<snip>

NodeTypeTemplate nt = nodeTypeManager.createNodeTypeTemplate();
nt.setName("my:nodeType");
nt.set....

PropertyDefinitionTemplate prop1 = nodeTypeManager.
createPropertyDefinitionTemplate();
prop1.setName("prop");
prop1.setRequiredType(PropertyType.STRING);
prop1.set...

nt. getPropertyDefinitionTemplates().add(prop1);

nodeTypeManager.registerNodeType(nt, false);

</snap>

Regards,
Alex

--
Alexander Klimetschek
alexander.klimetschek@day.com

Re: How to use Node and Property DefinitionTemplates to create a NodeTypeTemplate

Posted by Subash Chaturanga <su...@gmail.com>.
Thanks for your reply Alex ,

Yes ,but my prob is where should I keep the list.Lists asks from
NodeTypeTemplate .
NodeTypeManager can create any number of NodeTypeTemplates(with or with out
a definition) .
If i maintain a List in   NodeTypeManager then how can i return Definition
List asked from NodeTypeTemplate.getNodeDefinitionTemplates() which should
be specific to that particular NodeTypeTemplate ?

Thank you
Subash

Re: How to use Node and Property DefinitionTemplates to create a NodeTypeTemplate

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Jun 15, 2010 at 06:47, Subash Chaturanga <su...@gmail.com> wrote:
> In the JSR 283 spec , it says when creating  NodeDefinitionTemplate and
> PropertyDefinitionTemplate they can be attached to the NodeTypeTemplate.
> How we should attach those to NodeTypeTemplate? I mean is it the user's
> responsible to set the NodeTypeTemplate after acquiring Node and Property
> DefinitionTemplates ?

NodeTypeTemplate.getNodeDefinitionTemplates() and
getPropertyDefinitionTemplates() return *mutable* lists (see javadoc).
So you simply use list.add() to add the definitions created using
NodeTypeManager.createNodeDefinitionTemplate()  and
createPropertyDefinitionTemplate() (and modified according to your
needs).

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com