use of org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl in project jackrabbit by apache.
the class NodeTypeManagerImpl method registerNodeTypes.
/**
* @see NodeTypeManager#registerNodeTypes(javax.jcr.nodetype.NodeTypeDefinition[], boolean)
*/
public NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] ntds, boolean allowUpdate) throws RepositoryException {
List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>(ntds.length);
for (NodeTypeDefinition definition : ntds) {
QNodeTypeDefinition qdef = new QNodeTypeDefinitionImpl(definition, getNamePathResolver(), mgrProvider.getQValueFactory());
if (!allowUpdate && hasNodeType(qdef.getName())) {
throw new NodeTypeExistsException("NodeType " + definition.getName() + " already exists.");
}
defs.add(qdef);
}
getNodeTypeRegistry().registerNodeTypes(defs, allowUpdate);
List<NodeType> nts = new ArrayList<NodeType>();
for (QNodeTypeDefinition def : defs) {
nts.add(getNodeType(def.getName()));
}
return new NodeTypeIteratorAdapter(nts);
}
use of org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl in project jackrabbit by apache.
the class RepositoryServiceImpl method getQNodeTypeDefinitions.
/**
* {@inheritDoc}
*/
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
List<QNodeTypeDefinition> nodeTypes = new ArrayList<QNodeTypeDefinition>();
try {
for (NodeTypeIterator it = ntMgr.getAllNodeTypes(); it.hasNext(); ) {
NodeType nt = it.nextNodeType();
nodeTypes.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
}
} catch (NameException e) {
throw new RepositoryException(e);
}
return nodeTypes.iterator();
}
use of org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl 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.commons.QNodeTypeDefinitionImpl in project jackrabbit by apache.
the class LostFromCacheIssueTest method setUp.
public void setUp() throws Exception {
super.setUp();
Workspace workspace = superuser.getWorkspace();
NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
NodeTypeManager ntmgr = workspace.getNodeTypeManager();
NodeTypeRegistry nodetypeRegistry = ((NodeTypeManagerImpl) ntmgr).getNodeTypeRegistry();
try {
namespaceRegistry.registerNamespace(NAMESPACE_PREFIX, NAMESPACE_URI);
} catch (NamespaceException ignore) {
//already exists
}
QNodeTypeDefinition nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_1), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
try {
nodetypeRegistry.registerNodeType(nodeTypeDefinition);
} catch (InvalidNodeTypeDefException ignore) {
//already exists
}
nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_2), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
try {
nodetypeRegistry.registerNodeType(nodeTypeDefinition);
} catch (InvalidNodeTypeDefException ignore) {
//already exists
}
getOrCreate(superuser.getRootNode(), TESTNODE_PATH);
superuser.save();
}
use of org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl in project jackrabbit by apache.
the class RepositoryServiceImpl method getQNodeTypeDefinitions.
/**
* {@inheritDoc}
*/
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodetypeNames) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>();
for (Name nodetypeName : nodetypeNames) {
try {
String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeName);
NodeType nt = ntMgr.getNodeType(ntName);
defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
// in addition pack all supertypes into the return value
NodeType[] supertypes = nt.getSupertypes();
for (NodeType supertype : supertypes) {
defs.add(new QNodeTypeDefinitionImpl(supertype, sInfo.getNamePathResolver(), getQValueFactory()));
}
} catch (NameException e) {
throw new RepositoryException(e);
}
}
return defs.iterator();
}
Aggregations