use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class NodeTypeImpl method getInheritedSupertypes.
/**
* Returns all <i>inherited</i> supertypes of this node type.
*
* @return an array of <code>NodeType</code> objects.
* @see #getSupertypes
* @see #getDeclaredSupertypes
*/
public NodeType[] getInheritedSupertypes() {
// declared supertypes
Name[] ntNames = ntd.getSupertypes();
Set<Name> declared = new HashSet<Name>();
for (Name ntName : ntNames) {
declared.add(ntName);
}
// all supertypes
ntNames = ent.getInheritedNodeTypes();
// filter from all supertypes those that are not declared
List<NodeType> inherited = new ArrayList<NodeType>();
for (Name ntName : ntNames) {
if (!declared.contains(ntName)) {
try {
inherited.add(ntMgr.getNodeType(ntName));
} catch (NoSuchNodeTypeException e) {
// should never get here
log.error("undefined supertype", e);
return new NodeType[0];
}
}
}
return inherited.toArray(new NodeType[inherited.size()]);
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class QueryEngine method execute.
protected QueryResult execute(Column[] columns, Selector selector, Constraint constraint, Ordering[] orderings, long offset, long limit, int printIndentation) throws RepositoryException {
long time = System.currentTimeMillis();
Map<String, NodeType> selectorMap = getSelectorNames(selector);
String[] selectorNames = selectorMap.keySet().toArray(new String[selectorMap.size()]);
Map<String, PropertyValue> columnMap = getColumnMap(columns, selectorMap);
String[] columnNames = columnMap.keySet().toArray(new String[columnMap.size()]);
Sort sort = new Sort();
if (NATIVE_SORT) {
sort = new Sort(createSortFields(orderings, session));
}
// if true it means that the LuceneQueryFactory should just let the
// QueryEngine take care of sorting and applying offset and limit
// constraints
boolean externalSort = !NATIVE_SORT;
RowIterator rows = null;
try {
rows = new RowIteratorAdapter(lqf.execute(columnMap, selector, constraint, sort, externalSort, offset, limit));
} catch (IOException e) {
throw new RepositoryException("Failed to access the query index", e);
} finally {
log.debug("{}SQL2 SELECT took {} ms. selector: {}, columns: {}, constraint: {}, offset {}, limit {}", new Object[] { genString(printIndentation), System.currentTimeMillis() - time, selector, Arrays.toString(columnNames), constraint, offset, limit });
}
QueryResult result = new SimpleQueryResult(columnNames, selectorNames, rows);
if (NATIVE_SORT) {
return result;
}
long timeSort = System.currentTimeMillis();
QueryResult sorted = sort(result, orderings, evaluator, offset, limit);
log.debug("{}SQL2 SORT took {} ms.", genString(printIndentation), System.currentTimeMillis() - timeSort);
return sorted;
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class QueryEngine method getColumnMap.
private Map<String, PropertyValue> getColumnMap(Column[] columns, Map<String, NodeType> selectors) throws RepositoryException {
Map<String, PropertyValue> map = new LinkedHashMap<String, PropertyValue>();
if (columns != null && columns.length > 0) {
for (int i = 0; i < columns.length; i++) {
String name = columns[i].getColumnName();
if (name != null) {
map.put(name, qomFactory.propertyValue(columns[i].getSelectorName(), columns[i].getPropertyName()));
} else {
String selector = columns[i].getSelectorName();
map.putAll(getColumnMap(selector, selectors.get(selector)));
}
}
} else {
for (Map.Entry<String, NodeType> selector : selectors.entrySet()) {
map.putAll(getColumnMap(selector.getKey(), selector.getValue()));
}
}
return map;
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class AbstractNode method isNodeType.
/**
* Checks whether this node is of the given type.
* <p>
* The default implementation iterates through the primary and mixin
* types and all the supertypes of this node, returning <code>true</code>
* if a type with the given name is encountered. Returns <code>false</code>
* if none of the types matches.
*
* @param name type name
* @return <code>true</code> if this node is of the given type,
* <code>false</code> otherwise
* @throws RepositoryException if an error occurs
*/
public boolean isNodeType(String name) throws RepositoryException {
NodeType type = getPrimaryNodeType();
if (name.equals(type.getName())) {
return true;
}
NodeType[] supertypes = type.getSupertypes();
for (int i = 0; i < supertypes.length; i++) {
if (name.equals(supertypes[i].getName())) {
return true;
}
}
NodeType[] mixins = getMixinNodeTypes();
for (int i = 0; i < mixins.length; i++) {
if (name.equals(mixins[i].getName())) {
return true;
}
supertypes = mixins[i].getSupertypes();
for (int j = 0; j < supertypes.length; j++) {
if (name.equals(supertypes[j].getName())) {
return true;
}
}
}
return false;
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class JcrRemotingServlet method doGet.
@Override
protected void doGet(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavResource davResource) throws IOException, DavException {
if (canHandle(DavMethods.DAV_GET, webdavRequest, davResource)) {
// return json representation of the requested resource
DavResourceLocator locator = davResource.getLocator();
String path = locator.getRepositoryPath();
Session session = getRepositorySession(webdavRequest);
try {
Node node = session.getNode(path);
int depth = ((WrappingLocator) locator).getDepth();
webdavResponse.setContentType("text/plain;charset=utf-8");
webdavResponse.setStatus(DavServletResponse.SC_OK);
JsonWriter writer = new JsonWriter(webdavResponse.getWriter());
String[] includes = webdavRequest.getParameterValues(PARAM_INCLUDE);
if (includes == null) {
if (depth < BatchReadConfig.DEPTH_INFINITE) {
NodeType type = node.getPrimaryNodeType();
depth = brConfig.getDepth(type.getName());
}
writer.write(node, depth);
} else {
writeMultiple(writer, node, includes, depth);
}
} catch (PathNotFoundException e) {
// properties cannot be requested as json object.
throw new JcrDavException(new ItemNotFoundException("No node at " + path), DavServletResponse.SC_NOT_FOUND);
} catch (RepositoryException e) {
// should only get here if the item does not exist.
log.debug(e.getMessage());
throw new JcrDavException(e);
}
} else {
super.doGet(webdavRequest, webdavResponse, davResource);
}
}
Aggregations