Search in sources :

Example 6 with ListIndexException

use of org.apache.jena.rdf.model.ListIndexException 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

ListIndexException (org.apache.jena.rdf.model.ListIndexException)6 RDFList (org.apache.jena.rdf.model.RDFList)4 RDFNode (org.apache.jena.rdf.model.RDFNode)4 Test (org.junit.Test)3 SecuredRDFList (org.apache.jena.permissions.model.SecuredRDFList)2 Statement (org.apache.jena.rdf.model.Statement)2 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)2 Triple (org.apache.jena.graph.Triple)1 SecuredRDFNode (org.apache.jena.permissions.model.SecuredRDFNode)1 AccessDeniedException (org.apache.jena.shared.AccessDeniedException)1