Search in sources :

Example 1 with IdFactory

use of org.apache.jackrabbit.spi.IdFactory in project jackrabbit by apache.

the class NodeEntryImpl method getDeepPropertyEntry.

/**
     * @see NodeEntry#getDeepPropertyEntry(Path)
     */
public PropertyEntry getDeepPropertyEntry(Path path) throws PathNotFoundException, RepositoryException {
    NodeEntryImpl entry = this;
    Path.Element[] elems = path.getElements();
    int i = 0;
    for (; i < elems.length - 1; i++) {
        Path.Element elem = elems[i];
        if (elems[i].denotesRoot()) {
            if (entry.getParent() != null) {
                throw new RepositoryException("NodeEntry out of 'hierarchy' " + path.toString());
            }
            continue;
        }
        int index = elem.getNormalizedIndex();
        Name name = elem.getName();
        // first try to resolve to known node or property entry
        NodeEntry cne = entry.getNodeEntry(name, index, false);
        if (cne != null) {
            entry = (NodeEntryImpl) cne;
        } else {
            //    on the persistent layer.
            if (entry.childNodeEntries.isComplete()) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // -> check for moved child entry in node-attic
            // -> check if child points to a removed/moved sns
            List<NodeEntry> siblings = entry.childNodeEntries.get(name);
            if (entry.containsAtticChild(siblings, name, index)) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // break out of the loop and start deep loading the property
            break;
        }
    }
    int st = entry.getStatus();
    PropertyEntry pe;
    if (i == elems.length - 1 && Status.INVALIDATED != st && Status._UNDEFINED_ != st) {
        // all node entries present in the hierarchy and the direct ancestor
        // has already been resolved and isn't invalidated -> no need to
        // retrieve property entry from SPI
        pe = entry.properties.get(path.getName());
    } else {
        /*
            * Unknown parent entry (not-existing or not yet loaded) or a parent
            * entry that has been invalidated:
            * Skip all intermediate entries and directly try to load the
            * PropertyState (including building the intermediate entries. If that
            * fails ItemNotFoundException is thrown.
            */
        PathBuilder pb = new PathBuilder(getPathFactory());
        for (int j = i; j < elems.length; j++) {
            pb.addLast(elems[j]);
        }
        Path remainingPath = pb.getPath();
        IdFactory idFactory = getIdFactory();
        NodeId parentId = entry.getWorkspaceId();
        if (remainingPath.getLength() != 1) {
            parentId = idFactory.createNodeId(parentId, remainingPath.getAncestor(1));
        }
        PropertyId propId = idFactory.createPropertyId(parentId, remainingPath.getName());
        pe = entry.loadPropertyEntry(propId);
    }
    if (pe == null) {
        throw new PathNotFoundException(factory.saveGetJCRPath(path));
    }
    return pe;
}
Also used : Path(org.apache.jackrabbit.spi.Path) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.spi.PropertyId) PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) IdFactory(org.apache.jackrabbit.spi.IdFactory) NodeId(org.apache.jackrabbit.spi.NodeId) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 2 with IdFactory

use of org.apache.jackrabbit.spi.IdFactory in project jackrabbit by apache.

the class Spi2davRepositoryServiceFactory method createRepositoryService.

public RepositoryService createRepositoryService(Map<?, ?> parameters) throws RepositoryException {
    if (parameters == null) {
        throw new RepositoryException("Parameter " + PARAM_REPOSITORY_URI + " missing");
    }
    String uri;
    if (parameters.get(PARAM_REPOSITORY_URI) == null) {
        throw new RepositoryException("Parameter " + PARAM_REPOSITORY_URI + " missing");
    } else {
        uri = parameters.get(PARAM_REPOSITORY_URI).toString();
    }
    IdFactory idFactory;
    Object param = parameters.get(PARAM_ID_FACTORY);
    if (param != null && param instanceof IdFactory) {
        idFactory = (IdFactory) param;
    } else {
        idFactory = IdFactoryImpl.getInstance();
    }
    NameFactory nameFactory;
    param = parameters.get(PARAM_NAME_FACTORY);
    if (param != null && param instanceof NameFactory) {
        nameFactory = (NameFactory) param;
    } else {
        nameFactory = NameFactoryImpl.getInstance();
    }
    PathFactory pathFactory;
    param = parameters.get(PARAM_PATH_FACTORY);
    if (param != null && param instanceof PathFactory) {
        pathFactory = (PathFactory) param;
    } else {
        pathFactory = PathFactoryImpl.getInstance();
    }
    QValueFactory vFactory;
    param = parameters.get(PARAM_QVALUE_FACTORY);
    if (param != null && param instanceof QValueFactory) {
        vFactory = (QValueFactory) param;
    } else {
        vFactory = QValueFactoryImpl.getInstance();
    }
    int itemInfoCacheSize = ItemInfoCacheImpl.DEFAULT_CACHE_SIZE;
    param = parameters.get(PARAM_ITEMINFO_CACHE_SIZE);
    if (param != null) {
        try {
            itemInfoCacheSize = Integer.parseInt(param.toString());
        } catch (NumberFormatException e) {
        // ignore, use default
        }
    }
    // max connections config
    int maximumHttpConnections = 0;
    param = parameters.get(PARAM_MAX_CONNECTIONS);
    if (param != null) {
        try {
            maximumHttpConnections = Integer.parseInt(param.toString());
        } catch (NumberFormatException e) {
        // using default
        }
    }
    if (maximumHttpConnections > 0) {
        return new RepositoryServiceImpl(uri, idFactory, nameFactory, pathFactory, vFactory, itemInfoCacheSize, maximumHttpConnections);
    } else {
        return new RepositoryServiceImpl(uri, idFactory, nameFactory, pathFactory, vFactory, itemInfoCacheSize);
    }
}
Also used : IdFactory(org.apache.jackrabbit.spi.IdFactory) PathFactory(org.apache.jackrabbit.spi.PathFactory) RepositoryException(javax.jcr.RepositoryException) QValueFactory(org.apache.jackrabbit.spi.QValueFactory) NameFactory(org.apache.jackrabbit.spi.NameFactory)

