use of javax.jcr.nodetype.NodeType in project jackrabbit-oak by apache.
the class NodeImpl method internalSetPrimaryType.
private void internalSetPrimaryType(final String nodeTypeName) throws RepositoryException {
// TODO: figure out the right place for this check
// throws on not found
NodeType nt = getNodeTypeManager().getNodeType(nodeTypeName);
if (nt.isAbstract() || nt.isMixin()) {
throw new ConstraintViolationException(getNodePath());
}
// TODO: END
PropertyState state = PropertyStates.createProperty(JCR_PRIMARYTYPE, getOakName(nodeTypeName), NAME);
dlg.setProperty(state, true, true);
dlg.setOrderableChildren(nt.hasOrderableChildNodes());
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class GQL method collectNodeTypes.
/**
* Resolves and collects all node types that match <code>ntName</code>.
*
* @param ntName the name of a node type (optionally without prefix).
* @throws RepositoryException if an error occurs while reading from the
* node type manager.
*/
private void collectNodeTypes(String ntName) throws RepositoryException {
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
String[] resolvedNames = resolveNodeTypeName(ntName);
// now resolve node type hierarchy
for (String resolvedName : resolvedNames) {
try {
NodeType base = ntMgr.getNodeType(resolvedName);
if (base.isMixin()) {
// search for nodes where jcr:mixinTypes is set to this mixin
addTypeConstraint(new MixinComparision(resolvedName));
} else {
// search for nodes where jcr:primaryType is set to this type
addTypeConstraint(new PrimaryTypeComparision(resolvedName));
}
// now search for all node types that are derived from base
NodeTypeIterator allTypes = ntMgr.getAllNodeTypes();
while (allTypes.hasNext()) {
NodeType nt = allTypes.nextNodeType();
NodeType[] superTypes = nt.getSupertypes();
if (Arrays.asList(superTypes).contains(base)) {
if (nt.isMixin()) {
addTypeConstraint(new MixinComparision(nt.getName()));
} else {
addTypeConstraint(new PrimaryTypeComparision(nt.getName()));
}
}
}
} catch (NoSuchNodeTypeException e) {
// add anyway -> will not match anything
addTypeConstraint(new PrimaryTypeComparision(resolvedName));
}
}
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class GQL method resolvePropertyName.
/**
* Resolves the given property name. If the name has a prefix then the name
* is returned immediately as is. Otherwise the node type manager is
* searched for a property definition that defines a named property with
* a local name that matches the provided <code>name</code>. If such a match
* is found the name of the property definition is returned.
*
* @param name the name of a property (optionally without a prefix).
* @return the resolved property name.
* @throws RepositoryException if an error occurs while reading from the
* node type manager.
*/
private String resolvePropertyName(String name) throws RepositoryException {
if (isPrefixed(name)) {
return name;
}
if (propertyNames == null) {
propertyNames = new HashMap<String, String>();
if (session != null) {
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator it = ntMgr.getAllNodeTypes();
while (it.hasNext()) {
NodeType nt = it.nextNodeType();
PropertyDefinition[] defs = nt.getDeclaredPropertyDefinitions();
for (PropertyDefinition def : defs) {
String pn = def.getName();
if (!pn.equals("*")) {
String localName = pn;
int idx = pn.indexOf(':');
if (idx != -1) {
localName = pn.substring(idx + 1);
}
propertyNames.put(localName, pn);
}
}
}
}
}
String pn = propertyNames.get(name);
if (pn != null) {
return pn;
} else {
return name;
}
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class AbstractWorkspaceReferenceableTest method setUp.
protected void setUp() throws Exception {
super.setUp();
// we assume referencing is supported by repository
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
// assert that this repository supports references
try {
NodeType referenceableNt = ntMgr.getNodeType(mixReferenceable);
if (referenceableNt == null) {
throw new NotExecutableException("Repository does not support Referencing: mixin nodetype '" + mixReferenceable + "' is missing.");
}
} catch (NoSuchNodeTypeException e) {
throw new NotExecutableException("Repository does not support Referencing: mixin nodetype '" + mixReferenceable + "' is missing.");
}
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class AbstractWorkspaceVersionableTest method setUp.
protected void setUp() throws Exception {
super.setUp();
// we assume versioning is supported by repository
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
// assert that this repository supports versioning
try {
NodeType versionableNt = ntMgr.getNodeType(mixVersionable);
if (versionableNt == null) {
throw new NotExecutableException("Repository does not support versioning: mixin nodetype '" + mixVersionable + "' is missing.");
}
} catch (NoSuchNodeTypeException e) {
throw new NotExecutableException("Repository does not support versioning: mixin nodetype '" + mixVersionable + "' is missing.");
}
}
Aggregations