org.apache.jackrabbit.core.nodetype
Class NodeTypeRegistry

java.lang.Object
  extended byorg.apache.jackrabbit.core.nodetype.NodeTypeRegistry
All Implemented Interfaces:
Dumpable

public class NodeTypeRegistry
extends Object
implements Dumpable

A NodeTypeRegistry ...


Constructor Summary
protected NodeTypeRegistry(NamespaceRegistry nsReg, FileSystem ntStore)
          Protected constructor
 
Method Summary
 void addListener(NodeTypeRegistryListener listener)
          Add a NodeTypeRegistryListener
protected  void checkForConflictingContent(NodeTypeDef ntd)
          Checks whether there is existing content that would conflict with the given node type definition.
protected  void checkForReferencesInContent(QName nodeTypeName)
          Checks whether there is existing content that directly or indirectly refers to the specified node type.
static NodeTypeRegistry create(NamespaceRegistry nsReg, FileSystem ntStore)
          Create a new NodeTypeRegistry
 void dump(PrintStream ps)
          Dumps the state of this instance in a human readable format for diagnostic purposes.
 Set getDependentNodeTypes(QName nodeTypeName)
          Returns the names of those registered node types that have dependencies on the given node type.
 EffectiveNodeType getEffectiveNodeType(QName ntName)
           
 EffectiveNodeType getEffectiveNodeType(QName[] ntNames)
           
 NodeDef getNodeDef(NodeDefId id)
           
 NodeTypeDef getNodeTypeDef(QName nodeTypeName)
          Returns the node type definition of the node type with the given name.
 PropDef getPropDef(PropDefId id)
           
 QName[] getRegisteredNodeTypes()
          Returns the names of all registered node types.
 NodeDef getRootNodeDef()
           
 boolean isBuiltIn(QName nodeTypeName)
           
 boolean isRegistered(QName nodeTypeName)
           
protected  void loadBuiltInNodeTypeDefs(NodeTypeDefStore store)
          Loads the built-in node type definitions into the given store.
protected  void loadCustomNodeTypeDefs(NodeTypeDefStore store)
          Loads the custom node type definitions into the given store.
