You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by cl...@apache.org on 2015/08/07 20:56:18 UTC
[07/13] jena git commit: Added throw exception documentation
http://git-wip-us.apache.org/repos/asf/jena/blob/2c0454c6/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredAltImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredAltImpl.java b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredAltImpl.java
index 598c070..f5947ab 100644
--- a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredAltImpl.java
+++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredAltImpl.java
@@ -17,7 +17,7 @@
*/
package org.apache.jena.permissions.model.impl;
-import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.Triple;
import org.apache.jena.permissions.SecurityEvaluator.Action;
import org.apache.jena.permissions.impl.ItemHolder;
import org.apache.jena.permissions.impl.SecuredItemInvoker;
@@ -28,14 +28,16 @@ import org.apache.jena.permissions.model.SecuredModel;
import org.apache.jena.permissions.model.SecuredRDFNode;
import org.apache.jena.permissions.model.SecuredResource;
import org.apache.jena.permissions.model.SecuredSeq;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.rdf.model.*;
+import org.apache.jena.shared.AuthenticationRequiredException;
+import org.apache.jena.shared.ReadDeniedException;
+import org.apache.jena.shared.UpdateDeniedException;
+import org.apache.jena.util.iterator.ExtendedIterator;
/**
* Implementation of SecuredAlt to be used by a SecuredItemInvoker proxy.
*/
-public class SecuredAltImpl extends SecuredContainerImpl implements SecuredAlt
-{
+public class SecuredAltImpl extends SecuredContainerImpl implements SecuredAlt {
/**
* Get an instance of SecuredAlt.
*
@@ -45,16 +47,13 @@ public class SecuredAltImpl extends SecuredContainerImpl implements SecuredAlt
* The Alt to be secured.
* @return The secured Alt instance.
*/
- public static SecuredAlt getInstance( final SecuredModel securedModel,
- final Alt alt )
- {
- if (securedModel == null)
- {
+ public static SecuredAlt getInstance(final SecuredModel securedModel,
+ final Alt alt) {
+ if (securedModel == null) {
throw new IllegalArgumentException(
"Secured securedModel may not be null");
}
- if (alt == null)
- {
+ if (alt == null) {
throw new IllegalArgumentException("Alt may not be null");
}
final ItemHolder<Alt, SecuredAlt> holder = new ItemHolder<Alt, SecuredAlt>(
@@ -62,10 +61,8 @@ public class SecuredAltImpl extends SecuredContainerImpl implements SecuredAlt
final SecuredAltImpl checker = new SecuredAltImpl(securedModel, holder);
// if we are going to create a duplicate proxy, just return this
// one.
- if (alt instanceof SecuredAlt)
- {
- if (checker.isEquivalent((SecuredAlt) alt))
- {
+ if (alt instanceof SecuredAlt) {
+ if (checker.isEquivalent((SecuredAlt) alt)) {
return (SecuredAlt) alt;
}
}
@@ -84,104 +81,103 @@ public class SecuredAltImpl extends SecuredContainerImpl implements SecuredAlt
* @param holder
* The item holder that will hold this SecuredAlt.
*/
- protected SecuredAltImpl( final SecuredModel securedModel,
- final ItemHolder<? extends Alt, ? extends SecuredAlt> holder )
- {
+ protected SecuredAltImpl(final SecuredModel securedModel,
+ final ItemHolder<? extends Alt, ? extends SecuredAlt> holder) {
super(securedModel, holder);
this.holder = holder;
}
@Override
- public SecuredRDFNode getDefault()
- {
+ public SecuredRDFNode getDefault() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return SecuredRDFNodeImpl.getInstance(getModel(), getDefaultStatement()
.getObject());
}
@Override
- public SecuredAlt getDefaultAlt()
- {
+ public SecuredAlt getDefaultAlt() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return SecuredAltImpl.getInstance(getModel(), getDefaultStatement()
.getAlt());
}
@Override
- public SecuredBag getDefaultBag()
- {
+ public SecuredBag getDefaultBag() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return SecuredBagImpl.getInstance(getModel(), getDefaultStatement()
.getBag());
}
@Override
- public boolean getDefaultBoolean()
- {
+ public boolean getDefaultBoolean() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return getDefaultStatement().getBoolean();
}
@Override
- public byte getDefaultByte()
- {
+ public byte getDefaultByte() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return getDefaultStatement().getByte();
}
@Override
- public char getDefaultChar()
- {
+ public char getDefaultChar() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return getDefaultStatement().getChar();
}
@Override
- public double getDefaultDouble()
- {
+ public double getDefaultDouble() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return getDefaultStatement().getDouble();
}
@Override
- public float getDefaultFloat()
- {
+ public float getDefaultFloat() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return getDefaultStatement().getFloat();
}
@Override
- public int getDefaultInt()
- {
+ public int getDefaultInt() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return getDefaultStatement().getInt();
}
@Override
- public String getDefaultLanguage()
- {
+ public String getDefaultLanguage() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return getDefaultStatement().getLanguage();
}
@Override
- public SecuredLiteral getDefaultLiteral()
- {
+ public SecuredLiteral getDefaultLiteral() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return SecuredLiteralImpl.getInstance(getModel(), getDefaultStatement()
.getLiteral());
}
@Override
- public long getDefaultLong()
- {
+ public long getDefaultLong() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return getDefaultStatement().getLong();
}
@Override
- public SecuredResource getDefaultResource()
- {
+ public SecuredResource getDefaultResource() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return SecuredResourceImpl.getInstance(getModel(),
getDefaultStatement().getResource());
@@ -189,122 +185,94 @@ public class SecuredAltImpl extends SecuredContainerImpl implements SecuredAlt
@Override
@Deprecated
- public SecuredResource getDefaultResource( final ResourceF f )
- {
+ public SecuredResource getDefaultResource(final ResourceF f)
+ throws ReadDeniedException, AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return SecuredResourceImpl.getInstance(getModel(),
getDefaultStatement().getResource(f));
}
@Override
- public SecuredSeq getDefaultSeq()
- {
+ public SecuredSeq getDefaultSeq() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return SecuredSeqImpl.getInstance(getModel(), getDefaultStatement()
.getSeq());
}
@Override
- public short getDefaultShort()
- {
+ public short getDefaultShort() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return getDefaultStatement().getShort();
}
- private Statement getDefaultStatement()
- {
+ private Statement getDefaultStatement() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
final ExtendedIterator<Statement> iter = getStatementIterator(Action.Read);
- try
- {
- if (iter.hasNext())
- {
+ try {
+ if (iter.hasNext()) {
return iter.next();
}
throw new AltHasNoDefaultException(this);
- }
- finally
- {
+ } finally {
iter.close();
}
}
@Override
- public String getDefaultString()
- {
+ public String getDefaultString() throws ReadDeniedException,
+ AuthenticationRequiredException {
// getDefaultStatement() calls checkRead
return getDefaultStatement().getString();
}
- /*
- * private SecTriple getDefaultTriple()
- * {
- * final StmtIterator iter = holder.getBaseItem().getModel()
- * .listStatements(this, RDF.li(1), (RDFNode) null);
- * try
- * {
- * return iter.hasNext() ? iter.nextStatement().asTriple() : null;
- * }
- * finally
- * {
- * iter.close();
- * }
- *
- * }
- *
- * private SecTriple getNewTriple( final SecTriple t, final Object o )
- * {
- * return new SecTriple(t.getSubject(), t.getPredicate(),
- * SecNode.createLiteral(
- * String.valueOf(o), "", false));
- * }
- */
@Override
- public SecuredAlt setDefault( final boolean o )
- {
- return setDefault( asObject( o ));
+ public SecuredAlt setDefault(final boolean o) throws UpdateDeniedException,
+ AuthenticationRequiredException {
+ return setDefault(asObject(o));
}
@Override
- public SecuredAlt setDefault( final char o )
- {
- return setDefault( asObject( o ));
+ public SecuredAlt setDefault(final char o) throws UpdateDeniedException,
+ AuthenticationRequiredException {
+ return setDefault(asObject(o));
}
@Override
- public SecuredAlt setDefault( final double o )
- {
- return setDefault( asObject( o ));
+ public SecuredAlt setDefault(final double o) throws UpdateDeniedException,
+ AuthenticationRequiredException {
+ return setDefault(asObject(o));
}
@Override
- public SecuredAlt setDefault( final float o )
- {
- return setDefault( asObject( o ));
+ public SecuredAlt setDefault(final float o) throws UpdateDeniedException,
+ AuthenticationRequiredException {
+ return setDefault(asObject(o));
}
@Override
- public SecuredAlt setDefault( final long o )
- {
- return setDefault( asObject( o ));
+ public SecuredAlt setDefault(final long o) throws UpdateDeniedException,
+ AuthenticationRequiredException {
+ return setDefault(asObject(o));
}
@Override
- public SecuredAlt setDefault( final Object o )
- {
- return setDefault( asObject( o ));
+ public SecuredAlt setDefault(final Object o) throws UpdateDeniedException,
+ AuthenticationRequiredException {
+ return setDefault(asObject(o));
}
@Override
- public SecuredAlt setDefault( final RDFNode o )
- {
- checkUpdate();
+ public SecuredAlt setDefault(final RDFNode o) throws UpdateDeniedException,
+ AuthenticationRequiredException {
+ checkUpdate();
final ExtendedIterator<Statement> iter = getStatementIterator(Action.Read);
try {
- if (iter.hasNext())
- {
+ if (iter.hasNext()) {
final Statement stmt = iter.next();
final Triple t = stmt.asTriple();
final Triple t2 = new Triple(t.getSubject(), t.getPredicate(),
@@ -312,28 +280,25 @@ public class SecuredAltImpl extends SecuredContainerImpl implements SecuredAlt
checkUpdate(t, t2);
stmt.changeObject(o);
return holder.getSecuredItem();
- }
- else
- {
- add( o );
+ } else {
+ add(o);
return holder.getSecuredItem();
}
- }
- finally {
+ } finally {
iter.close();
}
-
+
}
@Override
- public SecuredAlt setDefault( final String o )
- {
- return setDefault( asLiteral( o, "" ));
+ public SecuredAlt setDefault(final String o) throws UpdateDeniedException,
+ AuthenticationRequiredException {
+ return setDefault(asLiteral(o, ""));
}
@Override
- public SecuredAlt setDefault( final String o, final String l )
- {
- return setDefault( asLiteral( o, l) );
+ public SecuredAlt setDefault(final String o, final String l)
+ throws UpdateDeniedException, AuthenticationRequiredException {
+ return setDefault(asLiteral(o, l));
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/2c0454c6/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredContainerImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredContainerImpl.java b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredContainerImpl.java
index 1f7f969..9fc4490 100644
--- a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredContainerImpl.java
+++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredContainerImpl.java
@@ -24,8 +24,8 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.Triple;
import org.apache.jena.permissions.SecurityEvaluator.Action;
import org.apache.jena.permissions.impl.ItemHolder;
import org.apache.jena.permissions.impl.SecuredItemInvoker;
@@ -33,17 +33,21 @@ import org.apache.jena.permissions.model.SecuredContainer;
import org.apache.jena.permissions.model.SecuredModel;
import org.apache.jena.permissions.utils.ContainerFilter;
import org.apache.jena.permissions.utils.PermStatementFilter;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.WrappedIterator ;
-import org.apache.jena.vocabulary.RDF ;
+import org.apache.jena.rdf.model.*;
+import org.apache.jena.shared.AddDeniedException;
+import org.apache.jena.shared.AuthenticationRequiredException;
+import org.apache.jena.shared.DeleteDeniedException;
+import org.apache.jena.shared.ReadDeniedException;
+import org.apache.jena.shared.UpdateDeniedException;
+import org.apache.jena.util.iterator.ExtendedIterator;
+import org.apache.jena.util.iterator.WrappedIterator;
+import org.apache.jena.vocabulary.RDF;
/**
* Implementation of SecuredContainer to be used by a SecuredItemInvoker proxy.
*/
public class SecuredContainerImpl extends SecuredResourceImpl implements
- SecuredContainer
-{
+ SecuredContainer {
/**
* Constructor
*
@@ -53,23 +57,19 @@ public class SecuredContainerImpl extends SecuredResourceImpl implements
* The container to secure.
* @return The SecuredResource
*/
- public static SecuredContainer getInstance(
- final SecuredModel securedModel, final Container container )
- {
- if (securedModel == null)
- {
+ public static SecuredContainer getInstance(final SecuredModel securedModel,
+ final Container container) {
+ if (securedModel == null) {
throw new IllegalArgumentException(
"Secured securedModel may not be null");
}
- if (container == null)
- {
+ if (container == null) {
throw new IllegalArgumentException("Container may not be null");
}
// check that resource has a securedModel.
Container goodContainer = container;
- if (goodContainer.getModel() == null)
- {
+ if (goodContainer.getModel() == null) {
container.asNode();
goodContainer = securedModel.createBag();
}
@@ -81,10 +81,8 @@ public class SecuredContainerImpl extends SecuredResourceImpl implements
securedModel, holder);
// if we are going to create a duplicate proxy, just return this
// one.
- if (goodContainer instanceof SecuredContainer)
- {
- if (checker.isEquivalent((SecuredContainer) goodContainer))
- {
+ if (goodContainer instanceof SecuredContainer) {
+ if (checker.isEquivalent((SecuredContainer) goodContainer)) {
return (SecuredContainer) goodContainer;
}
}
@@ -107,63 +105,61 @@ public class SecuredContainerImpl extends SecuredResourceImpl implements
*/
protected SecuredContainerImpl(
final SecuredModel securedModel,
- final ItemHolder<? extends Container, ? extends SecuredContainer> holder )
- {
+ final ItemHolder<? extends Container, ? extends SecuredContainer> holder) {
super(securedModel, holder);
this.holder = holder;
// listener=new ChangeListener();
// holder.getBaseItem().getModel().register(listener);
}
- protected RDFNode asObject( Object o )
- {
- return o instanceof RDFNode ? (RDFNode) o : ResourceFactory.createTypedLiteral( o );
- }
-
- protected RDFNode asLiteral( String o, String l )
- {
+ protected RDFNode asObject(Object o) {
+ return o instanceof RDFNode ? (RDFNode) o : ResourceFactory
+ .createTypedLiteral(o);
+ }
+
+ protected RDFNode asLiteral(String o, String l) {
return holder.getBaseItem().getModel().createLiteral(o, l);
}
-
+
@Override
- public SecuredContainer add( final boolean o )
- {
- return add( asObject( o ));
+ public SecuredContainer add(final boolean o) throws AddDeniedException,
+ UpdateDeniedException, AuthenticationRequiredException {
+ return add(asObject(o));
}
@Override
- public SecuredContainer add( final char o )
- {
- return add( asObject( o ));
+ public SecuredContainer add(final char o) throws AddDeniedException,
+ UpdateDeniedException, AuthenticationRequiredException {
+ return add(asObject(o));
}
@Override
- public SecuredContainer add( final double o )
- {
- return add( asObject( o ));
+ public SecuredContainer add(final double o) throws AddDeniedException,
+ UpdateDeniedException, AuthenticationRequiredException {
+ return add(asObject(o));
}
@Override
- public SecuredContainer add( final float o )
- {
- return add( asObject( o ));
+ public SecuredContainer add(final float o) throws AddDeniedException,
+ UpdateDeniedException, AuthenticationRequiredException {
+ return add(asObject(o));
}
@Override
- public SecuredContainer add( final long o )
- {
- return add( asObject( o ));
+ public SecuredContainer add(final long o) throws AddDeniedException,
+ UpdateDeniedException, AuthenticationRequiredException {
+ return add(asObject(o));
}
@Override
- public SecuredContainer add( final Object o )
- {
- return add( asObject( o ));
+ public SecuredContainer add(final Object o) throws AddDeniedException,
+ UpdateDeniedException, AuthenticationRequiredException {
+ return add(asObject(o));
}
@Override
- public SecuredContainer add( final RDFNode o )
- {
+ public SecuredContainer add(final RDFNode o) throws AddDeniedException,
+ UpdateDeniedException, AuthenticationRequiredException {
checkUpdate();
final int pos = holder.getBaseItem().size();
checkAdd(pos, o.asNode());
@@ -172,73 +168,74 @@ public class SecuredContainerImpl extends SecuredResourceImpl implements
}
@Override
- public SecuredContainer add( final String o )
- {
- return add( asLiteral( o, "" ));
+ public SecuredContainer add(final String o) throws AddDeniedException,
+ UpdateDeniedException, AuthenticationRequiredException {
+ return add(asLiteral(o, ""));
}
@Override
- public SecuredContainer add( final String o, final String l )
- {
- return add( asLiteral( o, l));
+ public SecuredContainer add(final String o, final String l)
+ throws AddDeniedException, UpdateDeniedException,
+ AuthenticationRequiredException {
+ return add(asLiteral(o, l));
}
- protected void checkAdd( final int pos, final Literal literal )
- {
+ protected void checkAdd(final int pos, final Literal literal)
+ throws AddDeniedException, UpdateDeniedException,
+ AuthenticationRequiredException {
checkAdd(pos, literal.asNode());
}
- protected void checkAdd( final int pos, final Node node )
- {
+ protected void checkAdd(final int pos, final Node node)
+ throws AddDeniedException, UpdateDeniedException,
+ AuthenticationRequiredException {
checkCreate(new Triple(holder.getBaseItem().asNode(), RDF.li(pos)
.asNode(), node));
}
@Override
- public boolean contains( final boolean o )
- {
- return contains( asObject( o ) );
+ public boolean contains(final boolean o) throws ReadDeniedException,
+ AuthenticationRequiredException {
+ return contains(asObject(o));
}
@Override
- public boolean contains( final char o )
- {
- return contains( asObject( o ) );
+ public boolean contains(final char o) throws ReadDeniedException,
+ AuthenticationRequiredException {
+ return contains(asObject(o));
}
@Override
- public boolean contains( final double o )
- {
- return contains( asObject( o ) );
+ public boolean contains(final double o) throws ReadDeniedException,
+ AuthenticationRequiredException {
+ return contains(asObject(o));
}
@Override
- public boolean contains( final float o )
- {
- return contains( asObject( o ) );
+ public boolean contains(final float o) throws ReadDeniedException,
+ AuthenticationRequiredException {
+ return contains(asObject(o));
}
@Override
- public boolean contains( final long o )
- {
- return contains( asObject( o ) );
+ public boolean contains(final long o) throws ReadDeniedException,
+ AuthenticationRequiredException {
+ return contains(asObject(o));
}
@Override
- public boolean contains( final Object o )
- {
- return contains( asObject( o ) );
+ public boolean contains(final Object o) throws ReadDeniedException,
+ AuthenticationRequiredException {
+ return contains(asObject(o));
}
@Override
- public boolean contains( final RDFNode o )
- {
+ public boolean contains(final RDFNode o) throws ReadDeniedException,
+ AuthenticationRequiredException {
// iterator check reads
final SecuredNodeIterator<RDFNode> iter = iterator();
- while (iter.hasNext())
- {
- if (iter.next().asNode().equals(o.asNode()))
- {
+ while (iter.hasNext()) {
+ if (iter.next().asNode().equals(o.asNode())) {
return true;
}
}
@@ -246,111 +243,94 @@ public class SecuredContainerImpl extends SecuredResourceImpl implements
}
@Override
- public boolean contains( final String o )
- {
- return contains( asLiteral( o, "" ));
+ public boolean contains(final String o) throws ReadDeniedException,
+ AuthenticationRequiredException {
+ return contains(asLiteral(o, ""));
}
@Override
- public boolean contains( final String o, final String l )
- {
- return contains( asLiteral( o, l ));
+ public boolean contains(final String o, final String l)
+ throws ReadDeniedException, AuthenticationRequiredException {
+ return contains(asLiteral(o, l));
}
- protected int getAddIndex()
- {
+ protected int getAddIndex() {
int pos = -1;
final ExtendedIterator<Statement> iter = holder.getBaseItem()
.listProperties();
- try
- {
- while (iter.hasNext())
- {
+ try {
+ while (iter.hasNext()) {
pos = Math.max(pos, getIndex(iter.next().getPredicate()));
}
- }
- finally
- {
+ } finally {
iter.close();
}
return pos + 1;
}
- protected static int getIndex( final Property p )
- {
+ protected static int getIndex(final Property p) {
if (p.getNameSpace().equals(RDF.getURI())
- && p.getLocalName().startsWith("_"))
- {
- try
- {
+ && p.getLocalName().startsWith("_")) {
+ try {
return Integer.parseInt(p.getLocalName().substring(1));
- }
- catch (final NumberFormatException e)
- {
+ } catch (final NumberFormatException e) {
// acceptable;
}
}
return -1;
}
- protected ExtendedIterator<Statement> getStatementIterator(
- final Action perm )
- {
+ protected ExtendedIterator<Statement> getStatementIterator(final Action perm) {
return holder.getBaseItem().listProperties()
.filterKeep(new ContainerFilter())
.filterKeep(new PermStatementFilter(perm, this));
}
protected ExtendedIterator<Statement> getStatementIterator(
- final Set<Action> perm )
- {
+ final Set<Action> perm) {
return holder.getBaseItem().listProperties()
.filterKeep(new ContainerFilter())
.filterKeep(new PermStatementFilter(perm, this));
}
@Override
- public boolean isAlt()
- {
+ public boolean isAlt() {
return holder.getBaseItem().isAlt();
}
@Override
- public boolean isBag()
- {
+ public boolean isBag() {
return holder.getBaseItem().isBag();
}
@Override
- public boolean isSeq()
- {
+ public boolean isSeq() {
return holder.getBaseItem().isSeq();
}
@Override
- public SecuredNodeIterator<RDFNode> iterator()
- {
+ public SecuredNodeIterator<RDFNode> iterator() {
// listProperties calls checkRead();
- SecuredStatementIterator iter = listProperties();
- try {
- SortedSet<Statement> result = new TreeSet<Statement>( new ContainerComparator() );
- while (iter.hasNext()) {
- Statement stmt = iter.next();
- if (stmt.getPredicate().getOrdinal() > 0)
- {
- result.add( stmt );
- }
- }
- return new SecuredNodeIterator<RDFNode>(getModel(), new StatementRemovingIterator(result.iterator()).mapWith( s -> s.getObject() ) );
- }
- finally {
- iter.close();
- }
+ SecuredStatementIterator iter = listProperties();
+ try {
+ SortedSet<Statement> result = new TreeSet<Statement>(
+ new ContainerComparator());
+ while (iter.hasNext()) {
+ Statement stmt = iter.next();
+ if (stmt.getPredicate().getOrdinal() > 0) {
+ result.add(stmt);
+ }
+ }
+ return new SecuredNodeIterator<RDFNode>(getModel(),
+ new StatementRemovingIterator(result.iterator())
+ .mapWith(s -> s.getObject()));
+ } finally {
+ iter.close();
+ }
}
@Override
- public SecuredNodeIterator<RDFNode> iterator( final Set<Action> perms )
- {
+ public SecuredNodeIterator<RDFNode> iterator(final Set<Action> perms) {
checkRead();
final Set<Action> permsCopy = new HashSet<Action>(perms);
permsCopy.add(Action.Read);
@@ -361,8 +341,9 @@ public class SecuredContainerImpl extends SecuredResourceImpl implements
}
@Override
- public SecuredContainer remove( final Statement s )
- {
+ public SecuredContainer remove(final Statement s)
+ throws UpdateDeniedException, DeleteDeniedException,
+ AuthenticationRequiredException {
checkUpdate();
checkDelete(s.asTriple());
holder.getBaseItem().remove(s);
@@ -370,188 +351,39 @@ public class SecuredContainerImpl extends SecuredResourceImpl implements
}
@Override
- public int size()
- {
+ public int size() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().size();
}
- /*
- * private synchronized void resetIndexes()
- * {
- * indexes.clear();
- * }
- */
- /*
- /**
- * find the position of i in the array
- *
- * @param i
- * @return the position or x<0 if not found.
- */
- /*
- * protected int mapValue( int i )
- * {
- * rebuildIndex();
- * return Collections.binarySearch( indexes, i );
- * }
- *
- * // return the value at position i
- * protected int unmapValue( int i )
- * {
- * return indexes.get(i);
- * }
- *
- *
- * private synchronized void rebuildIndex()
- * {
- * if (indexes.isEmpty())
- * {
- * ExtendedIterator<Statement> iter = getStatementIterator( Action.Read );
- * try {
- * while (iter.hasNext())
- * {
- * indexes.add( getIndex( iter.next().getPredicate() ) );
- * }
- * }
- * finally {
- * iter.close();
- * }
- * Collections.sort(indexes);
- * }
- * }
- *
- * private class ChangeListener implements ModelChangedListener
- * {
- *
- * private void checkStatement( Statement s )
- * {
- * if (indexes != null && s.getSubject().equals( holder.getBaseItem()))
- * {
- * resetIndexes();
- * }
- * }
- *
- * private void checkStatements( Iterator<Statement> iter )
- * {
- * while( indexes != null && iter.hasNext())
- * {
- * checkStatement( iter.next() );
- * }
- * }
- *
- * @Override
- * public void addedStatement( Statement s )
- * {
- * checkStatement( s );
- * }
- *
- * @Override
- * public void addedStatements( Statement[] statements )
- * {
- * checkStatements( Arrays.asList(statements).iterator() );
- * }
- *
- * @Override
- * public void addedStatements( List<Statement> statements )
- * {
- * checkStatements( statements.iterator() );
- * }
- *
- * @Override
- * public void addedStatements( StmtIterator statements )
- * {
- * try {
- * checkStatements( statements );
- * }
- * finally {
- * statements.close();
- * }
- * }
- *
- * @Override
- * public void addedStatements( Model baseModel )
- * {
- * addedStatements( baseModel.listStatements() );
- * }
- *
- * @Override
- * public void removedStatement( Statement s )
- * {
- * checkStatement( s );
- * }
- *
- * @Override
- * public void removedStatements( Statement[] statements )
- * {
- * checkStatements( Arrays.asList(statements).iterator() );
- * }
- *
- * @Override
- * public void removedStatements( List<Statement> statements )
- * {
- * checkStatements( statements.iterator() );
- * }
- *
- * @Override
- * public void removedStatements( StmtIterator statements )
- * {
- * try {
- * checkStatements( statements );
- * }
- * finally {
- * statements.close();
- * }
- * }
- *
- * @Override
- * public void removedStatements( Model baseModel )
- * {
- * removedStatements( baseModel.listStatements() );
- * }
- *
- * @Override
- * public void notifyEvent( Model baseModel, Object event )
- * {
- * // do nothing
- * }
- *
- * }
- */
- static class ContainerComparator implements Comparator<Statement>
- {
+ static class ContainerComparator implements Comparator<Statement> {
@Override
- public int compare( Statement arg0, Statement arg1 )
- {
- return Integer.valueOf(arg0.getPredicate().getOrdinal()).compareTo( arg1.getPredicate().getOrdinal());
+ public int compare(Statement arg0, Statement arg1) {
+ return Integer.valueOf(arg0.getPredicate().getOrdinal()).compareTo(
+ arg1.getPredicate().getOrdinal());
}
-
+
}
-
- static class StatementRemovingIterator extends WrappedIterator<Statement>
- {
+
+ static class StatementRemovingIterator extends WrappedIterator<Statement> {
private Statement stmt;
-
- public StatementRemovingIterator( Iterator<? extends Statement> base )
- {
+
+ public StatementRemovingIterator(Iterator<? extends Statement> base) {
super(base);
}
@Override
- public Statement next()
- {
+ public Statement next() {
stmt = super.next();
return stmt;
}
@Override
- public void remove()
- {
+ public void remove() {
stmt.remove();
super.remove();
}
-
-
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/2c0454c6/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredLiteralImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredLiteralImpl.java b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredLiteralImpl.java
index 3291bd1..21d9bb2 100644
--- a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredLiteralImpl.java
+++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredLiteralImpl.java
@@ -17,24 +17,25 @@
*/
package org.apache.jena.permissions.model.impl;
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.permissions.impl.ItemHolder ;
-import org.apache.jena.permissions.impl.SecuredItemInvoker ;
-import org.apache.jena.permissions.model.SecuredLiteral ;
-import org.apache.jena.permissions.model.SecuredModel ;
-import org.apache.jena.permissions.model.SecuredResource ;
-import org.apache.jena.rdf.model.Literal ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.RDFVisitor ;
-import org.apache.jena.rdf.model.ResourceRequiredException ;
+import org.apache.jena.datatypes.RDFDatatype;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.permissions.impl.ItemHolder;
+import org.apache.jena.permissions.impl.SecuredItemInvoker;
+import org.apache.jena.permissions.model.SecuredLiteral;
+import org.apache.jena.permissions.model.SecuredModel;
+import org.apache.jena.permissions.model.SecuredResource;
+import org.apache.jena.rdf.model.Literal;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.RDFVisitor;
+import org.apache.jena.rdf.model.ResourceRequiredException;
+import org.apache.jena.shared.AuthenticationRequiredException;
+import org.apache.jena.shared.ReadDeniedException;
/**
* Implementation of SecuredLiteral to be used by a SecuredItemInvoker proxy.
*/
public class SecuredLiteralImpl extends SecuredRDFNodeImpl implements
- SecuredLiteral
-{
+ SecuredLiteral {
/**
* Get an instance of SecuredLiteral
*
@@ -44,23 +45,19 @@ public class SecuredLiteralImpl extends SecuredRDFNodeImpl implements
* the literal to secure
* @return SecuredLiteral
*/
- public static SecuredLiteral getInstance( final SecuredModel securedModel,
- final Literal literal )
- {
- if (securedModel == null)
- {
+ public static SecuredLiteral getInstance(final SecuredModel securedModel,
+ final Literal literal) {
+ if (securedModel == null) {
throw new IllegalArgumentException(
"Secured securedModel may not be null");
}
- if (literal == null)
- {
+ if (literal == null) {
throw new IllegalArgumentException("literal may not be null");
}
// check that literal has a securedModel.
Literal goodLiteral = literal;
- if (goodLiteral.getModel() == null)
- {
+ if (goodLiteral.getModel() == null) {
goodLiteral = securedModel.createTypedLiteral(
literal.getLexicalForm(), literal.getDatatype());
}
@@ -71,10 +68,8 @@ public class SecuredLiteralImpl extends SecuredRDFNodeImpl implements
holder);
// if we are going to create a duplicate proxy, just return this
// one.
- if (goodLiteral instanceof SecuredLiteral)
- {
- if (checker.isEquivalent((SecuredLiteral) goodLiteral))
- {
+ if (goodLiteral instanceof SecuredLiteral) {
+ if (checker.isEquivalent((SecuredLiteral) goodLiteral)) {
return (SecuredLiteral) goodLiteral;
}
}
@@ -96,60 +91,55 @@ public class SecuredLiteralImpl extends SecuredRDFNodeImpl implements
* The item holder that will contain this SecuredLiteral.
*/
- private SecuredLiteralImpl( final SecuredModel securedModel,
- final ItemHolder<? extends Literal, ? extends SecuredLiteral> holder )
- {
+ private SecuredLiteralImpl(final SecuredModel securedModel,
+ final ItemHolder<? extends Literal, ? extends SecuredLiteral> holder) {
super(securedModel, holder);
this.holder = holder;
}
@Override
- public SecuredLiteral asLiteral()
- {
+ public SecuredLiteral asLiteral() {
return holder.getSecuredItem();
}
@Override
- public SecuredResource asResource()
- {
- if (canRead())
- {
+ public SecuredResource asResource() {
+ if (canRead()) {
throw new ResourceRequiredException(asNode());
- }
- else
- {
- throw new ResourceRequiredException(NodeFactory.createLiteral("Can not read"));
+ } else {
+ throw new ResourceRequiredException(
+ NodeFactory.createLiteral("Can not read"));
}
}
@Override
- public boolean getBoolean()
- {
+ public boolean getBoolean() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getBoolean();
}
@Override
- public byte getByte()
- {
+ public byte getByte() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getByte();
}
@Override
- public char getChar()
- {
+ public char getChar() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getChar();
}
/**
- * Return the datatype of the literal. This will be null in the
- * case of plain literals.
+ * Return the datatype of the literal. This will be null in the case of
+ * plain literals.
*/
@Override
- public RDFDatatype getDatatype()
- {
+ public RDFDatatype getDatatype() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getDatatype();
}
@@ -159,36 +149,36 @@ public class SecuredLiteralImpl extends SecuredRDFNodeImpl implements
* case of plain literals.
*/
@Override
- public String getDatatypeURI()
- {
+ public String getDatatypeURI() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getDatatypeURI();
}
@Override
- public double getDouble()
- {
+ public double getDouble() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getDouble();
}
@Override
- public float getFloat()
- {
+ public float getFloat() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getFloat();
}
@Override
- public int getInt()
- {
+ public int getInt() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getInt();
}
@Override
- public String getLanguage()
- {
+ public String getLanguage() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getLanguage();
}
@@ -197,80 +187,78 @@ public class SecuredLiteralImpl extends SecuredRDFNodeImpl implements
* Return the lexical form of the literal.
*/
@Override
- public String getLexicalForm()
- {
+ public String getLexicalForm() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getLexicalForm();
}
@Override
- public long getLong()
- {
+ public long getLong() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getLong();
}
@Override
- public short getShort()
- {
+ public short getShort() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getShort();
}
@Override
- public String getString()
- {
+ public String getString() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getString();
}
/**
- * Return the value of the literal. In the case of plain literals
- * this will return the literal string. In the case of typed literals
- * it will return a java object representing the value. In the case
- * of typed literals representing a java primitive then the appropriate
- * java wrapper class (Integer etc) will be returned.
+ * Return the value of the literal. In the case of plain literals this will
+ * return the literal string. In the case of typed literals it will return a
+ * java object representing the value. In the case of typed literals
+ * representing a java primitive then the appropriate java wrapper class
+ * (Integer etc) will be returned.
*/
@Override
- public Object getValue()
- {
+ public Object getValue() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().getValue();
}
@Override
- public Literal inModel( final Model m )
- {
+ public Literal inModel(final Model m) throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return m.createTypedLiteral(holder.getBaseItem().getLexicalForm(),
holder.getBaseItem().getDatatype());
}
@Override
- public boolean isWellFormedXML()
- {
+ public boolean isWellFormedXML() throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().isWellFormedXML();
}
/**
- * Test that two literals are semantically equivalent.
- * In some cases this may be the sames as equals, in others
- * equals is stricter. For example, two xsd:int literals with
- * the same value but different language tag are semantically
- * equivalent but distinguished by the java equality function
+ * Test that two literals are semantically equivalent. In some cases this
+ * may be the sames as equals, in others equals is stricter. For example,
+ * two xsd:int literals with the same value but different language tag are
+ * semantically equivalent but distinguished by the java equality function
* in order to support round tripping.
*/
@Override
- public boolean sameValueAs( final Literal other )
- {
+ public boolean sameValueAs(final Literal other) throws ReadDeniedException,
+ AuthenticationRequiredException {
checkRead();
return holder.getBaseItem().sameValueAs(other);
}
@Override
- public Object visitWith( final RDFVisitor rv )
- {
+ public Object visitWith(final RDFVisitor rv) {
return rv.visitLiteral(this);
}
}