org.modeshape.jcr
Class JackrabbitXmlNodeTypeReader

java.lang.Object
  extended by org.modeshape.jcr.JackrabbitXmlNodeTypeReader
All Implemented Interfaces:
Iterable<NodeTypeDefinition>

public class JackrabbitXmlNodeTypeReader
extends Object

A class that reads node types from Jackrabbit XML files.

Typically, the class will be used like this:

 Session session = ...
 // Instantiate the reader and load one or more files ... 
 JackrabbitXmlNodeTypeReader reader = new JackrabbitXmlNodeTypeReader(session);
 reader.read(file); // or stream or resource file
 
 if (!reader.getProblems().isEmpty()) {
     // Report problems
 } else {
     // Use the standard JCR API to register the loaded node types ... 
     boolean allowUpdate = false;
     session.getWorkspace().getNodeTypeManager().registerNodeTypes(reader.getNodeTypeDefinitions(), allowUpdate);
 }
 

The format of the XML is defined by this DTD:

 <!ELEMENT nodeTypes (nodeType)*>
     <!ELEMENT nodeType (supertypes?|propertyDefinition*|childNodeDefinition*)>
 
     <!ATTLIST nodeType
             name CDATA #REQUIRED
             isMixin (true|false) #REQUIRED
              hasOrderableChildNodes (true|false) #REQUIRED
             primaryItemName CDATA #REQUIRED
         >
     <!ELEMENT supertypes (supertype+)>
     <!ELEMENT supertype (CDATA)>
 
     <!ELEMENT propertyDefinition (valueConstraints?|defaultValues?)>
     <!ATTLIST propertyDefinition
             name CDATA #REQUIRED
             requiredType (String|Date|Path|Name|Reference|Binary|Double|Long|Boolean|undefined) #REQUIRED
             autoCreated (true|false) #REQUIRED
             mandatory (true|false) #REQUIRED
             onParentVersion (COPY|VERSION|INITIALIZE|COMPUTE|IGNORE|ABORT) #REQUIRED
             protected (true|false) #REQUIRED
             multiple  (true|false) #REQUIRED
         >
     <!ELEMENT valueConstraints (valueConstraint+)>
     <!ELEMENT valueConstraint (CDATA)>
     <!ELEMENT defaultValues (defaultValue+)>
     <!ELEMENT defaultValue (CDATA)>
 
     <!ELEMENT childNodeDefinition (requiredPrimaryTypes)>
     <!ATTLIST childNodeDefinition
             name CDATA #REQUIRED
             defaultPrimaryType  CDATA #REQUIRED
             autoCreated (true|false) #REQUIRED
             mandatory (true|false) #REQUIRED
             onParentVersion (COPY|VERSION|INITIALIZE|COMPUTE|IGNORE|ABORT) #REQUIRED
             protected (true|false) #REQUIRED
             sameNameSiblings (true|false) #REQUIRED
         >
     <!ELEMENT requiredPrimaryTypes (requiredPrimaryType+)>
     <!ELEMENT requiredPrimaryType (CDATA)>
 
 


Nested Class Summary
protected static class JackrabbitXmlNodeTypeReader.XmlImporter
           
 
Field Summary
protected  ValueFactory<Boolean> booleanFactory
           
protected  ExecutionContext context
           
protected  List<NodeTypeDefinition> immutableTypes
           
protected  NameFactory nameFactory
           
protected  PathFactory pathFactory
           
protected  Problems problems
           
protected  Path root
           
protected  ValueFactory<String> stringFactory
           
protected  List<NodeTypeDefinition> types
           
protected  ValueFactories valueFactories
           
 
Constructor Summary
JackrabbitXmlNodeTypeReader(ExecutionContext context)
          Create a new node type factory that reads the node types from Jackrabbit XML files.
JackrabbitXmlNodeTypeReader(Session session)
          Create a new node type factory that reads the node types from Jackrabbit XML files.
 
Method Summary
protected  NodeDefinitionTemplate childNodeDefinitionFrom(Subgraph nodeTypeGraph, Location childNodeLocation)
           
 NodeTypeDefinition[] getNodeTypeDefinitions()
          Returns the node type definitions created by this factory.
 Problems getProblems()
          Get the problems where warnings and error messages were recorded by this factory.
protected  void importFrom(Destination destination, Path path, String content, String resourceName)
          Method that loads into the graph destination the content containing the node type definitions.
 Iterator<NodeTypeDefinition> iterator()
          
protected  Name name(String name)
           
