use of org.apache.jena.permissions.model.SecuredRDFList in project jena by apache.
the class SecuredRDFListImpl method getInstance.
/**
* Get an instance of SecuredProperty
*
* @param securedModel
* the Secured Model to use.
* @param rdfList
* The rdfList to secure
* @return The SecuredProperty
*/
public static <T extends RDFList> SecuredRDFList getInstance(final SecuredModel securedModel, final T rdfList) {
if (securedModel == null) {
throw new IllegalArgumentException("Secured securedModel may not be null");
}
if (rdfList == null) {
throw new IllegalArgumentException("RDFList may not be null");
}
// check that property has a securedModel.
RDFList goodList = rdfList;
if (goodList.getModel() == null) {
goodList = securedModel.createList(rdfList.asJavaList().iterator());
}
final ItemHolder<RDFList, SecuredRDFList> holder = new ItemHolder<>(goodList);
final SecuredRDFListImpl checker = new SecuredRDFListImpl(securedModel, holder);
// one.
if (goodList instanceof SecuredRDFList) {
if (checker.isEquivalent((SecuredRDFList) goodList)) {
return (SecuredRDFList) goodList;
}
}
return holder.setSecuredItem(new SecuredItemInvoker(rdfList.getClass(), checker));
}
use of org.apache.jena.permissions.model.SecuredRDFList in project jena by apache.
the class SecuredRDFListImpl method removeHead.
@Override
public SecuredRDFList removeHead() throws UpdateDeniedException, DeleteDeniedException, AuthenticationRequiredException {
checkUpdate();
final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator(Action.Read).mapWith(new SecuredListMap());
try {
if (!iter.hasNext()) {
throw new EmptyListException("Attempted to delete the head of a nil list");
}
final SecuredRDFList cell = iter.next();
final Statement s = cell.getRequiredProperty(RDF.first);
checkDelete(s);
return SecuredRDFListImpl.getInstance(getModel(), baseRemove(cell));
} finally {
iter.close();
}
}
use of org.apache.jena.permissions.model.SecuredRDFList 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(listRest());
final RDFNode retval = rest.getObject();
final Triple t = new Triple(holder.getBaseItem().asNode(), listRest().asNode(), retval.asNode());
final Triple t2 = new Triple(holder.getBaseItem().asNode(), listRest().asNode(), tail.asNode());
checkUpdate(t, t2);
rest.changeObject(tail);
return SecuredRDFListImpl.getInstance(getModel(), retval.as(RDFList.class));
}
use of org.apache.jena.permissions.model.SecuredRDFList in project jena by apache.
the class SecuredRDFListImpl method replace.
@Override
public SecuredRDFNode replace(final int i, final RDFNode value) throws UpdateDeniedException, AuthenticationRequiredException, ListIndexException {
checkUpdate();
final SecuredNodeMap map = new SecuredNodeMap(listFirst());
final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator(Action.Read).mapWith(new SecuredListMap());
int idx = 0;
try {
while (iter.hasNext()) {
if (i == idx) {
final SecuredRDFList list = iter.next();
final SecuredRDFNode retval = map.apply(list);
final Triple t = new Triple(list.asNode(), listFirst().asNode(), retval.asNode());
final Triple t2 = new Triple(list.asNode(), listFirst().asNode(), value.asNode());
checkUpdate(t, t2);
final RDFList base = (RDFList) list.getBaseItem();
base.getRequiredProperty(listFirst()).changeObject(value);
return retval;
} else {
idx++;
iter.next();
}
}
throw new ListIndexException();
} finally {
iter.close();
}
}
Aggregations