use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class NodeTypeManagerImpl method registerNodeTypes.
//--------------------------------------------< JackrabbitNodeTypeManager >
/**
* Internal helper method for registering a list of node type definitions.
* Returns a collection containing the registered node types.
*
* @param defs a collection of <code>QNodeTypeDefinition<code> objects
* @return registered node types
* @throws InvalidNodeTypeDefException if a nodetype is invalid
* @throws RepositoryException if an error occurs
*/
private Collection<NodeType> registerNodeTypes(List<QNodeTypeDefinition> defs) throws InvalidNodeTypeDefException, RepositoryException {
context.getNodeTypeRegistry().registerNodeTypes(defs);
Set<NodeType> types = new HashSet<NodeType>();
for (QNodeTypeDefinition def : defs) {
try {
types.add(getNodeType(def.getName()));
} catch (NoSuchNodeTypeException e) {
// ignore
}
}
return types;
}
use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class NodeTypeRegistry method registerNodeTypes.
/**
* Internal implementation of {@link #registerNodeTypes(Collection)}
*
* @param ntDefs a collection of <code>QNodeTypeDefinition<code> objects
* @param external whether this invocation should be considered external
* @throws InvalidNodeTypeDefException if the given node type definition is invalid.
* @throws RepositoryException if a repository error occurs.
*/
private void registerNodeTypes(Collection<QNodeTypeDefinition> ntDefs, boolean external) throws InvalidNodeTypeDefException, RepositoryException {
synchronized (this) {
// validate and register new node type definitions
internalRegister(ntDefs, external);
// persist new node type definitions
for (QNodeTypeDefinition ntDef : ntDefs) {
customNTDefs.add(ntDef);
}
persistCustomNodeTypeDefs(customNTDefs);
// notify listeners
for (QNodeTypeDefinition ntDef : ntDefs) {
notifyRegistered(ntDef.getName());
}
}
// inform cluster if this is not an external invocation
if (!external && eventChannel != null) {
eventChannel.registered(ntDefs);
}
}
use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class NodeTypeRegistry method checkNtBaseSubtyping.
/**
* Checks if the given node type def has the correct supertypes in respect
* to nt:base. all mixin nodetypes must not have a nt:base, the primary
* ones only if they don't inherit it from another supertype.
*
* @param ntd the node type def to check
* @param ntdCache cache for lookup
* @return the node type definition that was given to check or a new
* instance if it had to be fixed up.
*/
private static QNodeTypeDefinition checkNtBaseSubtyping(QNodeTypeDefinition ntd, Map<Name, QNodeTypeDefinition> ntdCache) {
if (NameConstants.NT_BASE.equals(ntd.getName())) {
return ntd;
}
Set<Name> supertypes = new TreeSet<Name>(Arrays.asList(ntd.getSupertypes()));
if (supertypes.isEmpty()) {
return ntd;
}
boolean modified;
if (ntd.isMixin()) {
// if mixin, remove possible nt:base supertype
modified = supertypes.remove(NameConstants.NT_BASE);
} else {
// check if all supertypes (except nt:base) are mixins
boolean allMixins = true;
for (Name name : supertypes) {
if (!name.equals(NameConstants.NT_BASE)) {
QNodeTypeDefinition def = ntdCache.get(name);
if (def != null && !def.isMixin()) {
allMixins = false;
break;
}
}
}
if (allMixins) {
// ntd is a primary node type and has only mixins as supertypes,
// so it needs a nt:base
modified = supertypes.add(NameConstants.NT_BASE);
} else {
// ntd is a primary node type and at least one of the supertypes
// is too, so ensure that no nt:base is added. note that the
// trivial case, where there would be no supertype left is handled
// in the QNodeTypeDefinition directly
modified = supertypes.remove(NameConstants.NT_BASE);
}
}
if (modified) {
ntd = new QNodeTypeDefinitionImpl(ntd.getName(), supertypes.toArray(new Name[supertypes.size()]), ntd.getSupportedMixinTypes(), ntd.isMixin(), ntd.isAbstract(), ntd.isQueryable(), ntd.hasOrderableChildNodes(), ntd.getPrimaryItemName(), ntd.getPropertyDefs(), ntd.getChildNodeDefs());
}
return ntd;
}
use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class NodeTypeManagerImpl method registerNodeTypes.
//--------------------------------------------------< new JSR 283 methods >
/**
* Registers or updates the specified <code>Collection</code> of
* <code>NodeTypeDefinition</code> objects. This method is used to register
* or update a set of node types with mutual dependencies. Returns an
* iterator over the resulting <code>NodeType</code> objects.
* <p>
* The effect of the method is "all or nothing"; if an error occurs, no node
* types are registered or updated.
* <p>
* Throws an <code>InvalidNodeTypeDefinitionException</code> if a
* <code>NodeTypeDefinition</code> within the <code>Collection</code> is
* invalid or if the <code>Collection</code> contains an object of a type
* other than <code>NodeTypeDefinition</code>.
* <p>
* Throws a <code>NodeTypeExistsException</code> if <code>allowUpdate</code>
* is <code>false</code> and a <code>NodeTypeDefinition</code> within the
* <code>Collection</code> specifies a node type name that is already
* registered.
* <p>
* Throws an <code>UnsupportedRepositoryOperationException</code> if this
* implementation does not support node type registration.
*
* @param definitions a collection of <code>NodeTypeDefinition</code>s
* @param allowUpdate a boolean
* @return the registered node types.
* @throws InvalidNodeTypeDefinitionException if a
* <code>NodeTypeDefinition</code> within the <code>Collection</code> is
* invalid or if the <code>Collection</code> contains an object of a type
* other than <code>NodeTypeDefinition</code>.
* @throws NodeTypeExistsException if <code>allowUpdate</code> is
* <code>false</code> and a <code>NodeTypeDefinition</code> within the
* <code>Collection</code> specifies a node type name that is already
* registered.
* @throws UnsupportedRepositoryOperationException if this implementation
* does not support node type registration.
* @throws RepositoryException if another error occurs.
* @since JCR 2.0
*/
public NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] definitions, boolean allowUpdate) throws InvalidNodeTypeDefinitionException, NodeTypeExistsException, UnsupportedRepositoryOperationException, RepositoryException {
// make sure the editing session is allowed to register node types.
context.getAccessManager().checkRepositoryPermission(Permission.NODE_TYPE_DEF_MNGMT);
NodeTypeRegistry registry = context.getNodeTypeRegistry();
// split the node types into new and already registered node types.
// this way we can register new node types together with already
// registered node types which make circular dependencies possible
List<QNodeTypeDefinition> addedDefs = new ArrayList<QNodeTypeDefinition>();
List<QNodeTypeDefinition> modifiedDefs = new ArrayList<QNodeTypeDefinition>();
for (NodeTypeDefinition definition : definitions) {
// convert to QNodeTypeDefinition
QNodeTypeDefinition def = toNodeTypeDef(definition);
if (registry.isRegistered(def.getName())) {
if (allowUpdate) {
modifiedDefs.add(def);
} else {
throw new NodeTypeExistsException(definition.getName());
}
} else {
addedDefs.add(def);
}
}
try {
ArrayList<NodeType> result = new ArrayList<NodeType>();
// register new node types
result.addAll(registerNodeTypes(addedDefs));
// re-register already existing node types
for (QNodeTypeDefinition nodeTypeDef : modifiedDefs) {
registry.reregisterNodeType(nodeTypeDef);
result.add(getNodeType(nodeTypeDef.getName()));
}
return new NodeTypeIteratorAdapter(result);
} catch (InvalidNodeTypeDefException e) {
throw new InvalidNodeTypeDefinitionException(e.getMessage(), e);
}
}
use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class PropertyTypeRegistry method nodeTypeRegistered.
public void nodeTypeRegistered(Name ntName) {
try {
QNodeTypeDefinition def = registry.getNodeTypeDef(ntName);
QPropertyDefinition[] propDefs = def.getPropertyDefs();
synchronized (typeMapping) {
for (QPropertyDefinition propDef : propDefs) {
int type = propDef.getRequiredType();
if (!propDef.definesResidual() && type != PropertyType.UNDEFINED) {
Name name = propDef.getName();
// only remember defined property types
TypeMapping[] types = typeMapping.get(name);
if (types == null) {
types = new TypeMapping[1];
} else {
TypeMapping[] tmp = new TypeMapping[types.length + 1];
System.arraycopy(types, 0, tmp, 0, types.length);
types = tmp;
}
types[types.length - 1] = new TypeMapping(ntName, type, propDef.isMultiple());
typeMapping.put(name, types);
}
}
}
} catch (NoSuchNodeTypeException e) {
log.error("Unable to get newly registered node type definition for name: " + ntName);
}
}
Aggregations