protected  void persistCustomNodeTypeDefs(NodeTypeDefStore store)
          Persists the custom node type definitions contained in the given store.
 EffectiveNodeType registerNodeType(NodeTypeDef ntd)
          Validates the NodeTypeDef and returns a registered EffectiveNodeType instance.
 void registerNodeTypes(Collection ntDefs)
          Same as registerNodeType(NodeTypeDef) except that a collection of NodeTypeDefs is registered instead of just one.
 void removeListener(NodeTypeRegistryListener listener)
          Remove a NodeTypeRegistryListener
 EffectiveNodeType reregisterNodeType(NodeTypeDef ntd)
           
 void unregisterNodeType(QName nodeTypeName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeTypeRegistry

protected NodeTypeRegistry(NamespaceRegistry nsReg,
                           FileSystem ntStore)
                    throws RepositoryException
Protected constructor

Parameters:
nsReg -
ntStore -
Throws:
RepositoryException
Method Detail

create

public static NodeTypeRegistry create(NamespaceRegistry nsReg,
                                      FileSystem ntStore)
                               throws RepositoryException
Create a new NodeTypeRegistry

Parameters:
nsReg -
ntStore -
Returns:
NodeTypeRegistry object
Throws:
RepositoryException

addListener

public void addListener(NodeTypeRegistryListener listener)
Add a NodeTypeRegistryListener

Parameters:
listener - the new listener to be informed on (un)registration of node types

removeListener

public void removeListener(NodeTypeRegistryListener listener)
Remove a NodeTypeRegistryListener

Parameters:
listener - an existing listener

getRegisteredNodeTypes

public QName[] getRegisteredNodeTypes()
Returns the names of all registered node types. That includes primary and mixin node types.

Returns:
the names of all registered node types.

getRootNodeDef

public NodeDef getRootNodeDef()
Returns:

getEffectiveNodeType

public EffectiveNodeType getEffectiveNodeType(QName ntName)
                                       throws NoSuchNodeTypeException
Parameters:
ntName -
Returns:
Throws:
NoSuchNodeTypeException

getEffectiveNodeType

public EffectiveNodeType getEffectiveNodeType(QName[] ntNames)
                                       throws NodeTypeConflictException,
                                              NoSuchNodeTypeException
Parameters:
ntNames -
Returns:
Throws:
NodeTypeConflictException
NoSuchNodeTypeException

registerNodeType

public EffectiveNodeType registerNodeType(NodeTypeDef ntd)
                                   throws InvalidNodeTypeDefException,
                                          RepositoryException
Validates the NodeTypeDef and returns a registered EffectiveNodeType instance.

The validation includes the following checks:

  • Supertypes must exist and be registered
  • Inheritance graph must not be circular
  • Aggregation of supertypes must not result in name conflicts, ambiguities, etc.
  • Definitions of auto-created properties must specify a name
  • Default values in property definitions must satisfy value constraints specified in the same property definition
  • Definitions of auto-created child-nodes must specify a name
  • Default node type in child-node definitions must exist and be registered
  • The aggregation of the default node types in child-node definitions must not result in name conflicts, ambiguities, etc.
  • Definitions of auto-created child-nodes must not specify default node types which would lead to infinite child node creation (e.g. node type 'A' defines auto-created child node with default node type 'A' ...)
  • Node types specified as constraints in child-node definitions must exist and be registered
  • The aggregation of the node types specified as constraints in child-node definitions must not result in name conflicts, ambiguities, etc.
  • Default node types in child-node definitions must satisfy node type constraints specified in the same child-node definition

Parameters:
ntd - the definition of the new node type
Returns:
an EffectiveNodeType instance
Throws:
InvalidNodeTypeDefException
RepositoryException

registerNodeTypes

public void registerNodeTypes(Collection ntDefs)
                       throws InvalidNodeTypeDefException,
                              RepositoryException
Same as registerNodeType(NodeTypeDef) except that a collection of NodeTypeDefs is registered instead of just one.

This method can be used to register a set of node types that have dependencies on each other.

Note that in the case an exception is thrown, some node types might have been nevertheless successfully registered.

Parameters:
ntDefs - a collection of NodeTypeDefs
Throws:
InvalidNodeTypeDefException
RepositoryException

unregisterNodeType

public void unregisterNodeType(QName nodeTypeName)
                        throws NoSuchNodeTypeException,
                               RepositoryException
Parameters:
nodeTypeName -
Throws:
NoSuchNodeTypeException
RepositoryException

reregisterNodeType

public EffectiveNodeType reregisterNodeType(NodeTypeDef ntd)
                                     throws NoSuchNodeTypeException,
                                            InvalidNodeTypeDefException,
                                            RepositoryException
Parameters:
ntd -
Returns:
Throws:
NoSuchNodeTypeException
InvalidNodeTypeDefException
RepositoryException

getDependentNodeTypes

public Set getDependentNodeTypes(QName nodeTypeName)
                          throws NoSuchNodeTypeException
Returns the names of those registered node types that have dependencies on the given node type.

Parameters:
nodeTypeName -
Returns:
a set of node type QNames
Throws:
NoSuchNodeTypeException

getNodeTypeDef

public NodeTypeDef getNodeTypeDef(QName nodeTypeName)
                           throws NoSuchNodeTypeException
Returns the node type definition of the node type with the given name.

Parameters:
nodeTypeName - name of node type whose definition should be returned.
Returns:
the node type definition of the node type with the given name.
Throws:
NoSuchNodeTypeException - if a node type with the given name does not exist

isRegistered

public boolean isRegistered(QName nodeTypeName)
Parameters:
nodeTypeName -
Returns:

isBuiltIn

public boolean isBuiltIn(QName nodeTypeName)
Parameters:
nodeTypeName -
Returns:

getNodeDef

public NodeDef getNodeDef(NodeDefId id)
Parameters:
id -
Returns:

getPropDef

public PropDef getPropDef(PropDefId id)
Parameters:
id -
Returns:

dump

public void dump(PrintStream ps)
Dumps the state of this instance in a human readable format for diagnostic purposes.

Specified by:
dump in interface Dumpable
Parameters:
ps - stream to dump state to

loadBuiltInNodeTypeDefs

protected void loadBuiltInNodeTypeDefs(NodeTypeDefStore store)
                                throws RepositoryException
Loads the built-in node type definitions into the given store.

This method may be overridden by extensions of this class; It must only be called once and only from within the constructor though.

Parameters:
store - The NodeTypeDefStore into which the node type definitions are loaded.
Throws:
RepositoryException - If an error occurrs while loading the built-in node type definitions.

loadCustomNodeTypeDefs

protected void loadCustomNodeTypeDefs(NodeTypeDefStore store)
                               throws RepositoryException
Loads the custom node type definitions into the given store.

This method may be overridden by extensions of this class; It must only be called once and only from within the constructor though.

Parameters:
store - The NodeTypeDefStore into which the node type definitions are loaded.
Throws:
RepositoryException - If an error occurrs while loading the custom node type definitions.

persistCustomNodeTypeDefs

protected void persistCustomNodeTypeDefs(NodeTypeDefStore store)
                                  throws RepositoryException
Persists the custom node type definitions contained in the given store.

Parameters:
store - The NodeTypeDefStore containing the definitons to be persisted.
Throws:
RepositoryException - If an error occurrs while persisting the custom node type definitions.

checkForConflictingContent

protected void checkForConflictingContent(NodeTypeDef ntd)
                                   throws RepositoryException
Checks whether there is existing content that would conflict with the given node type definition.

This method is not implemented yet and always throws a RepositoryException.

TODO

  1. apply deep locks on root nodes in every workspace or alternatively put repository in 'exclusive' or 'single-user' mode
  2. check if the given node type (or any node type that has dependencies on this node type) is currently referenced by nodes in the repository.
  3. check if applying the changed definitions to the affected items would violate existing node type constraints
  4. apply and persist changes to affected nodes (e.g. update definition id's, etc.)

    the above checks/actions are absolutely necessary in order to guarantee integrity of repository content.

    Parameters:
    ntd - The node type definition replacing the former node type definition of the same name.
    Throws:
    RepositoryException - If there is conflicting content or if the check failed for some other reason.

checkForReferencesInContent

protected void checkForReferencesInContent(QName nodeTypeName)
                                    throws RepositoryException
Checks whether there is existing content that directly or indirectly refers to the specified node type.

This method is not implemented yet and always throws a RepositoryException.

TODO:

  1. apply deep locks on root nodes in every workspace or alternatively put repository in 'single-user' mode
  2. check if the given node type is currently referenced by nodes in the repository.
  3. remove the node type if it is not currently referenced, otherwise throw exception

    the above checks are absolutely necessary in order to guarantee integrity of repository content.

    Parameters:
    nodeTypeName - The name of the node type to be checked.
    Throws:
    RepositoryException - If the specified node type is currently being referenced or if the check failed for some other reason.


Copyright © 2004-2005 The Apache Software Foundation. All Rights Reserved.