Class NodeTypeRegistry
- java.lang.Object
-
- org.apache.jackrabbit.core.nodetype.NodeTypeRegistry
-
- All Implemented Interfaces:
NodeTypeEventListener
public class NodeTypeRegistry extends Object implements NodeTypeEventListener
ANodeTypeRegistry
...
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
disableCheckForReferencesInContentException
Feature flag for the unfortunate behavior in Jackrabbit 2.1 and 2.2 where the exception fromcheckForReferencesInContent(Name)
was never thrown because of a mistaken commit for JCR-2587.
-
Constructor Summary
Constructors Constructor Description NodeTypeRegistry(NamespaceRegistry nsReg, FileSystem fs)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(NodeTypeRegistryListener listener)
Add aNodeTypeRegistryListener
protected void
checkForConflictingContent(QNodeTypeDefinition ntd, NodeTypeDefDiff diff)
Checks whether there is existing content that would conflict with the given node type definition.protected void
checkForReferencesInContent(Name nodeTypeName)
Checks whether there is existing content that directly or indirectly refers to the specified node type.void
externalRegistered(Collection<QNodeTypeDefinition> ntDefs)
Called when one or more node types have been externally registered.void
externalReregistered(QNodeTypeDefinition ntDef)
Called when a node type has been externally re-registered.void
externalUnregistered(Collection<Name> ntNames)
Called when one or more node types have been externally unregistered.Set<Name>
getDependentNodeTypes(Name nodeTypeName)
Returns the names of those registered node types that have dependencies on the given node type.EffectiveNodeType
getEffectiveNodeType(Set<Name> mixins)
Returns the effective node type representation of the given node types.EffectiveNodeType
getEffectiveNodeType(Name ntName)
EffectiveNodeType
getEffectiveNodeType(Name primary, Set<Name> mixins)
Returns the effective node type of a node with the given primary and mixin types.QNodeTypeDefinition
getNodeTypeDef(Name nodeTypeName)
Returns the node type definition of the node type with the given name.Name[]
getRegisteredNodeTypes()
Returns the names of all registered node types.QNodeDefinition
getRootNodeDef()
boolean
isBuiltIn(Name nodeTypeName)
boolean
isRegistered(Name nodeTypeName)
protected void
loadBuiltInNodeTypeDefs(NodeTypeDefStore store)
Loads the built-in node type definitions into the givenstore
.protected void
loadCustomNodeTypeDefs(NodeTypeDefStore store)
Loads the custom node type definitions into the givenstore
.protected void
persistCustomNodeTypeDefs(NodeTypeDefStore store)
Persists the custom node type definitions contained in the givenstore
.EffectiveNodeType
registerNodeType(QNodeTypeDefinition ntd)
Validates theNodeTypeDef
and returns anEffectiveNodeType
object representing the newly registered node type.void
registerNodeTypes(Collection<QNodeTypeDefinition> ntDefs)
Same as
except that a collection ofregisterNodeType(QNodeTypeDefinition)
NodeTypeDef
s is registered instead of just one.void
removeListener(NodeTypeRegistryListener listener)
Remove aNodeTypeRegistryListener
EffectiveNodeType
reregisterNodeType(QNodeTypeDefinition ntd)
Reregister a node type.void
setEventChannel(NodeTypeEventChannel eventChannel)
Set an event channel to inform about changes.String
toString()
void
unregisterNodeType(Name ntName)
Unregisters the specified node type.void
unregisterNodeTypes(Set<Name> ntNames)
Same as
except that a set of node types is unregistered instead of just one.unregisterNodeType(Name)
-
-
-
Field Detail
-
disableCheckForReferencesInContentException
public static volatile boolean disableCheckForReferencesInContentException
Feature flag for the unfortunate behavior in Jackrabbit 2.1 and 2.2 where the exception fromcheckForReferencesInContent(Name)
was never thrown because of a mistaken commit for JCR-2587. Setting this flag totrue
(the default value comes from the "disableCheckForReferencesInContentException" system property) will disable the exception thrown by default by the method.- See Also:
- JCR-3223
-
-
Constructor Detail
-
NodeTypeRegistry
public NodeTypeRegistry(NamespaceRegistry nsReg, FileSystem fs) throws RepositoryException
Constructor- Parameters:
nsReg
- name space registryfs
- repository file system- Throws:
RepositoryException
- if an error occurs
-
-
Method Detail
-
getRegisteredNodeTypes
public Name[] getRegisteredNodeTypes()
Returns the names of all registered node types. That includes primary and mixin node types.- Returns:
- the names of all registered node types.
-
registerNodeType
public EffectiveNodeType registerNodeType(QNodeTypeDefinition ntd) throws InvalidNodeTypeDefException, RepositoryException
Validates theNodeTypeDef
and returns anEffectiveNodeType
object representing the newly registered node type.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
- if the given node type definition is invalid.RepositoryException
- if a repository error occurs.
-
registerNodeTypes
public void registerNodeTypes(Collection<QNodeTypeDefinition> ntDefs) throws InvalidNodeTypeDefException, RepositoryException
Same as
except that a collection ofregisterNodeType(QNodeTypeDefinition)
NodeTypeDef
s is registered instead of just one.This method can be used to register a set of node types that have dependencies on each other.
- Parameters:
ntDefs
- a collection ofQNodeTypeDefinition
objects- Throws:
InvalidNodeTypeDefException
- if the given node type definition is invalid.RepositoryException
- if a repository error occurs.
-
unregisterNodeTypes
public void unregisterNodeTypes(Set<Name> ntNames) throws NoSuchNodeTypeException, RepositoryException
Same as
except that a set of node types is unregistered instead of just one.unregisterNodeType(Name)
This method can be used to unregister a set of node types that depend on each other.
- Parameters:
ntNames
- a collection ofName
objects denoting the node types to be unregistered- Throws:
NoSuchNodeTypeException
- if any of the specified names does not denote a registered node type.RepositoryException
- if another error occurs- See Also:
unregisterNodeType(Name)
-
unregisterNodeType
public void unregisterNodeType(Name ntName) throws NoSuchNodeTypeException, RepositoryException
Unregisters the specified node type. In order for a node type to be successfully unregistered it must meet the following conditions:- the node type must obviously be registered.
- a built-in node type can not be unregistered.
- the node type must not have dependents, i.e. other node types that are referencing it.
- the node type must not be currently used by any workspace.
- Parameters:
ntName
- name of the node type to be unregistered- Throws:
NoSuchNodeTypeException
- ifntName
does not denote a registered node type.RepositoryException
- if another error occurs.- See Also:
unregisterNodeTypes(Collection, boolean)
-
reregisterNodeType
public EffectiveNodeType reregisterNodeType(QNodeTypeDefinition ntd) throws NoSuchNodeTypeException, InvalidNodeTypeDefException, RepositoryException
Reregister a node type.- Parameters:
ntd
- node type definition- Returns:
- the new effective node type
- Throws:
NoSuchNodeTypeException
- ifntd
refers to an unknown node typeInvalidNodeTypeDefException
- if the node type definition is invalidRepositoryException
- if another error occurs
-
getEffectiveNodeType
public EffectiveNodeType getEffectiveNodeType(Name ntName) throws NoSuchNodeTypeException
- Parameters:
ntName
- name- Returns:
- effective node type
- Throws:
NoSuchNodeTypeException
- if node type does not exist
-
getEffectiveNodeType
public EffectiveNodeType getEffectiveNodeType(Name primary, Set<Name> mixins) throws NodeTypeConflictException, NoSuchNodeTypeException
Returns the effective node type of a node with the given primary and mixin types.- Parameters:
primary
- primary type of the nodemixins
- mixin types of the node (set ofnames
);- Returns:
- effective node type
- Throws:
NodeTypeConflictException
- if the given types are conflictingNoSuchNodeTypeException
- if one of the given types is not found
-
getEffectiveNodeType
public EffectiveNodeType getEffectiveNodeType(Set<Name> mixins) throws NodeTypeConflictException, NoSuchNodeTypeException
Returns the effective node type representation of the given node types.- Parameters:
mixins
- mixin types of the node (set ofnames
);- Returns:
- effective node type
- Throws:
NodeTypeConflictException
- if the given types are conflictingNoSuchNodeTypeException
- if one of the given types is not found
-
getDependentNodeTypes
public Set<Name> getDependentNodeTypes(Name nodeTypeName) throws NoSuchNodeTypeException
Returns the names of those registered node types that have dependencies on the given node type.- Parameters:
nodeTypeName
- node type name- Returns:
- a set of node type
Name
s - Throws:
NoSuchNodeTypeException
- if node type does not exist
-
getNodeTypeDef
public QNodeTypeDefinition getNodeTypeDef(Name 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(Name nodeTypeName)
- Parameters:
nodeTypeName
- node type name- Returns:
true
if the specified node type is registered;false
otherwise.
-
isBuiltIn
public boolean isBuiltIn(Name nodeTypeName)
- Parameters:
nodeTypeName
- node type name- Returns:
true
if the specified node type is built-in;false
otherwise.
-
addListener
public void addListener(NodeTypeRegistryListener listener)
Add aNodeTypeRegistryListener
- Parameters:
listener
- the new listener to be informed on (un)registration of node types
-
removeListener
public void removeListener(NodeTypeRegistryListener listener)
Remove aNodeTypeRegistryListener
- Parameters:
listener
- an existing listener
-
externalRegistered
public void externalRegistered(Collection<QNodeTypeDefinition> ntDefs) throws RepositoryException, InvalidNodeTypeDefException
Called when one or more node types have been externally registered.- Specified by:
externalRegistered
in interfaceNodeTypeEventListener
- Parameters:
ntDefs
- node type definitions- Throws:
RepositoryException
- if an error occursInvalidNodeTypeDefException
- if the node type definition is invalid
-
externalReregistered
public void externalReregistered(QNodeTypeDefinition ntDef) throws NoSuchNodeTypeException, InvalidNodeTypeDefException, RepositoryException
Called when a node type has been externally re-registered.- Specified by:
externalReregistered
in interfaceNodeTypeEventListener
- Parameters:
ntDef
- node type definition- Throws:
NoSuchNodeTypeException
- if the node type had not yet been registeredInvalidNodeTypeDefException
- if the node type definition is invalidRepositoryException
- if an error occurs
-
externalUnregistered
public void externalUnregistered(Collection<Name> ntNames) throws RepositoryException, NoSuchNodeTypeException
Called when one or more node types have been externally unregistered.- Specified by:
externalUnregistered
in interfaceNodeTypeEventListener
- Parameters:
ntNames
- node type qnames- Throws:
RepositoryException
- if an error occursNoSuchNodeTypeException
- if a node type is already unregistered
-
loadBuiltInNodeTypeDefs
protected void loadBuiltInNodeTypeDefs(NodeTypeDefStore store) throws RepositoryException
Loads the built-in node type definitions into the givenstore
.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
- TheNodeTypeDefStore
into which the node type definitions are loaded.- Throws:
RepositoryException
- If an error occurs while loading the built-in node type definitions.
-
loadCustomNodeTypeDefs
protected void loadCustomNodeTypeDefs(NodeTypeDefStore store) throws RepositoryException
Loads the custom node type definitions into the givenstore
.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
- TheNodeTypeDefStore
into which the node type definitions are loaded.- Throws:
RepositoryException
- If an error occurs while loading the custom node type definitions.
-
persistCustomNodeTypeDefs
protected void persistCustomNodeTypeDefs(NodeTypeDefStore store) throws RepositoryException
Persists the custom node type definitions contained in the givenstore
.- Parameters:
store
- TheNodeTypeDefStore
containing the definitions to be persisted.- Throws:
RepositoryException
- If an error occurs while persisting the custom node type definitions.
-
checkForConflictingContent
protected void checkForConflictingContent(QNodeTypeDefinition ntd, NodeTypeDefDiff diff) 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
- apply deep locks on root nodes in every workspace or alternatively put repository in 'exclusive' or 'single-user' mode
- 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.
- check if applying the changed definitions to the affected items would violate existing node type constraints
- 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.diff
-- Throws:
RepositoryException
- If there is conflicting content or if the check failed for some other reason.
-
checkForReferencesInContent
protected void checkForReferencesInContent(Name 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:
- apply deep locks on root nodes in every workspace or alternatively put repository in 'single-user' mode
- check if the given node type is currently referenced by nodes in the repository.
- 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.
-
getRootNodeDef
public QNodeDefinition getRootNodeDef()
- Returns:
- the definition of the root node
-
setEventChannel
public void setEventChannel(NodeTypeEventChannel eventChannel)
Set an event channel to inform about changes.- Parameters:
eventChannel
- event channel
-
-