ModeShape Distribution 3.0.0.Beta4

org.modeshape.jcr
Class CndImporter

java.lang.Object
  extended by org.modeshape.jcr.CndImporter

@NotThreadSafe
public class CndImporter
extends Object

A class that imports the node types contained in a JCR Compact Node Definition (CND) file into NodeTypeDefinition instances.


Field Summary
protected  List<String> BUILT_INS
           
protected  ExecutionContext context
           
static boolean DEFAULT_COMPATIBLE_WITH_PREJCR2
          The default flag for supporting pre-JCR 2.0 CND format is true .
static boolean DEFAULT_USE_VENDOR_EXTENSIONS
          The default flag for using vendor extensions is true .
protected  boolean jcr170
           
protected  LocalNamespaceRegistry localRegistry
           
protected  NameFactory nameFactory
           
protected  List<NodeTypeDefinition> nodeTypes
           
protected  ValueFactory<String> stringFactory
           
protected  List<String> VALID_ON_PARENT_VERSION
           
protected  List<String> VALID_PROPERTY_TYPES
           
protected  Set<String> VALID_QUERY_OPERATORS
           
protected  ValueFactory valueFactory
           
protected  Pattern VENDOR_PATTERN
           
protected  String VENDOR_PATTERN_STRING
          The regular expression used to capture the vendor property name and the value.
 
Constructor Summary
CndImporter(ExecutionContext context, boolean compatibleWithPreJcr2)
          Create a new importer that will place the content in the supplied destination under the supplied path.
 
Method Summary
protected  void applyVendorExtensions(org.modeshape.jcr.JcrNodeDefinitionTemplate childDefn, List<Property> extensions)
          Method that is responsible for setting the vendor extensions on the supplied child node type template.
protected  void applyVendorExtensions(JcrNodeTypeTemplate nodeType, List<Property> extensions)
          Method that is responsible for setting the vendor extensions on the supplied node type template.
protected  void applyVendorExtensions(org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn, List<Property> extensions)
          Method that is responsible for setting the vendor extensions on the supplied property definition template.
 Set<NamespaceRegistry.Namespace> getNamespaces()
           
 List<NodeTypeDefinition> getNodeTypeDefinitions()
           
 void importBuiltIns(Problems problems)
           
 void importFrom(File file, Problems problems)
          Import the CND content from the supplied stream, placing the content into the importer's destination.
 void importFrom(InputStream stream, Problems problems, String resourceName)
          Import the CND content from the supplied stream, placing the content into the importer's destination.
 void importFrom(String content, Problems problems, String resourceName)
          Import the CND content from the supplied stream, placing the content into the importer's destination.
protected  String[] names(Collection<Name> names)
           
protected  void parse(String content)
          Parse the CND content.
protected  void parseChildNodeDefinition(TokenStream tokens, JcrNodeTypeTemplate nodeType)
          Parse a node type's child node definition from the next tokens on the stream.
protected  void parseDefaultType(TokenStream tokens, org.modeshape.jcr.JcrNodeDefinitionTemplate childDefn)
          Parse the child node definition's default type, if they appear next on the token stream.
protected  void parseDefaultValues(TokenStream tokens, org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn)
          Parse the property definition's default value, if they appear next on the token stream.
protected  Name parseName(TokenStream tokens)
          Parse the name that is expected to be next on the token stream.
protected  List<Name> parseNameList(TokenStream tokens)
          Parse a list of names, separated by commas.
protected  void parseNamespaceMapping(TokenStream tokens)
          Parse the namespace mapping statement that is next on the token stream.
protected  void parseNodeAttributes(TokenStream tokens, org.modeshape.jcr.JcrNodeDefinitionTemplate childDefn, JcrNodeTypeTemplate nodeType)
          Parse the child node definition's attributes, if they appear next on the token stream.
protected  void parseNodeTypeDefinition(TokenStream tokens)
          Parse the node type definition that is next on the token stream.
protected  Name parseNodeTypeName(TokenStream tokens)
          Parse a node type name that appears next on the token stream.
protected  void parseNodeTypeOptions(TokenStream tokens, JcrNodeTypeTemplate nodeType)
          Parse the options for the node types, including whether the node type is orderable, a mixin, abstract, whether it supports querying, and which property/child node (if any) is the primary item for the node type.
protected  void parsePropertyAttributes(TokenStream tokens, org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn, JcrNodeTypeTemplate nodeType)
          Parse the property definition's attributes, if they appear next on the token stream.
protected  void parsePropertyDefinition(TokenStream tokens, JcrNodeTypeTemplate nodeType)
          Parse a node type's property definition from the next tokens on the stream.
