Mapping Collection Fields

Introduction

The collection-descriptor maps a collection attribute into JCR nodes.

Based on our model defined here, the following collection-descriptor is used to map the "paragraphs" field into the JCR node called "paragraphs".

 				
<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Page" jcrNodeType="graffito:page">
	<collection-descriptor fieldName="paragraphs" jcrName="paragraphs" 
			       elementClassName="org.apache.portals.graffito.jcr.testmodel.Paragraph" />
	<!-- other field, bean and collection mapping here !-->
</class-descriptor>
																		
<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Paragraph" jcrNodeType="graffito:paragraph">
	<field-descriptor fieldName="path" path="true" />
	<field-descriptor fieldName="text" jcrName="graffito:text"/>
</class-descriptor>									
				

The collection-descriptor contains the elementClassName attribute which specify the collection element class.

Result in the JCR repository

Following our example, the resulting JCR structure can be :

 
/mysite/page1	
	/mysite/page1/paragraphs
		/mysite/page1/paragraphs/paragraph1
			graffito:text = "This is the content of para1"
		/mysite/page1/paragraphs/paragraph2
			graffito:text = ""This is the content of para2"
	... other subnodes for page1 ... 
				

Creating subnodes like this example (mysite/page1/paragraphs) is the default behavior. See the section Reviewing the collection-descriptor to get other collection-field mapping strategies.

Supported Collection Types

Current supported collection types are Collection, List, ArrayList and Vector. It is also possible other Collection or Map types with the ManageableCollection interface. See the section Reviewing the collection-descriptor to get more information on the ManageableCollection.