Search in sources :

Example 11 with RDFList

use of org.apache.jena.rdf.model.RDFList in project jena by apache.

the class SecuredRDFListImpl method baseRemove.

/**
 * Removes val from underlying list.
 *
 * @param val
 * @return the modified RDFList.
 */
private RDFList baseRemove(final RDFList val) {
    RDFList prev = null;
    RDFList cell = holder.getBaseItem();
    final boolean searching = true;
    while (searching && !cell.isEmpty()) {
        if (cell.equals(val)) {
            // found the value to be removed
            final RDFList tail = cell.getTail();
            if (prev != null) {
                prev.setTail(tail);
            }
            cell.removeProperties();
            // return this unless we have removed the head element
            return (prev == null) ? tail : this;
        }
        // not found yet
        prev = cell;
        cell = cell.getTail();
    }
    // not found
    return this;
}
Also used : SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList) RDFList(org.apache.jena.rdf.model.RDFList)

Example 12 with RDFList

use of org.apache.jena.rdf.model.RDFList in project jena by apache.

the class SecuredRDFListImpl method setTail.

@Override
public SecuredRDFList setTail(final RDFList tail) throws UpdateDeniedException, AuthenticationRequiredException {
    checkUpdate();
    final Statement rest = holder.getBaseItem().getRequiredProperty(RDF.rest);
    final RDFNode retval = rest.getObject();
    final Triple t = new Triple(holder.getBaseItem().asNode(), RDF.rest.asNode(), retval.asNode());
    final Triple t2 = new Triple(holder.getBaseItem().asNode(), RDF.rest.asNode(), tail.asNode());
    checkUpdate(t, t2);
    rest.changeObject(tail);
    return SecuredRDFListImpl.getInstance(getModel(), retval.as(RDFList.class));
}
Also used : Triple(org.apache.jena.graph.Triple) SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList) RDFList(org.apache.jena.rdf.model.RDFList) Statement(org.apache.jena.rdf.model.Statement) RDFNode(org.apache.jena.rdf.model.RDFNode) SecuredRDFNode(org.apache.jena.permissions.model.SecuredRDFNode)

Example 13 with RDFList

use of org.apache.jena.rdf.model.RDFList in project jena by apache.

the class SecuredRDFListImpl method replace.

/**
 * @sec.graph Update
 * @sec.triple Update for triple i, and value.
 * @throws UpdateDeniedException
 * @throws EmptyListException
 * @throws ListIndexException
 * @throws InvalidListException
 * @throws AuthenticationRequiredException if user is not authenticated and is
 *                                         required to be.
 */
@Override
public SecuredRDFNode replace(final int i, final RDFNode value) throws UpdateDeniedException, AuthenticationRequiredException, ListIndexException {
    checkUpdate();
    // get all the ones we can see since the replace must be against one we could
    // see.
    final ExtendedIterator<RDFList> iter = getFilteredRDFListIterator(Action.Read);
    int idx = 0;
    try {
        while (iter.hasNext()) {
            // seek to the proper position.
            if (i == idx) {
                // verify we can delete and if so delete.
                final RDFList list = iter.next();
                final RDFNode retval = list.getRequiredProperty(RDF.first).getObject();
                final Triple t = new Triple(list.asNode(), RDF.first.asNode(), retval.asNode());
                final Triple t2 = new Triple(list.asNode(), RDF.first.asNode(), value.asNode());
                checkUpdate(t, t2);
                list.getRequiredProperty(RDF.first).changeObject(value);
                return SecuredRDFNodeImpl.getInstance(getModel(), retval);
            }
            idx++;
            iter.next();
        }
        throw new ListIndexException();
    } finally {
        iter.close();
    }
}
Also used : Triple(org.apache.jena.graph.Triple) SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList) RDFList(org.apache.jena.rdf.model.RDFList) ListIndexException(org.apache.jena.rdf.model.ListIndexException) RDFNode(org.apache.jena.rdf.model.RDFNode) SecuredRDFNode(org.apache.jena.permissions.model.SecuredRDFNode)

Aggregations

RDFList (org.apache.jena.rdf.model.RDFList)13 RDFNode (org.apache.jena.rdf.model.RDFNode)8 SecuredRDFList (org.apache.jena.permissions.model.SecuredRDFList)6 Test (org.junit.Test)5 AccessDeniedException (org.apache.jena.shared.AccessDeniedException)4 Triple (org.apache.jena.graph.Triple)3 EmptyListException (org.apache.jena.rdf.model.EmptyListException)3 ListIndexException (org.apache.jena.rdf.model.ListIndexException)3 SecuredRDFNode (org.apache.jena.permissions.model.SecuredRDFNode)2 Statement (org.apache.jena.rdf.model.Statement)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Assembler (org.apache.jena.assembler.Assembler)1 Mode (org.apache.jena.assembler.Mode)1 AssemblerBase (org.apache.jena.assembler.assemblers.AssemblerBase)1 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)1