Search in sources :

Example 71 with NodeType

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()]);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) AbstractNodeType(org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeType) ArrayList(java.util.ArrayList) Name(org.apache.jackrabbit.spi.Name) HashSet(java.util.HashSet) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 72 with NodeType

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;
}
Also used : PropertyValue(javax.jcr.query.qom.PropertyValue) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) QueryResult(javax.jcr.query.QueryResult) RowIteratorAdapter(org.apache.jackrabbit.commons.iterator.RowIteratorAdapter) NodeType(javax.jcr.nodetype.NodeType) RowIterator(javax.jcr.query.RowIterator) Sort(org.apache.lucene.search.Sort)

Example 73 with NodeType

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;
}
Also used : NodeType(javax.jcr.nodetype.NodeType) PropertyValue(javax.jcr.query.qom.PropertyValue) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Constraint(javax.jcr.query.qom.Constraint) LinkedHashMap(java.util.LinkedHashMap)

Example 74 with NodeType

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;
}
Also used : NodeType(javax.jcr.nodetype.NodeType)

Example 75 with NodeType

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);
    }
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) NodeType(javax.jcr.nodetype.NodeType) PathNotFoundException(javax.jcr.PathNotFoundException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

NodeType (javax.jcr.nodetype.NodeType)272 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)84 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)81 Node (javax.jcr.Node)63 Value (javax.jcr.Value)60 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)55 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)46 NodeDefinition (javax.jcr.nodetype.NodeDefinition)45 RepositoryException (javax.jcr.RepositoryException)41 ArrayList (java.util.ArrayList)30 Test (org.junit.Test)30 Session (javax.jcr.Session)29 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)16 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)15 Name (org.apache.jackrabbit.spi.Name)15 HashSet (java.util.HashSet)14 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)12 NodeIterator (javax.jcr.NodeIterator)7 Property (javax.jcr.Property)7 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)7