protected  void parsePropertyOrChildNodeDefinitions(TokenStream tokens, JcrNodeTypeTemplate nodeType)
          Parse a node type's property or child node definitions that appear next on the token stream.
protected  void parsePropertyType(TokenStream tokens, org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn, String defaultPropertyType)
          Parse the property type, if a valid one appears next on the token stream.
protected  void parseQueryOperators(TokenStream tokens, org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn)
          Parse the property definition's query operators, if they appear next on the token stream.
protected  void parseRequiredPrimaryTypes(TokenStream tokens, org.modeshape.jcr.JcrNodeDefinitionTemplate childDefn)
          Parse the child node definition's list of required primary types, if they appear next on the token stream.
protected  List<String> parseStringList(TokenStream tokens)
          Parse a list of strings, separated by commas.
protected  List<Name> parseSupertypes(TokenStream tokens)
          Parse an optional list of supertypes if they appear next on the token stream.
protected  void parseValueConstraints(TokenStream tokens, org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn)
          Parse the property definition's value constraints, if they appear next on the token stream.
protected  Property parseVendorExtension(String vendorExtension)
          Parse the vendor extension, including the curly braces in the CND content.
protected  Property parseVendorExtensionContent(String vendorExtension)
          Parse the content of the vendor extension excluding the curly braces in the CND content.
protected  void parseVendorExtensions(TokenStream tokens, List<Property> properties)
          Parse the vendor extensions that may appear next on the tokenzied stream.
protected  String removeQuotes(String text)
           
protected  String string(Object name)
           
protected  String[] strings(Collection<String> values)
           
protected  Value[] values(Collection<String> values)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALID_PROPERTY_TYPES

protected final List<String> VALID_PROPERTY_TYPES

VALID_ON_PARENT_VERSION

protected final List<String> VALID_ON_PARENT_VERSION

VALID_QUERY_OPERATORS

protected final Set<String> VALID_QUERY_OPERATORS

BUILT_INS

protected final List<String> BUILT_INS

DEFAULT_USE_VENDOR_EXTENSIONS

public static final boolean DEFAULT_USE_VENDOR_EXTENSIONS
The default flag for using vendor extensions is true .

See Also:
Constant Field Values

DEFAULT_COMPATIBLE_WITH_PREJCR2

public static final boolean DEFAULT_COMPATIBLE_WITH_PREJCR2
The default flag for supporting pre-JCR 2.0 CND format is true .

See Also:
Constant Field Values

VENDOR_PATTERN_STRING

protected final String VENDOR_PATTERN_STRING
The regular expression used to capture the vendor property name and the value. The expression is " ([^\s]+)(\s+(.*))".

See Also:
Constant Field Values

VENDOR_PATTERN

protected final Pattern VENDOR_PATTERN

context

protected final ExecutionContext context

localRegistry

protected final LocalNamespaceRegistry localRegistry

nameFactory

protected final NameFactory nameFactory

stringFactory

protected final ValueFactory<String> stringFactory

valueFactory

protected final ValueFactory valueFactory

jcr170

protected final boolean jcr170

nodeTypes

protected final List<NodeTypeDefinition> nodeTypes
Constructor Detail

CndImporter

public CndImporter(ExecutionContext context,
                   boolean compatibleWithPreJcr2)
Create a new importer that will place the content in the supplied destination under the supplied path.

Parameters:
context - the context in which the importing should be performed; may not be null
compatibleWithPreJcr2 - true if this parser should accept the CND format that was used in the reference implementation prior to JCR 2.0.
Method Detail

importFrom

public void importFrom(InputStream stream,
                       Problems problems,
                       String resourceName)
                throws IOException
Import the CND content from the supplied stream, placing the content into the importer's destination.

Parameters:
stream - the stream containing the CND content
problems - where any problems encountered during import should be reported
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

importFrom

public void importFrom(File file,
                       Problems problems)
                throws IOException
Import the CND content from the supplied stream, placing the content into the importer's destination.

Parameters:
file - the file containing the CND content
problems - where any problems encountered during import should be reported
Throws:
IOException - if there is a problem reading from the supplied stream

importFrom

public void importFrom(String content,
                       Problems problems,
                       String resourceName)
Import the CND content from the supplied stream, placing the content into the importer's destination.

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

importBuiltIns

public void importBuiltIns(Problems problems)
                    throws IOException
Throws:
IOException

getNamespaces

public Set<NamespaceRegistry.Namespace> getNamespaces()

getNodeTypeDefinitions

public List<NodeTypeDefinition> getNodeTypeDefinitions()
Returns:
nodeTypes

parse

protected void parse(String content)
Parse the CND content.

Parameters:
content - the content
Throws:
ParsingException - if there is a problem parsing the content

parseNamespaceMapping

