org.jboss.dna.jcr
Class CndNodeTypeSource

java.lang.Object
  extended by org.jboss.dna.jcr.CndNodeTypeSource
All Implemented Interfaces:
JcrNodeTypeSource

@Immutable
public class CndNodeTypeSource
extends Object
implements JcrNodeTypeSource

Class to parse one or more Compact Node Definition (CND) files containing custom node type definitions into a format that can be registered with the JcrNodeTypeManager.

The class contains methods for determining whether the CND files were parsed successfully and what errors occurred. Typically, the class will be used like this:

 try {
  String[] cndFilePaths = // The URIs for the resource files on the classpath
  JcrNodeTypeSource nodeTypeSource = new CndNodeTypeSource(cndFilePaths);
  
  if (!nodeTypeSource.isValid()) {
      Problems problems = nodeTypeSource.getProblems();
      // Report problems
  }
  else {
      jcrNodeTypeManager.registerNodeTypes(nodeTypeSource);
  }
 }
 catch (IOException ioe) {
  System.err.println("Could not find one of the CND files.");
  ioe.printStackTrace();
 }
 
 


Constructor Summary
CndNodeTypeSource(String resourceName)
          Creates a new JcrNodeTypeSource with based on the CND file with the given resource name.
CndNodeTypeSource(String[] resourceNames)
          Creates a new JcrNodeTypeSource based on the CND files at the given resource names.
 
Method Summary
 Graph getNodeTypes()
          Returns the node type information to be registered in graph form.
 Problems getProblems()
          Returns the problems (if any) that were encountered parsing the CND files.
 boolean isValid()
          Returns true if no errors were encountered while parsing the CND file or files
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CndNodeTypeSource

public CndNodeTypeSource(String resourceName)
                  throws IOException
Creates a new JcrNodeTypeSource with based on the CND file with the given resource name.

Parameters:
resourceName - the name of the resource; this resource must be on the classpath
Throws:
IOException - if an error loading or reading the resource occurs

CndNodeTypeSource

public CndNodeTypeSource(String[] resourceNames)
                  throws IOException
Creates a new JcrNodeTypeSource based on the CND files at the given resource names.

Parameters:
resourceNames - the name of the resources to load; these resources must be on the classpath
Throws:
IOException - if an error loading or reading the any of the resources occurs
Method Detail

isValid

public boolean isValid()
Returns true if no errors were encountered while parsing the CND file or files

Returns:
true if no errors were encountered while parsing the CND file or files

getProblems

public Problems getProblems()
Returns the problems (if any) that were encountered parsing the CND files. Node type registration errors or warnings will NOT be added to this set of problems.

Returns:
returns the problems (if any) that were encountered parsing the CND files.

getNodeTypes

public final Graph getNodeTypes()
Returns the node type information to be registered in graph form. The graph has a very specific required format.

The root node of the graph should have zero or more children. Each child of the root node represents a type to be registered and the name of the node should be the name of the node type to be registered. Additionally, any facets of the node type that are specified should be set in a manner consistent with the JCR specification for the nt:nodeType built-in node type. The jcr:primaryType property does not need to be set on these nodes, but the nodes must be semantically valid as if the jcr:primaryType property was set.

Each node type node may have zero or more children, each with the name jcr:propertyDefinition or jcr:childNodeDefinition, as per the definition of the nt:nodeType built-in type. Each property definition and child node definition must obey the semantics of jcr:propertyDefinition and jcr:childNodeDefinition respectively However these nodes also do not need to have the jcr:primaryType property set.

For example, one valid graph is:

 <root>
 +---- test:testMixinType
        +--- jcr:nodeTypeName               =  test:testMixinType  (PROPERTY)
        +--- jcr:isMixin                    =  true                (PROPERTY)    
        +--- jcr:childNodeDefinition                               (CHILD NODE)
        |     +--- jcr:name                 =  test:childNodeA     (PROPERTY)
        |     +--- jcr:mandatory            =  true                (PROPERTY)
        |     +--- jcr:autoCreated          =  true                (PROPERTY)
        |     +--- jcr:defaultPrimaryType   =  nt:base             (PROPERTY)
        |     +--- jcr:requiredPrimaryTypes =  nt:base             (PROPERTY)
        +--- jcr:propertyDefinition                                (CHILD NODE)
              +--- jcr:name                 =  test:propertyA      (PROPERTY)
              +--- jcr:multiple             =  true                (PROPERTY)
              +--- jcr:requiredType         =  String              (PROPERTY)
 
This graph (when registered) would create a mixin node named "test:testMixinType" with a mandatory, autocreated child node named "test:childNodeA" with a default and required primary type of "nt:base" and a multi-valued string property named "test:propertyA".

Specified by:
getNodeTypes in interface JcrNodeTypeSource
Returns:
a graph with the semantics noted above
See Also:
JcrNodeTypeSource.getNodeTypes()


Copyright © 2008-2009 JBoss, a division of Red Hat. All Rights Reserved.