protected  Name nameFrom(SubgraphNode node)
           
protected  NodeTypeTemplate nodeTypeFrom(SubgraphNode nodeTypeNode, Subgraph subgraph)
           
protected  PropertyDefinitionTemplate propertyDefinitionFrom(Subgraph nodeTypeGraph, Location propertyLocation)
           
 void read(File file)
          Import the node types from the supplied file and add all of the node type definitions to this factory's list.
 void read(Graph graph, Path parentOfTypes, String resourceName)
          Import the node types from the supplied location in the specified graph.
 void read(InputStream stream, String resourceName)
          Import the node types from the supplied stream and add all of the node type definitions to this factory's list.
 void read(String resourceFile)
          Import the node types from the supplied file and add all of the node type definitions to this factory's list.
 void read(String content, String resourceName)
          Import the node types from the supplied string and add all of the node type definitions to this factory's list.
 void read(Subgraph subgraph, Location locationOfParent, String resourceName)
          Import the node types from the supplied location in the specified graph.
 void read(URL url)
          Import the node types from the file at the supplied URL and add all of the node type definitions to this factory's list.
protected  boolean readBoolean(SubgraphNode node, Name propertyName, boolean defaultValue)
           
protected  boolean readBoolean(SubgraphNode node, String propertyName, boolean defaultValue)
           
protected  Name readName(SubgraphNode node, Name propertyName, Name defaultValue)
           
protected  Name readName(SubgraphNode node, String propertyName, Name defaultValue)
           
protected  List<Name> readNames(SubgraphNode node, Name propertyName, Name defaultIfNone)
           
protected  List<Name> readNames(SubgraphNode node, String propertyName, Name defaultIfNone)
           
protected  String readString(SubgraphNode node, Name propertyName, String defaultValue)
           
protected  String readString(SubgraphNode node, String propertyName, String defaultValue)
           
protected  List<String> readStrings(SubgraphNode node, Name propertyName)
           
protected  List<String> readStrings(SubgraphNode node, String propertyName)
           
protected  List<NodeTypeDefinition> readTypesFrom(Graph graph, Path parentOfTypes)
           
protected  List<NodeTypeDefinition> readTypesFrom(Subgraph nodeTypeSubgraph, Location locationOfParentOfNodeTypes)
           
protected  List<Value> readValues(SubgraphNode node, Name propertyName, int requiredType)
           