protected void parseNamespaceMapping(TokenStream tokens)
Parse the namespace mapping statement that is next on the token stream.

Parameters:
tokens - the tokens containing the namespace statement; never null
Throws:
ParsingException - if there is a problem parsing the content

parseNodeTypeDefinition

protected void parseNodeTypeDefinition(TokenStream tokens)
Parse the node type definition that is next on the token stream.

Parameters:
tokens - the tokens containing the node type definition; never null
Throws:
ParsingException - if there is a problem parsing the content

parseNodeTypeName

protected Name parseNodeTypeName(TokenStream tokens)
Parse a node type name that appears next on the token stream.

Parameters:
tokens - the tokens containing the node type name; never null
Returns:
the node type name
Throws:
ParsingException - if there is a problem parsing the content

parseSupertypes

protected List<Name> parseSupertypes(TokenStream tokens)
Parse an optional list of supertypes if they appear next on the token stream.

Parameters:
tokens - the tokens containing the supertype names; never null
Returns:
the list of supertype names; never null, but possibly empty
Throws:
ParsingException - if there is a problem parsing the content

parseStringList

protected List<String> parseStringList(TokenStream tokens)
Parse a list of strings, separated by commas. Any quotes surrounding the strings are removed.

Parameters:
tokens - the tokens containing the comma-separated strings; never null
Returns:
the list of string values; never null, but possibly empty
Throws:
ParsingException - if there is a problem parsing the content

parseNameList

protected List<Name> parseNameList(TokenStream tokens)
Parse a list of names, separated by commas. Any quotes surrounding the names are removed.

Parameters:
tokens - the tokens containing the comma-separated strings; never null
Returns:
the list of string values; never null, but possibly empty
Throws:
ParsingException - if there is a problem parsing the content

parseNodeTypeOptions

protected void parseNodeTypeOptions(TokenStream tokens,
                                    JcrNodeTypeTemplate nodeType)
                             throws ConstraintViolationException
Parse the options for the node types, including whether the node type is orderable, a mixin, abstract, whether it supports querying, and which property/child node (if any) is the primary item for the node type.

Parameters:
tokens - the tokens containing the comma-separated strings; never null
nodeType - the node type being created; may not be null
Throws:
ParsingException - if there is a problem parsing the content
ConstraintViolationException - not expected

parsePropertyOrChildNodeDefinitions

protected void parsePropertyOrChildNodeDefinitions(TokenStream tokens,
                                                   JcrNodeTypeTemplate nodeType)
                                            throws ConstraintViolationException
Parse a node type's property or child node definitions that appear next on the token stream.

Parameters:
tokens - the tokens containing the definitions; never null
nodeType - the node type being created; never null
Throws:
ParsingException - if there is a problem parsing the content
ConstraintViolationException - not expected

parsePropertyDefinition

protected void parsePropertyDefinition(TokenStream tokens,
                                       JcrNodeTypeTemplate nodeType)
                                throws ConstraintViolationException
Parse a node type's property definition from the next tokens on the stream.

Parameters:
tokens - the tokens containing the definition; never null
nodeType - the node type definition; never null
Throws:
ParsingException - if there is a problem parsing the content
ConstraintViolationException - not expected

parsePropertyType

protected void parsePropertyType(TokenStream tokens,
                                 org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn,
                                 String defaultPropertyType)
Parse the property type, if a valid one appears next on the token stream.

Parameters:
tokens - the tokens containing the definition; never null
propDefn - the property definition; never null
defaultPropertyType - the default property type if none is actually found
Throws:
ParsingException - if there is a problem parsing the content

parseDefaultValues

protected void parseDefaultValues(TokenStream tokens,
                                  org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn)
Parse the property definition's default value, if they appear next on the token stream.

Parameters:
tokens - the tokens containing the definition; never null
propDefn - the property definition; never null
Throws:
ParsingException - if there is a problem parsing the content

parseValueConstraints

protected void parseValueConstraints(TokenStream tokens,
                                     org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn)
Parse the property definition's value constraints, if they appear next on the token stream.

Parameters:
tokens - the tokens containing the definition; never null
propDefn - the property definition; never null
Throws:
ParsingException - if there is a problem parsing the content

parsePropertyAttributes

protected void parsePropertyAttributes(TokenStream tokens,
                                       org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn,
                                       JcrNodeTypeTemplate nodeType)
                                throws ConstraintViolationException
Parse the property definition's attributes, if they appear next on the token stream.

Parameters:
tokens - the tokens containing the attributes; never null
propDefn - the property definition; never null
nodeType - the node type; never null
Throws:
ParsingException - if there is a problem parsing the content
ConstraintViolationException - not expected

parseQueryOperators

protected void parseQueryOperators(TokenStream tokens,
                                   org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn)
