jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shah.Abhishek" <engr.abhisheks...@gmail.com>
Subject How to add ChildNodeDefinition to NodeTypeTemplate while creating a custom NodeType using NodeTypeManager?
Date Fri, 25 Jan 2013 15:16:41 GMT
Hi,

I *need to* create a Custom Node type using the NodeTypeManager and other
api available in Jackrabbit 2.4.2. I can successfully create a custom node
type but am unable to add ChildNodeDefinitions to that node type. 

JCR docs specify that one can use NodeDefinitionTemplate:
*"NodeTypeManager.createNodeDefinitionTemplate() returns an empty
NodeDefinitionTemplate which can then be used to create a child node
definition and attached to a NodeTypeTemplate"*

Here,
When I try to create a new ChildNodeDefinition and try to register the
NodeTypeTemplate after appending the ChildNodeDefinition, it throws and
exception saying that "No such node type is defined" (talking about the
childNodeDefinition as it isn't registered.

And considering that I have to append a the Definition of a registered
NodeType, I don't have any way to get the Definition of a registered
NodeType. Even the NodeTypeManager returns the NodeType by using
NodeTypeManager.getNodeType("NodeTypeName") method.

Also adding a NodeType instance to NodeDefinitionList of NodeTypeTemplate
isn't an option as it gives ClassCastException.

Please, kindly help me out on this.


Below attached is my code:

NodeTypeManager nodeTypeManager = sessionImpl.getNodeTypeManager();
				try{
				
sessionImpl.getWorkspace().getNamespaceRegistry().registerNamespace("new",
"www.demo.com/new");
				}catch(Exception err)
				{
					System.out.println("EXCEPTION: Namespace is already registered!!");
				}
				
                                System.out.println("Create custom Node
Type");
				
				/* Create node type */
				NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate();
				nodeType.setName("new:contentType");
				

				/* Create a new property */
				PropertyDefinitionTemplate customProperty =
nodeTypeManager.createPropertyDefinitionTemplate();
				PropertyDefinitionTemplate customProperty_temp =
nodeTypeManager.createPropertyDefinitionTemplate();
				PropertyDefinitionTemplate customProperty_Two =
nodeTypeManager.createPropertyDefinitionTemplate();
	
				customProperty.setName("my_custom_property");
				customProperty.setRequiredType(PropertyType.LONG);
				customProperty_temp.setName("new:prop");
				customProperty_temp.setRequiredType(PropertyType.STRING);
				customProperty_temp.setMandatory(true);
				
				customProperty_Two.setName("new:property");
				customProperty_Two.setRequiredType(PropertyType.STRING);
				
				/* Add property to node type */
				nodeType.getPropertyDefinitionTemplates().add(customProperty);
				nodeType.getPropertyDefinitionTemplates().add(customProperty_temp);
				
                                //Complete child node part has been
commented, don't refer to it

				/*//TESTING FOR CHILD NODE TYPES
				
				 * Creating a definition for child node
				 
				NodeTypeTemplate childNode = nodeTypeManager.createNodeTypeTemplate();
				childNode.setName("new:childContentType");
				nodeTypeManager.registerNodeType(childNode, true);
				
				NodeDefinitionTemplate childNodeDefinition =
nodeTypeManager.createNodeDefinitionTemplate();
				//NodeDefinitionTemplate childNodeDefinition = (NodeDefinitionTemplate)
nodeTypeManager.getNodeType("tcs:childContentType");
				
				try{
					//nodeType.getNodeDefinitionTemplates().add(childNodeDefinition);
				}catch(Exception err)
				{
					System.out.println("CLASS-CAST-EXCEPTION!!");
				}
				
				 * End of child node definition creation and registration
				 */


				/* Register node type */

                                 //Even this won't work, not even if you try
to update the registered nodetype
                                // as it throws 
                                /*
java.lang.ArrayStoreException:
org.apache.jackrabbit.spi.commons.nodetype.NodeTypeTemplateImpl
                                   at java.util.LinkedList.toArray(Unknown
Source)
                               */
				//nodeType.getNodeDefinitionTemplates().add(nodeType);

				try{
					nodeTypeManager.registerNodeType(nodeType, true);
				}catch(Exception err)
				{
					System.out.println("Problem in registering a node type!");
				}




--
View this message in context: http://jackrabbit.510166.n4.nabble.com/How-to-add-ChildNodeDefinition-to-NodeTypeTemplate-while-creating-a-custom-NodeType-using-NodeTypeMa-tp4657488.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Mime
View raw message