Example 3 with IdFactory

use of org.apache.jackrabbit.spi.IdFactory in project jackrabbit by apache.

the class ItemDefinitionProviderImpl method getRootNodeDefinition.

public QNodeDefinition getRootNodeDefinition() throws RepositoryException {
    if (rootNodeDefinition == null) {
        IdFactory idFactory = service.getIdFactory();
        PathFactory pf = service.getPathFactory();
        rootNodeDefinition = service.getNodeDefinition(sessionInfo, idFactory.createNodeId((String) null, pf.getRootPath()));
    }
    return rootNodeDefinition;
}
Also used : IdFactory(org.apache.jackrabbit.spi.IdFactory) PathFactory(org.apache.jackrabbit.spi.PathFactory)

Example 4 with IdFactory

use of org.apache.jackrabbit.spi.IdFactory in project jackrabbit by apache.

the class NodeEntryImpl method getDeepNodeEntry.

/**
     * @see NodeEntry#getDeepNodeEntry(Path)
     */
public NodeEntry getDeepNodeEntry(Path path) throws PathNotFoundException, RepositoryException {
    NodeEntryImpl entry = this;
    Path.Element[] elems = path.getElements();
    for (int i = 0; i < elems.length; i++) {
        Path.Element elem = elems[i];
        // check for root element
        if (elem.denotesRoot()) {
            if (entry.getParent() != null) {
                throw new RepositoryException("NodeEntry out of 'hierarchy' " + path.toString());
            }
            continue;
        }
        int index = elem.getNormalizedIndex();
        Name name = elem.getName();
        // first try to resolve to known node or property entry
        NodeEntry cne = entry.getNodeEntry(name, index, false);
        if (cne != null) {
            entry = (NodeEntryImpl) cne;
        } else {
            //    on the persistent layer.
            if (entry.childNodeEntries.isComplete()) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // -> check for moved child entry in node-attic
            // -> check if child points to a removed/moved sns
            List<NodeEntry> siblings = entry.childNodeEntries.get(name);
            if (entry.containsAtticChild(siblings, name, index)) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // elements -> hierarchy doesn't exist anyway.
            if (entry.getStatus() == Status.NEW) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            /*
                * Unknown entry (not-existing or not yet loaded):
                * Skip all intermediate entries and directly try to load the ItemState
                * (including building the intermediate entries. If that fails
                * ItemNotFoundException is thrown.
                *
                * Since 'path' might be ambiguous (Node or Property):
                * 1) first try Node
                * 2) if the NameElement does not have SNS-index => try Property
                * 3) else throw
                */
            PathBuilder pb = new PathBuilder(getPathFactory());
            for (int j = i; j < elems.length; j++) {
                pb.addLast(elems[j]);
            }
            Path remainingPath = pb.getPath();
            NodeId parentId = entry.getWorkspaceId();
            IdFactory idFactory = factory.getIdFactory();
            NodeId nodeId = idFactory.createNodeId(parentId, remainingPath);
            NodeEntry ne = entry.loadNodeEntry(nodeId);
            if (ne != null) {
                return ne;
            } else {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
        }
    }
    return entry;
}
Also used : Path(org.apache.jackrabbit.spi.Path) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) IdFactory(org.apache.jackrabbit.spi.IdFactory) NodeId(org.apache.jackrabbit.spi.NodeId) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 5 with IdFactory

use of org.apache.jackrabbit.spi.IdFactory in project jackrabbit by apache.

the class WorkspaceItemStateFactory method createRootState.

public NodeState createRootState(NodeEntry entry) throws ItemNotFoundException, RepositoryException {
    IdFactory idFactory = service.getIdFactory();
    PathFactory pf = service.getPathFactory();
    return createNodeState(idFactory.createNodeId((String) null, pf.getRootPath()), entry);
}
Also used : IdFactory(org.apache.jackrabbit.spi.IdFactory) PathFactory(org.apache.jackrabbit.spi.PathFactory)

Aggregations

IdFactory (org.apache.jackrabbit.spi.IdFactory)7 PathFactory (org.apache.jackrabbit.spi.PathFactory)5 RepositoryException (javax.jcr.RepositoryException)3 NameFactory (org.apache.jackrabbit.spi.NameFactory)3 QValueFactory (org.apache.jackrabbit.spi.QValueFactory)3 PathNotFoundException (javax.jcr.PathNotFoundException)2 Name (org.apache.jackrabbit.spi.Name)2 NodeId (org.apache.jackrabbit.spi.NodeId)2 Path (org.apache.jackrabbit.spi.Path)2 PathBuilder (org.apache.jackrabbit.spi.commons.name.PathBuilder)2 PropertyId (org.apache.jackrabbit.spi.PropertyId)1