Parse the property definition's query operators, if they appear next on the token stream.

Parameters:
tokens - the tokens containing the definition; never null
propDefn - the property definition; never null
Throws:
ParsingException - if there is a problem parsing the content

parseChildNodeDefinition

protected void parseChildNodeDefinition(TokenStream tokens,
                                        JcrNodeTypeTemplate nodeType)
                                 throws ConstraintViolationException
Parse a node type's child node definition from the next tokens on the stream.

Parameters:
tokens - the tokens containing the definition; never null
nodeType - the node type being created; never null
Throws:
ParsingException - if there is a problem parsing the content
ConstraintViolationException - not expected

parseRequiredPrimaryTypes

protected void parseRequiredPrimaryTypes(TokenStream tokens,
                                         org.modeshape.jcr.JcrNodeDefinitionTemplate childDefn)
                                  throws ConstraintViolationException
Parse the child node definition's list of required primary types, if they appear next on the token stream.

Parameters:
tokens - the tokens containing the definition; never null
childDefn - the child node definition; never null
Throws:
ParsingException - if there is a problem parsing the content
ConstraintViolationException - not expected

parseDefaultType

protected void parseDefaultType(TokenStream tokens,
                                org.modeshape.jcr.JcrNodeDefinitionTemplate childDefn)
                         throws ConstraintViolationException
Parse the child node definition's default type, if they appear next on the token stream.

Parameters:
tokens - the tokens containing the definition; never null
childDefn - the child node definition; never null
Throws:
ParsingException - if there is a problem parsing the content
ConstraintViolationException - not expected

parseNodeAttributes

protected void parseNodeAttributes(TokenStream tokens,
                                   org.modeshape.jcr.JcrNodeDefinitionTemplate childDefn,
                                   JcrNodeTypeTemplate nodeType)
                            throws ConstraintViolationException
Parse the child node definition's attributes, if they appear next on the token stream.

Parameters:
tokens - the tokens containing the attributes; never null
childDefn - the child node definition; never null
nodeType - the node type being created; never null
Throws:
ParsingException - if there is a problem parsing the content
ConstraintViolationException - not expected

parseName

protected Name parseName(TokenStream tokens)
Parse the name that is expected to be next on the token stream.

Parameters:
tokens - the tokens containing the name; never null
Returns:
the name; never null
Throws:
ParsingException - if there is a problem parsing the content

removeQuotes

protected final String removeQuotes(String text)

parseVendorExtensions

protected final void parseVendorExtensions(TokenStream tokens,
                                           List<Property> properties)
Parse the vendor extensions that may appear next on the tokenzied stream.

Parameters:
tokens - token stream; may not be null
properties - the list of properties to which any vendor extension properties should be added

parseVendorExtension

protected final Property parseVendorExtension(String vendorExtension)
Parse the vendor extension, including the curly braces in the CND content.

Parameters:
vendorExtension - the vendor extension string
Returns:
the property representing the vendor extension, or null if the vendor extension is incomplete

parseVendorExtensionContent

protected final Property parseVendorExtensionContent(String vendorExtension)
Parse the content of the vendor extension excluding the curly braces in the CND content.

Parameters:
vendorExtension - the vendor extension string; never null
Returns:
the property representing the vendor extension, or null if the vendor extension is incomplete

applyVendorExtensions

protected void applyVendorExtensions(JcrNodeTypeTemplate nodeType,
                                     List<Property> extensions)
Method that is responsible for setting the vendor extensions on the supplied node type template. By default this method does nothing; subclasses should override this method for custom extensions.

Parameters:
nodeType - the node type definition; never null
extensions - the extensions; never null but possibly empty

applyVendorExtensions

protected void applyVendorExtensions(org.modeshape.jcr.JcrNodeDefinitionTemplate childDefn,
                                     List<Property> extensions)
Method that is responsible for setting the vendor extensions on the supplied child node type template. By default this method does nothing; subclasses should override this method for custom extensions.

Parameters:
childDefn - the child definition; never null
extensions - the extensions; never null but possibly empty

applyVendorExtensions

protected void applyVendorExtensions(org.modeshape.jcr.JcrPropertyDefinitionTemplate propDefn,
                                     List<Property> extensions)
Method that is responsible for setting the vendor extensions on the supplied property definition template. By default this method does nothing; subclasses should override this method for custom extensions.

Parameters:
propDefn - the property definition; never null
extensions - the extensions; never null but possibly empty

string

protected final String string(Object name)

names

protected final String[] names(Collection<Name> names)

strings

protected final String[] strings(Collection<String> values)

values

protected final Value[] values(Collection<String> values)

ModeShape Distribution 3.0.0.Beta4

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