jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cla...@apache.org
Subject [19/24] jena git commit: modifications to rename jena security as jena permissions modifications to adapt to removed deprecated classes in org.apache.jena.
Date Sat, 25 Apr 2015 08:51:22 GMT
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/main/java/org/apache/jena/permissions/model/SecuredUnsupportedPolymorphismException.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/SecuredUnsupportedPolymorphismException.java
b/jena-permissions/src/main/java/org/apache/jena/permissions/model/SecuredUnsupportedPolymorphismException.java
new file mode 100644
index 0000000..32a81be
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/SecuredUnsupportedPolymorphismException.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.permissions.model;
+
+import org.apache.jena.enhanced.UnsupportedPolymorphismException ;
+import org.apache.jena.permissions.model.impl.SecuredRDFNodeImpl;
+
+/**
+ * An extension to the UnsupportedPolymorphismException to handle
+ * secured polymorphic changes.
+ */
+public class SecuredUnsupportedPolymorphismException extends
+		UnsupportedPolymorphismException
+{
+	
+	public SecuredUnsupportedPolymorphismException(
+			final SecuredRDFNodeImpl node, final Class<?> type )
+	{
+		super( node, node.getModel() != null, type);
+	}
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/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
new file mode 100644
index 0000000..598c070
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredAltImpl.java
@@ -0,0 +1,339 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.permissions.model.impl;
+
+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;
+import org.apache.jena.permissions.model.SecuredAlt;
+import org.apache.jena.permissions.model.SecuredBag;
+import org.apache.jena.permissions.model.SecuredLiteral;
+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 ;
+
+/**
+ * Implementation of SecuredAlt to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredAltImpl extends SecuredContainerImpl implements SecuredAlt
+{
+	/**
+	 * Get an instance of SecuredAlt.
+	 * 
+	 * @param securedModel
+	 *            the Secured Model to use.
+	 * @param alt
+	 *            The Alt to be secured.
+	 * @return The secured Alt instance.
+	 */
+	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)
+		{
+			throw new IllegalArgumentException("Alt may not be null");
+		}
+		final ItemHolder<Alt, SecuredAlt> holder = new ItemHolder<Alt, SecuredAlt>(
+				alt);
+		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))
+			{
+				return (SecuredAlt) alt;
+			}
+		}
+		return holder.setSecuredItem(new SecuredItemInvoker(alt.getClass(),
+				checker));
+	}
+
+	// The item holder holding this SecuredAlt
+	private final ItemHolder<? extends Alt, ? extends SecuredAlt> holder;
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param securedModel
+	 *            the securedModel to use.
+	 * @param holder
+	 *            The item holder that will hold this SecuredAlt.
+	 */
+	protected SecuredAltImpl( final SecuredModel securedModel,
+			final ItemHolder<? extends Alt, ? extends SecuredAlt> holder )
+	{
+		super(securedModel, holder);
+		this.holder = holder;
+	}
+
+	@Override
+	public SecuredRDFNode getDefault()
+	{
+		// getDefaultStatement() calls checkRead
+		return SecuredRDFNodeImpl.getInstance(getModel(), getDefaultStatement()
+				.getObject());
+	}
+
+	@Override
+	public SecuredAlt getDefaultAlt()
+	{
+		// getDefaultStatement() calls checkRead
+		return SecuredAltImpl.getInstance(getModel(), getDefaultStatement()
+				.getAlt());
+	}
+
+	@Override
+	public SecuredBag getDefaultBag()
+	{
+		// getDefaultStatement() calls checkRead
+		return SecuredBagImpl.getInstance(getModel(), getDefaultStatement()
+				.getBag());
+	}
+
+	@Override
+	public boolean getDefaultBoolean()
+	{
+		// getDefaultStatement() calls checkRead
+		return getDefaultStatement().getBoolean();
+	}
+
+	@Override
+	public byte getDefaultByte()
+	{
+		// getDefaultStatement() calls checkRead
+		return getDefaultStatement().getByte();
+	}
+
+	@Override
+	public char getDefaultChar()
+	{
+		// getDefaultStatement() calls checkRead
+		return getDefaultStatement().getChar();
+	}
+
+	@Override
+	public double getDefaultDouble()
+	{
+		// getDefaultStatement() calls checkRead
+		return getDefaultStatement().getDouble();
+	}
+
+	@Override
+	public float getDefaultFloat()
+	{
+		// getDefaultStatement() calls checkRead
+		return getDefaultStatement().getFloat();
+	}
+
+	@Override
+	public int getDefaultInt()
+	{
+		// getDefaultStatement() calls checkRead
+		return getDefaultStatement().getInt();
+	}
+
+	@Override
+	public String getDefaultLanguage()
+	{
+		// getDefaultStatement() calls checkRead
+		return getDefaultStatement().getLanguage();
+	}
+
+	@Override
+	public SecuredLiteral getDefaultLiteral()
+	{
+		// getDefaultStatement() calls checkRead
+		return SecuredLiteralImpl.getInstance(getModel(), getDefaultStatement()
+				.getLiteral());
+	}
+
+	@Override
+	public long getDefaultLong()
+	{
+		// getDefaultStatement() calls checkRead
+		return getDefaultStatement().getLong();
+	}
+
+	@Override
+	public SecuredResource getDefaultResource()
+	{
+		// getDefaultStatement() calls checkRead
+		return SecuredResourceImpl.getInstance(getModel(),
+				getDefaultStatement().getResource());
+	}
+
+	@Override
+	@Deprecated
+	public SecuredResource getDefaultResource( final ResourceF f )
+	{
+		// getDefaultStatement() calls checkRead
+		return SecuredResourceImpl.getInstance(getModel(),
+				getDefaultStatement().getResource(f));
+	}
+
+	@Override
+	public SecuredSeq getDefaultSeq()
+	{
+		// getDefaultStatement() calls checkRead
+		return SecuredSeqImpl.getInstance(getModel(), getDefaultStatement()
+				.getSeq());
+	}
+
+	@Override
+	public short getDefaultShort()
+	{
+		// getDefaultStatement() calls checkRead
+		return getDefaultStatement().getShort();
+
+	}
+
+	private Statement getDefaultStatement()
+	{
+		checkRead();
+		final ExtendedIterator<Statement> iter = getStatementIterator(Action.Read);
+		try
+		{
+			if (iter.hasNext())
+			{
+				return iter.next();
+			}
+			throw new AltHasNoDefaultException(this);
+		}
+		finally
+		{
+			iter.close();
+		}
+	}
+
+	@Override
+	public String getDefaultString()
+	{
+		// 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 ));
+	}
+
+	@Override
+	public SecuredAlt setDefault( final char o )
+	{
+		return setDefault( asObject( o ));
+	}
+
+	@Override
+	public SecuredAlt setDefault( final double o )
+	{
+		return setDefault( asObject( o ));
+	}
+
+	@Override
+	public SecuredAlt setDefault( final float o )
+	{
+		return setDefault( asObject( o ));
+	}
+
+	@Override
+	public SecuredAlt setDefault( final long o )
+	{
+		return setDefault( asObject( o ));
+	}
+
+	@Override
+	public SecuredAlt setDefault( final Object o )
+	{
+		return setDefault( asObject( o ));
+	}
+
+	@Override
+	public SecuredAlt setDefault( final RDFNode o )
+	{
+		checkUpdate();			
+		final ExtendedIterator<Statement> iter = getStatementIterator(Action.Read);
+		try {
+			if (iter.hasNext())
+			{
+				final Statement stmt = iter.next();
+				final Triple t = stmt.asTriple();
+				final Triple t2 = new Triple(t.getSubject(), t.getPredicate(),
+						o.asNode());
+				checkUpdate(t, t2);
+				stmt.changeObject(o);
+				return holder.getSecuredItem();
+			}
+			else
+			{
+				add( o );
+				return holder.getSecuredItem();
+			}
+		}
+		finally {
+			iter.close();
+		}
+		
+	}
+
+	@Override
+	public SecuredAlt setDefault( final String o )
+	{
+		return setDefault( asLiteral( o, "" ));
+	}
+
+	@Override
+	public SecuredAlt setDefault( final String o, final String l )
+	{
+		return setDefault( asLiteral( o, l) );
+	}
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredBagImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredBagImpl.java
b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredBagImpl.java
new file mode 100644
index 0000000..785ba5d
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredBagImpl.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.permissions.model.impl;
+
+import org.apache.jena.permissions.impl.ItemHolder;
+import org.apache.jena.permissions.impl.SecuredItemInvoker;
+import org.apache.jena.permissions.model.SecuredBag;
+import org.apache.jena.permissions.model.SecuredModel;
+import org.apache.jena.rdf.model.Bag ;
+
+/**
+ * Implementation of SecuredBag to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredBagImpl extends SecuredContainerImpl implements SecuredBag
+{
+	/**
+	 * Get an instance of SecuredBag
+	 * 
+	 * @param securedModel
+	 *            The Secured Model to use.
+	 * @param bag
+	 *            The bag to secure
+	 * @return The SecuredBag
+	 */
+	public static SecuredBag getInstance( final SecuredModel securedModel,
+			final Bag bag )
+	{
+		if (securedModel == null)
+		{
+			throw new IllegalArgumentException(
+					"Secured securedModel may not be null");
+		}
+		if (bag == null)
+		{
+			throw new IllegalArgumentException("Bag may not be null");
+		}
+		final ItemHolder<Bag, SecuredBag> holder = new ItemHolder<Bag, SecuredBag>(
+				bag);
+		final SecuredBagImpl checker = new SecuredBagImpl(securedModel, holder);
+		// if we are going to create a duplicate proxy, just return this
+		// one.
+		if (bag instanceof SecuredBag)
+		{
+			if (checker.isEquivalent((SecuredBag) bag))
+			{
+				return (SecuredBag) bag;
+			}
+		}
+		return holder.setSecuredItem(new SecuredItemInvoker(bag.getClass(),
+				checker));
+	}
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param securedModel
+	 *            The Secured Model to use.
+	 * @param holder
+	 *            The holder that will contain this SecuredBag.
+	 */
+	protected SecuredBagImpl( final SecuredModel securedModel,
+			final ItemHolder<? extends Bag, ? extends SecuredBag> holder )
+	{
+		super(securedModel, holder);
+	}
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/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
new file mode 100644
index 0000000..0339c8b
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredContainerImpl.java
@@ -0,0 +1,576 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.permissions.model.impl;
+
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+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.permissions.SecurityEvaluator.Action;
+import org.apache.jena.permissions.impl.ItemHolder;
+import org.apache.jena.permissions.impl.SecuredItemInvoker;
+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.Map1 ;
+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
+{
+	/**
+	 * Constructor
+	 * 
+	 * @param securedModel
+	 *            the Secured Model to use.
+	 * @param container
+	 *            The container to secure.
+	 * @return The SecuredResource
+	 */
+	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)
+		{
+			throw new IllegalArgumentException("Container may not be null");
+		}
+
+		// check that resource has a securedModel.
+		Container goodContainer = container;
+		if (goodContainer.getModel() == null)
+		{
+			container.asNode();
+			goodContainer = securedModel.createBag();
+		}
+
+		final ItemHolder<Container, SecuredContainer> holder = new ItemHolder<Container,
SecuredContainer>(
+				goodContainer);
+
+		final SecuredContainerImpl checker = new SecuredContainerImpl(
+				securedModel, holder);
+		// if we are going to create a duplicate proxy, just return this
+		// one.
+		if (goodContainer instanceof SecuredContainer)
+		{
+			if (checker.isEquivalent((SecuredContainer) goodContainer))
+			{
+				return (SecuredContainer) goodContainer;
+			}
+		}
+
+		return holder.setSecuredItem(new SecuredItemInvoker(container
+				.getClass(), checker));
+
+	}
+
+	// the item holder that contains this SecuredContainer.
+	private final ItemHolder<? extends Container, ? extends SecuredContainer> holder;
+
+	/**
+	 * Constructor
+	 * 
+	 * @param securedModel
+	 *            the Secured Model to use.
+	 * @param holder
+	 *            The item holder that will contain this SecuredContainer
+	 */
+	protected SecuredContainerImpl(
+			final SecuredModel securedModel,
+			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 )
+	{
+		return holder.getBaseItem().getModel().createLiteral(o, l);
+	}
+	
+	@Override
+	public SecuredContainer add( final boolean o )
+	{
+		return add( asObject( o ));
+	}
+
+	@Override
+	public SecuredContainer add( final char o )
+	{
+		return add( asObject( o ));
+	}
+
+	@Override
+	public SecuredContainer add( final double o )
+	{
+		return add( asObject( o ));
+	}
+
+	@Override
+	public SecuredContainer add( final float o )
+	{
+		return add( asObject( o ));
+	}
+
+	@Override
+	public SecuredContainer add( final long o )
+	{
+		return add( asObject( o ));
+	}
+
+	@Override
+	public SecuredContainer add( final Object o )
+	{
+		return add( asObject( o ));
+	}
+
+	@Override
+	public SecuredContainer add( final RDFNode o )
+	{
+		checkUpdate();
+		final int pos = holder.getBaseItem().size();
+		checkAdd(pos, o.asNode());
+		holder.getBaseItem().add(o);
+		return holder.getSecuredItem();
+	}
+
+	@Override
+	public SecuredContainer add( final String o )
+	{
+		return add( asLiteral( o, "" ));
+	}
+
+	@Override
+	public SecuredContainer add( final String o, final String l )
+	{
+		return add( asLiteral( o, l));
+	}
+
+	protected void checkAdd( final int pos, final Literal literal )
+	{
+		checkAdd(pos, literal.asNode());
+	}
+
+	protected void checkAdd( final int pos, final Node node )
+	{
+		checkCreate(new Triple(holder.getBaseItem().asNode(), RDF.li(pos)
+				.asNode(), node));
+	}
+
+	@Override
+	public boolean contains( final boolean o )
+	{
+		return contains( asObject( o ) );
+	}
+
+	@Override
+	public boolean contains( final char o )
+	{
+		return contains( asObject( o ) );
+	}
+
+	@Override
+	public boolean contains( final double o )
+	{
+		return contains( asObject( o ) );
+	}
+
+	@Override
+	public boolean contains( final float o )
+	{
+		return contains( asObject( o ) );
+	}
+
+	@Override
+	public boolean contains( final long o )
+	{
+		return contains( asObject( o ) );
+	}
+
+	@Override
+	public boolean contains( final Object o )
+	{
+		return contains( asObject( o ) );
+	}
+
+	@Override
+	public boolean contains( final RDFNode o )
+	{
+		// iterator check reads
+		final SecuredNodeIterator<RDFNode> iter = iterator();
+		while (iter.hasNext())
+		{
+			if (iter.next().asNode().equals(o.asNode()))
+			{
+				return true;
+			}
+		}
+		return false;
+	}
+
+	@Override
+	public boolean contains( final String o )
+	{
+		return contains( asLiteral( o, "" ));
+	}
+
+	@Override
+	public boolean contains( final String o, final String l )
+	{
+		return contains( asLiteral( o, l ));
+	}
+
+	protected int getAddIndex()
+	{
+		int pos = -1;
+		final ExtendedIterator<Statement> iter = holder.getBaseItem()
+				.listProperties();
+		try
+		{
+			while (iter.hasNext())
+			{
+				pos = Math.max(pos, getIndex(iter.next().getPredicate()));
+			}
+		}
+		finally
+		{
+			iter.close();
+		}
+		return pos + 1;
+	}
+
+	protected static int getIndex( final Property p )
+	{
+		if (p.getNameSpace().equals(RDF.getURI())
+				&& p.getLocalName().startsWith("_"))
+		{
+			try
+			{
+				return Integer.parseInt(p.getLocalName().substring(1));
+			}
+			catch (final NumberFormatException e)
+			{
+				// acceptable;
+			}
+		}
+		return -1;
+	}
+
+	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 )
+	{
+		return holder.getBaseItem().listProperties()
+				.filterKeep(new ContainerFilter())
+				.filterKeep(new PermStatementFilter(perm, this));
+	}
+
+	@Override
+	public boolean isAlt()
+	{
+		return holder.getBaseItem().isAlt();
+	}
+
+	@Override
+	public boolean isBag()
+	{
+		return holder.getBaseItem().isBag();
+	}
+
+	@Override
+	public boolean isSeq()
+	{
+		return holder.getBaseItem().isSeq();
+	}
+
+	@Override
+	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(
new NodeMap() ) );
+        }
+        finally {
+        	iter.close();
+        }
+	}
+
+	@Override
+	public SecuredNodeIterator<RDFNode> iterator( final Set<Action> perms )
+	{
+		checkRead();
+		final Set<Action> permsCopy = new HashSet<Action>(perms);
+		permsCopy.add(Action.Read);
+		final ExtendedIterator<RDFNode> ni = getStatementIterator(perms)
+				.mapWith(new Map1<Statement, RDFNode>() {
+
+					@Override
+					public RDFNode map1( final Statement o )
+					{
+						return o.getObject();
+					}
+				});
+		return new SecuredNodeIterator<RDFNode>(getModel(), ni);
+
+	}
+
+	@Override
+	public SecuredContainer remove( final Statement s )
+	{
+		checkUpdate();
+		checkDelete(s.asTriple());
+		holder.getBaseItem().remove(s);
+		return holder.getSecuredItem();
+	}
+
+	@Override
+	public int size()
+	{
+		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 NodeMap implements Map1<Statement,RDFNode>
+	{
+
+		@Override
+		public RDFNode map1( Statement o )
+		{
+			return o.getObject();
+		}
+		
+	}
+	
+	static class ContainerComparator implements Comparator<Statement>
+	{
+
+		@Override
+		public int compare( Statement arg0, Statement arg1 )
+		{
+			return Integer.valueOf(arg0.getPredicate().getOrdinal()).compareTo( arg1.getPredicate().getOrdinal());
+		}
+		
+	}
+	
+	static class StatementRemovingIterator extends WrappedIterator<Statement>
+	{
+		private Statement stmt;
+		
+		public StatementRemovingIterator( Iterator<? extends Statement> base )
+		{
+			super(base);
+		}
+
+		@Override
+		public Statement next()
+		{
+			stmt = super.next();
+			return stmt;
+		}
+
+		@Override
+		public void remove()
+		{
+			stmt.remove();
+			super.remove();
+		}
+		
+		
+	}
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/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
new file mode 100644
index 0000000..c457328
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredLiteralImpl.java
@@ -0,0 +1,277 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.permissions.model.impl;
+
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.graph.Node ;
+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 ;
+
+/**
+ * Implementation of SecuredLiteral to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredLiteralImpl extends SecuredRDFNodeImpl implements
+		SecuredLiteral
+{
+	/**
+	 * Get an instance of SecuredLiteral
+	 * 
+	 * @param securedModel
+	 *            the item providing the security context.
+	 * @param literal
+	 *            the literal to secure
+	 * @return SecuredLiteral
+	 */
+	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)
+		{
+			throw new IllegalArgumentException("literal may not be null");
+		}
+
+		// check that literal has a securedModel.
+		Literal goodLiteral = literal;
+		if (goodLiteral.getModel() == null)
+		{
+			goodLiteral = securedModel.createTypedLiteral(
+					literal.getLexicalForm(), literal.getDatatype());
+		}
+
+		final ItemHolder<Literal, SecuredLiteral> holder = new ItemHolder<Literal, SecuredLiteral>(
+				goodLiteral);
+		final SecuredLiteralImpl checker = new SecuredLiteralImpl(securedModel,
+				holder);
+		// if we are going to create a duplicate proxy, just return this
+		// one.
+		if (goodLiteral instanceof SecuredLiteral)
+		{
+			if (checker.isEquivalent((SecuredLiteral) goodLiteral))
+			{
+				return (SecuredLiteral) goodLiteral;
+			}
+		}
+		return holder.setSecuredItem(new SecuredItemInvoker(literal.getClass(),
+				checker));
+	}
+
+	// the item holder that contains this SecuredLiteral
+	private final ItemHolder<? extends Literal, ? extends SecuredLiteral> holder;
+
+	/**
+	 * Constructor
+	 * 
+	 * @param securityEvaluator
+	 *            The security evaluator to use.
+	 * @param graphIRI
+	 *            the graph IRI to validate against.
+	 * @param holder
+	 *            The item holder that will contain this SecuredLiteral.
+	 */
+
+	private SecuredLiteralImpl( final SecuredModel securedModel,
+			final ItemHolder<? extends Literal, ? extends SecuredLiteral> holder )
+	{
+		super(securedModel, holder);
+		this.holder = holder;
+	}
+
+	@Override
+	public SecuredLiteral asLiteral()
+	{
+		return holder.getSecuredItem();
+	}
+
+	@Override
+	public SecuredResource asResource()
+	{
+		if (canRead())
+		{
+			throw new ResourceRequiredException(asNode());
+		}
+		else
+		{
+			throw new ResourceRequiredException(
+					Node.createLiteral("Can not read"));
+		}
+	}
+
+	@Override
+	public boolean getBoolean()
+	{
+		checkRead();
+		return holder.getBaseItem().getBoolean();
+	}
+
+	@Override
+	public byte getByte()
+	{
+		checkRead();
+		return holder.getBaseItem().getByte();
+	}
+
+	@Override
+	public char getChar()
+	{
+		checkRead();
+		return holder.getBaseItem().getChar();
+	}
+
+	/**
+	 * Return the datatype of the literal. This will be null in the
+	 * case of plain literals.
+	 */
+	@Override
+	public RDFDatatype getDatatype()
+	{
+		checkRead();
+		return holder.getBaseItem().getDatatype();
+	}
+
+	/**
+	 * Return the uri of the datatype of the literal. This will be null in the
+	 * case of plain literals.
+	 */
+	@Override
+	public String getDatatypeURI()
+	{
+		checkRead();
+		return holder.getBaseItem().getDatatypeURI();
+	}
+
+	@Override
+	public double getDouble()
+	{
+		checkRead();
+		return holder.getBaseItem().getDouble();
+	}
+
+	@Override
+	public float getFloat()
+	{
+		checkRead();
+		return holder.getBaseItem().getFloat();
+	}
+
+	@Override
+	public int getInt()
+	{
+		checkRead();
+		return holder.getBaseItem().getInt();
+	}
+
+	@Override
+	public String getLanguage()
+	{
+		checkRead();
+		return holder.getBaseItem().getLanguage();
+	}
+
+	/**
+	 * Return the lexical form of the literal.
+	 */
+	@Override
+	public String getLexicalForm()
+	{
+		checkRead();
+		return holder.getBaseItem().getLexicalForm();
+	}
+
+	@Override
+	public long getLong()
+	{
+		checkRead();
+		return holder.getBaseItem().getLong();
+	}
+
+	@Override
+	public short getShort()
+	{
+		checkRead();
+		return holder.getBaseItem().getShort();
+	}
+
+	@Override
+	public String getString()
+	{
+		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.
+	 */
+	@Override
+	public Object getValue()
+	{
+		checkRead();
+		return holder.getBaseItem().getValue();
+	}
+
+	@Override
+	public Literal inModel( final Model m )
+	{
+		checkRead();
+		return m.createTypedLiteral(holder.getBaseItem().getLexicalForm(),
+				holder.getBaseItem().getDatatype());
+	}
+
+	@Override
+	public boolean isWellFormedXML()
+	{
+		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
+	 * in order to support round tripping.
+	 */
+	@Override
+	public boolean sameValueAs( final Literal other )
+	{
+		checkRead();
+		return holder.getBaseItem().sameValueAs(other);
+	}
+
+	@Override
+	public Object visitWith( final RDFVisitor rv )
+	{
+		return rv.visitLiteral(this);
+	}
+}


Mime
View raw message