protected  String string(Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

problems

protected final Problems problems

types

protected final List<NodeTypeDefinition> types

immutableTypes

protected final List<NodeTypeDefinition> immutableTypes

context

protected final ExecutionContext context

valueFactories

protected final ValueFactories valueFactories

pathFactory

protected final PathFactory pathFactory

nameFactory

protected final NameFactory nameFactory

booleanFactory

protected final ValueFactory<Boolean> booleanFactory

stringFactory

protected final ValueFactory<String> stringFactory

root

protected final Path root
Constructor Detail

JackrabbitXmlNodeTypeReader

public JackrabbitXmlNodeTypeReader(Session session)
Create a new node type factory that reads the node types from Jackrabbit XML files.

Parameters:
session - the session that will be used to register the node types; may not be null

JackrabbitXmlNodeTypeReader

public JackrabbitXmlNodeTypeReader(ExecutionContext context)
Create a new node type factory that reads the node types from Jackrabbit XML files.

Parameters:
context - the context that will be used to load the node types; may not be null
Method Detail

read

public void read(InputStream stream,
                 String resourceName)
          throws IOException
Import the node types from the supplied stream and add all of the node type definitions to this factory's list.

Parameters:
stream - the stream containing the CND content
resourceName - a logical name for the resource name to be used when reporting problems; may be null if there is no useful name
Throws:
IOException - if there is a problem reading from the supplied stream

read

public void read(File file)
          throws IOException
Import the node types from the supplied file and add all of the node type definitions to this factory's list.

Parameters:
file - the file containing the CND content
Throws:
IOException - if there is a problem reading from the supplied stream

read

public void read(URL url)
          throws IOException
Import the node types from the file at the supplied URL and add all of the node type definitions to this factory's list.

Parameters:
url - the URL to the file containing the node types
Throws:
IOException - if there is a problem reading from the supplied stream

read

public void read(String resourceFile)
          throws IOException
Import the node types from the supplied file and add all of the node type definitions to this factory's list.

Parameters:
resourceFile - the name of the resource file on the classpath containing the node types
Throws:
IOException - if there is a problem reading from the supplied resource

read

public void read(String content,
                 String resourceName)
Import the node types from the supplied string and add all of the node type definitions to this factory's list.

Parameters:
content - the string containing the CND content
resourceName - a logical name for the resource name to be used when reporting problems; may be null if there is no useful name

read

public void read(Graph graph,
                 Path parentOfTypes,
                 String resourceName)
Import the node types from the supplied location in the specified graph.

Parameters:
graph - the graph containing the standard ModeShape CND content
parentOfTypes - the path to the parent of the node type definition nodes
resourceName - a logical name for the resource name to be used when reporting problems; may be null if there is no useful name

read

public void read(Subgraph subgraph,
                 Location locationOfParent,
                 String resourceName)
Import the node types from the supplied location in the specified graph.

Parameters:
subgraph - the subgraph containing the standard ModeShape CND content
locationOfParent - the location to the parent of the node type definition nodes
resourceName - a logical name for the resource name to be used when reporting problems; may be null if there is no useful name

getProblems

public Problems getProblems()
Get the problems where warnings and error messages were recorded by this factory.

Returns:
the problems; never null

getNodeTypeDefinitions

public NodeTypeDefinition[] getNodeTypeDefinitions()
Returns the node type definitions created by this factory.

Returns:
the NodeTypeDefinitions

iterator

public Iterator<NodeTypeDefinition> iterator()

Specified by:
iterator in interface Iterable<NodeTypeDefinition>
See Also:
Iterable.iterator()

importFrom

protected void importFrom(Destination destination,
                          Path path,
                          String content,
                          String resourceName)
                   throws Exception
Method that loads into the graph destination the content containing the node type definitions.

Parameters:
destination - the destination to which the node type content should be written; never null
path - the path within the destination at which the node type content should be rooted; never null
content - the content containing some string representation of the node types to be imported; never null
resourceName - a descriptive name for this import (used only for error messages); may be null
Throws:
Exception - if there is a problem importing from the content; this will be automatically recorded in the problems
See Also:
GraphNodeTypeReader.importFrom(org.modeshape.graph.io.Destination, org.modeshape.graph.property.Path, java.lang.String, java.lang.String)

readTypesFrom

protected List<NodeTypeDefinition> readTypesFrom(Graph graph,
                                                 Path parentOfTypes)

readTypesFrom

protected List<NodeTypeDefinition> readTypesFrom(Subgraph nodeTypeSubgraph,
                                                 Location locationOfParentOfNodeTypes)

nodeTypeFrom

protected NodeTypeTemplate nodeTypeFrom(SubgraphNode nodeTypeNode,
                                        Subgraph subgraph)
                                 throws ConstraintViolationException
Throws:
ConstraintViolationException

propertyDefinitionFrom

protected PropertyDefinitionTemplate propertyDefinitionFrom(Subgraph nodeTypeGraph,
                                                            Location propertyLocation)
                                                     throws ConstraintViolationException
Throws:
ConstraintViolationException

childNodeDefinitionFrom

protected NodeDefinitionTemplate childNodeDefinitionFrom(Subgraph nodeTypeGraph,
                                                         Location childNodeLocation)
                                                  throws ConstraintViolationException
Throws:
ConstraintViolationException

nameFrom

protected Name nameFrom(SubgraphNode node)

name

protected Name name(String name)

string

protected String string(Object value)

readBoolean

protected boolean readBoolean(SubgraphNode node,
                              String propertyName,
                              boolean defaultValue)

readBoolean

protected boolean readBoolean(SubgraphNode node,
                              Name propertyName,
                              boolean defaultValue)

readString

protected String readString(SubgraphNode node,
                            String propertyName,
                            String defaultValue)

readString

protected String readString(SubgraphNode node,
                            Name propertyName,
                            String defaultValue)

readStrings

protected List<String> readStrings(SubgraphNode node,
                                   String propertyName)

readStrings

protected List<String> readStrings(SubgraphNode node,
                                   Name propertyName)

readValues

protected List<Value> readValues(SubgraphNode node,
                                 Name propertyName,
                                 int requiredType)

readName

protected Name readName(SubgraphNode node,
                        String propertyName,
                        Name defaultValue)

readName

protected Name readName(SubgraphNode node,
                        Name propertyName,
                        Name defaultValue)

readNames

protected List<Name> readNames(SubgraphNode node,
                               String propertyName,
                               Name defaultIfNone)

readNames

protected List<Name> readNames(SubgraphNode node,
                               Name propertyName,
                               Name defaultIfNone)


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