use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class NodeTypeUtil method locateAllChildNodeDef.
/**
* Locate all non-protected child node def declared by a non-abstract node type
* parsing all node types
*
* @param session the session to access the node types
* @param regardDefaultPrimaryType if true, the default primary type of the
* returned <code>NodeDef</code> is
* according to param <code>defaultPrimaryType</code>.
* If false, the returned <code>NodeDef</code>
* might have a default primary type or
* not.
* @param defaultPrimaryType if <code>regardDefaultPrimaryType</code>
* is true: if true, the returned
* <code>NodeDef</code> has a default
* primary type, else not
* @param residual if true, the returned <code>NodeDef</code>
* is of the residual name "*", else not
* @return
* @throws RepositoryException
*/
public static List<NodeDefinition> locateAllChildNodeDef(Session session, boolean regardDefaultPrimaryType, boolean defaultPrimaryType, boolean residual) throws RepositoryException {
List<NodeDefinition> nodeTypes = new ArrayList<NodeDefinition>();
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator types = manager.getAllNodeTypes();
boolean skip = false;
while (types.hasNext()) {
NodeType type = types.nextNodeType();
// node types with more than one residual child node definition
// will cause trouble in test cases. the implementation
// might pick another definition than the definition returned by
// this method, when a child node is set.
NodeDefinition[] childDefs = type.getChildNodeDefinitions();
int residuals = 0;
for (int i = 0; i < childDefs.length; i++) {
if (childDefs[i].getName().equals("*")) {
residuals++;
}
}
if (residuals > 1) {
// more than one residual, not suitable for tests
continue;
}
NodeDefinition[] nodeDefs = type.getDeclaredChildNodeDefinitions();
for (int i = 0; i < nodeDefs.length; i++) {
NodeDefinition nodeDef = nodeDefs[i];
if (nodeDef.getDeclaringNodeType().isAbstract()) {
continue;
}
if (nodeDef.isProtected()) {
continue;
}
if (nodeDef.getRequiredPrimaryTypes().length > 1) {
// of primary node types is not specified
continue;
}
if (regardDefaultPrimaryType) {
if (defaultPrimaryType && nodeDef.getDefaultPrimaryType() == null) {
continue;
}
if (!defaultPrimaryType && nodeDef.getDefaultPrimaryType() != null) {
continue;
}
}
if (residual && !nodeDef.getName().equals("*")) {
continue;
}
if (!residual) {
// if another child node def is a residual definition
// skip the current node type
NodeDefinition[] nodeDefsAll = type.getChildNodeDefinitions();
for (int j = 0; j < nodeDefsAll.length; j++) {
if (nodeDefsAll[j].getName().equals("*")) {
skip = true;
break;
}
}
if (skip) {
// break the loop of the current child not defs
skip = false;
break;
}
}
nodeTypes.add(nodeDef);
}
}
return nodeTypes;
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class ColumnTest method testExpandColumnsForNodeType.
/**
* From the spec:
* <p>
* If propertyName is not specified, a column is included for each
* single-valued non-residual property of the node type specified by the
* nodeType attribute of the selector selectorName.
* <p>
* [..] If propertyName is not specified,
* columnName must not be specified, and the included columns will be
* named "selectorName.propertyName".
*/
public void testExpandColumnsForNodeType() throws RepositoryException {
QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, SELECTOR_1), null, null, new Column[] { qf.column(SELECTOR_1, null, null) });
forQOMandSQL2(qom, new Callable() {
public Object call(Query query) throws RepositoryException {
QueryResult result = query.execute();
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
NodeType nt = ntMgr.getNodeType(testNodeType);
PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
Set<String> names = new HashSet<String>();
for (int i = 0; i < propDefs.length; i++) {
PropertyDefinition propDef = propDefs[i];
if (!propDef.isMultiple() && !propDef.getName().equals("*")) {
String columnName = SELECTOR_1 + "." + propDef.getName();
names.add(columnName);
}
}
for (String columnName : result.getColumnNames()) {
names.remove(columnName);
}
assertTrue("Missing required column(s): " + names, names.isEmpty());
return null;
}
});
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class SelectorTest method testUnknownNodeType.
public void testUnknownNodeType() throws RepositoryException {
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
String ntName = testNodeType;
for (; ; ) {
try {
ntMgr.getNodeType(ntName);
ntName += "x";
} catch (NoSuchNodeTypeException e) {
break;
}
}
try {
qf.createQuery(qf.selector(ntName, "s"), null, null, null).execute();
fail("Selector with unknown node type must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
try {
String stmt = "SELECT * FROM [" + ntName + "] AS nt";
qm.createQuery(stmt, Query.JCR_SQL2).execute();
fail("Selector with unknown node type must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class SameNodeTest method testChildNodesDoNotMatchSelector.
public void testChildNodesDoNotMatchSelector() throws RepositoryException, NotExecutableException {
testRootNode.addNode(nodeName1, testNodeType);
superuser.save();
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
NodeTypeIterator it = ntMgr.getPrimaryNodeTypes();
NodeType testNt = ntMgr.getNodeType(testNodeType);
while (it.hasNext()) {
NodeType nt = it.nextNodeType();
if (!testNt.isNodeType(nt.getName())) {
// perform test
QueryObjectModel qom = qf.createQuery(qf.selector(nt.getName(), "s"), qf.sameNode("s", testRoot + "/" + nodeName1), null, null);
checkQOM(qom, new Node[] {});
return;
}
}
throw new NotExecutableException("No suitable node type found to " + "perform test against '" + testNodeType + "' nodes");
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class NodeTypeUtil method locateChildNodeDef.
/**
* Locate a non-protected child node def declared by a non-abstract node type
* parsing all node types
*
* @param session the session to access the node types
* @param regardDefaultPrimaryType if true, the default primary type of the
* returned <code>NodeDef</code> is
* according to param <code>defaultPrimaryType</code>.
* If false, the returned <code>NodeDef</code>
* might have a default primary type or
* not.
* @param defaultPrimaryType if <code>regardDefaultPrimaryType</code>
* is true: if true, the returned
* <code>NodeDef</code> has a default
* primary type, else not
* @param residual if true, the returned <code>NodeDef</code>
* is of the residual name "*", else not
* @return
* @throws RepositoryException
*/
public static NodeDefinition locateChildNodeDef(Session session, boolean regardDefaultPrimaryType, boolean defaultPrimaryType, boolean residual) throws RepositoryException {
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator types = manager.getAllNodeTypes();
boolean skip = false;
while (types.hasNext()) {
NodeType type = types.nextNodeType();
// node types with more than one residual child node definition
// will cause trouble in test cases. the implementation
// might pick another definition than the definition returned by
// this method, when a child node is set.
NodeDefinition[] childDefs = type.getChildNodeDefinitions();
int residuals = 0;
for (int i = 0; i < childDefs.length; i++) {
if (childDefs[i].getName().equals("*")) {
residuals++;
}
}
if (residuals > 1) {
// more than one residual, not suitable for tests
continue;
}
NodeDefinition[] nodeDefs = type.getDeclaredChildNodeDefinitions();
for (int i = 0; i < nodeDefs.length; i++) {
NodeDefinition nodeDef = nodeDefs[i];
if (nodeDef.getDeclaringNodeType().isAbstract()) {
continue;
}
if (nodeDef.isProtected()) {
continue;
}
if (nodeDef.getRequiredPrimaryTypes().length > 1) {
// of primary node types is not specified
continue;
}
if (regardDefaultPrimaryType) {
if (defaultPrimaryType && nodeDef.getDefaultPrimaryType() == null) {
continue;
}
if (!defaultPrimaryType && nodeDef.getDefaultPrimaryType() != null) {
continue;
}
}
if (residual && !nodeDef.getName().equals("*")) {
continue;
}
if (!residual) {
// if another child node def is a residual definition
// skip the current node type
NodeDefinition[] nodeDefsAll = type.getChildNodeDefinitions();
for (int j = 0; j < nodeDefsAll.length; j++) {
if (nodeDefsAll[j].getName().equals("*")) {
skip = true;
break;
}
}
if (skip) {
// break the loop of the current child not defs
skip = false;
break;
}
}
return nodeDef;
}
}
return null;
}
Aggregations