jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1451345 - in /jena/trunk/jena-arq/src: main/java/org/apache/jena/riot/system/ test/java/org/apache/jena/riot/system/
Date Thu, 28 Feb 2013 21:06:01 GMT
Author: andy
Date: Thu Feb 28 21:06:01 2013
New Revision: 1451345

URL: http://svn.apache.org/r1451345
Log:
Complete the set.

Added:
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapNull.java
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapUnmodifiable.java
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapWrapper.java
    jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestPrefixMapOther.java
    jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestPrefixMapWrapper.java
Modified:
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMap.java
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapFactory.java
    jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TS_RiotSystem.java

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMap.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMap.java?rev=1451345&r1=1451344&r2=1451345&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMap.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMap.java Thu Feb 28
21:06:01 2013
@@ -142,7 +142,7 @@ public interface PrefixMap {
     public abstract String abbreviate(String uriStr);
 
     /**
-     * Abbreviate an IRI or return a pair of prefix and local parts.
+     * Abbreviate an IRI and return a pair of prefix and local parts, or null.
      * 
      * @param uriStr
      *            URI string to abbreviate

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapFactory.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapFactory.java?rev=1451345&r1=1451344&r2=1451345&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapFactory.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapFactory.java Thu
Feb 28 21:06:01 2013
@@ -227,4 +227,24 @@ public class PrefixMapFactory {
     public static PrefixMap extend(PrefixMap pmap) {
         return new PrefixMapExtended(pmap);
     }
+    
+    /** Return an immutable view of the prefix map.
+     * Throws {@linkplain UnsupportedOperationException} on 
+     * attempts to update it.  Refelcts hcnages mad to the underlying map.
+     * @param pmap  PrefixMap
+     * @return Prefix Map
+     */
+    public static PrefixMap unmodifiablePrefixMap(PrefixMap pmap)
+    {
+        return new PrefixMapUnmodifiable(pmap) ;
+    }
+    
+    /** Return an always-empty and immutable prefix map 
+     * @return Prefix Map
+     */ 
+    public static PrefixMap emptyPrefixMap()
+    {
+        return PrefixMapNull.empty ;
+    }
+    
 }

Added: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapNull.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapNull.java?rev=1451345&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapNull.java (added)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapNull.java Thu Feb
28 21:06:01 2013
@@ -0,0 +1,132 @@
+/**
+ * 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.riot.system;
+
+import java.util.Collections ;
+import java.util.Map ;
+
+import org.apache.jena.atlas.lib.Pair ;
+import org.apache.jena.iri.IRI ;
+
+import com.hp.hpl.jena.shared.PrefixMapping ;
+
+/** Always empty prefix map */
+public class PrefixMapNull implements PrefixMap
+{
+    public static PrefixMap empty = new PrefixMapNull() ;
+
+    private PrefixMapNull()
+    {}
+
+    @Override
+    public Map<String, IRI> getMapping()
+    {
+        return Collections.emptyMap() ;
+    }
+
+    @Override
+    public Map<String, IRI> getMappingCopy()
+    {
+        return Collections.emptyMap() ;
+    }
+
+    @Override
+    public Map<String, String> getMappingCopyStr()
+    {
+        return Collections.emptyMap() ;
+    }
+
+    @Override
+    public void add(String prefix, String iriString)
+    {
+        throw new UnsupportedOperationException("Unmodifiable PrefixMap") ;
+    }
+
+    @Override
+    public void add(String prefix, IRI iri)
+    {
+        throw new UnsupportedOperationException("Unmodifiable PrefixMap") ;
+    }
+
+    @Override
+    public void putAll(PrefixMap pmap)
+    {
+        throw new UnsupportedOperationException("Unmodifiable PrefixMap") ;
+    }
+
+    @Override
+    public void putAll(PrefixMapping pmap)
+    {
+        throw new UnsupportedOperationException("Unmodifiable PrefixMap") ;
+    }
+
+    @Override
+    public void putAll(Map<String, String> mapping)
+    {
+        throw new UnsupportedOperationException("Unmodifiable PrefixMap") ;
+    }
+
+    @Override
+    public void delete(String prefix)
+    {
+        throw new UnsupportedOperationException("Unmodifiable PrefixMap") ;
+    }
+
+    @Override
+    public boolean contains(String prefix)
+    {
+        return false ;
+    }
+
+    @Override
+    public String abbreviate(String uriStr)
+    {
+        return null ;
+    }
+
+    @Override
+    public Pair<String, String> abbrev(String uriStr)
+    {
+        return null ;
+    }
+
+    @Override
+    public String expand(String prefixedName)
+    {
+        return null ;
+    }
+
+    @Override
+    public String expand(String prefix, String localName)
+    {
+        return null ;
+    }
+
+    @Override
+    public boolean isEmpty()
+    {
+        return true ;
+    }
+
+    @Override
+    public int size()
+    {
+        return 0 ;
+    }
+}

Added: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapUnmodifiable.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapUnmodifiable.java?rev=1451345&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapUnmodifiable.java
(added)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapUnmodifiable.java
Thu Feb 28 21:06:01 2013
@@ -0,0 +1,60 @@
+/**
+ * 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.riot.system;
+
+import java.util.Collections ;
+import java.util.Map ;
+
+import org.apache.jena.iri.IRI ;
+
+import com.hp.hpl.jena.shared.PrefixMapping ;
+
+/** A PrefixMap that traps update operations on a wrapped prefix map */ 
+public class PrefixMapUnmodifiable extends PrefixMapWrapper
+{
+    public PrefixMapUnmodifiable(PrefixMap other) { super(other) ; }
+
+    @Override
+    public Map<String, IRI> getMapping()
+    { return Collections.unmodifiableMap(other.getMapping()) ; }
+
+    @Override
+    public void add(String prefix, String iriString)
+    { throw new UnsupportedOperationException("Unmodifiable PrefixMap") ; }  
+
+    @Override
+    public void add(String prefix, IRI iri)
+    { throw new UnsupportedOperationException("Unmodifiable PrefixMap") ; }  
+
+    @Override
+    public void putAll(PrefixMap pmap)
+    { throw new UnsupportedOperationException("Unmodifiable PrefixMap") ; }  
+
+    @Override
+    public void putAll(PrefixMapping pmap)
+    { throw new UnsupportedOperationException("Unmodifiable PrefixMap") ; }  
+
+    @Override
+    public void putAll(Map<String, String> mapping)
+    { throw new UnsupportedOperationException("Unmodifiable PrefixMap") ; }  
+
+    @Override
+    public void delete(String prefix)
+    { throw new UnsupportedOperationException("Unmodifiable PrefixMap") ; }  
+}

Added: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapWrapper.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapWrapper.java?rev=1451345&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapWrapper.java (added)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapWrapper.java Thu
Feb 28 21:06:01 2013
@@ -0,0 +1,104 @@
+/**
+ * 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.riot.system;
+
+import java.util.Map ;
+
+import org.apache.jena.atlas.lib.Pair ;
+import org.apache.jena.iri.IRI ;
+
+import com.hp.hpl.jena.shared.PrefixMapping ;
+
+//private static PrefixMap empty = new PrefixMapNull() ; 
+    /**
+     * Creates an always-empty prefix map, which can not be changed.
+     */
+//    public static PrefixMap nullPrefixMap() {
+//    }
+    
+    public class PrefixMapWrapper implements PrefixMap
+    {
+        protected final PrefixMap other ;
+
+        public PrefixMapWrapper(PrefixMap other) { this.other = other ; }
+        
+        @Override
+        public Map<String, IRI> getMapping()
+        { return other.getMapping() ; }
+
+        @Override
+        public Map<String, IRI> getMappingCopy()
+        { return other.getMappingCopy() ; }
+
+        @Override
+        public Map<String, String> getMappingCopyStr()
+        { return other.getMappingCopyStr() ; } 
+
+        @Override
+        public void add(String prefix, String iriString)
+        { other.add(prefix, iriString) ; }
+
+        @Override
+        public void add(String prefix, IRI iri)
+        { other.add(prefix, iri) ; }
+
+        @Override
+        public void putAll(PrefixMap pmap)
+        { other.putAll(pmap) ; }
+
+        @Override
+        public void putAll(PrefixMapping pmap)
+        { other.putAll(pmap) ; }
+
+        @Override
+        public void putAll(Map<String, String> mapping)
+        { other.putAll(mapping) ; }
+
+        @Override
+        public void delete(String prefix)
+        { other.delete(prefix) ; }
+
+        @Override
+        public boolean contains(String prefix)
+        { return other.contains(prefix) ; }
+
+        @Override
+        public String abbreviate(String uriStr)
+        { return other.abbreviate(uriStr) ; }
+
+        @Override
+        public Pair<String, String> abbrev(String uriStr)
+        { return other.abbrev(uriStr) ; }
+
+        @Override
+        public String expand(String prefixedName)
+        { return other.expand(prefixedName) ; }
+
+        @Override
+        public String expand(String prefix, String localName)
+        { return other.expand(prefix, localName) ; }
+
+        @Override
+        public boolean isEmpty()
+        { return other.isEmpty() ; }
+
+        @Override
+        public int size()
+        { return other.size() ; }
+    }

Modified: jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TS_RiotSystem.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TS_RiotSystem.java?rev=1451345&r1=1451344&r2=1451345&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TS_RiotSystem.java (original)
+++ jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TS_RiotSystem.java Thu Feb
28 21:06:01 2013
@@ -32,6 +32,8 @@ import org.junit.runners.Suite.SuiteClas
     
     // Prefix Map implementations
     , TestPrefixMap.class
+    , TestPrefixMapWrapper.class
+    , TestPrefixMapOther.class
     , TestFastAbbreviatingPrefixMap.class
     , TestPrefixMapExtended1.class
     , TestPrefixMapExtended2.class

Added: jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestPrefixMapOther.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestPrefixMapOther.java?rev=1451345&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestPrefixMapOther.java
(added)
+++ jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestPrefixMapOther.java
Thu Feb 28 21:06:01 2013
@@ -0,0 +1,61 @@
+/*
+ * 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.riot.system;
+
+import org.apache.jena.atlas.junit.BaseTest ;
+import org.junit.Test ;
+
+/**
+ * Test the standard {@link PrefixMapStd} implementation
+ *
+ */
+public class TestPrefixMapOther extends BaseTest
+{
+    @Test(expected=UnsupportedOperationException.class) 
+    public void other_01()
+    {
+        PrefixMap pmap = PrefixMapFactory.create() ;
+        pmap = PrefixMapFactory.unmodifiablePrefixMap(pmap) ;
+        pmap.add("foo", "bar") ;
+    }
+    
+    @Test(expected=UnsupportedOperationException.class) 
+    public void other_02()
+    {
+        PrefixMap pmap = PrefixMapFactory.create() ;
+        pmap = PrefixMapFactory.unmodifiablePrefixMap(pmap) ;
+        pmap.getMapping().put("ex", IRIResolver.iriFactory.construct("http://example/"))
 ;
+    }
+    
+
+    @Test(expected=UnsupportedOperationException.class) 
+    public void other_10()
+    {
+        PrefixMap pmap = PrefixMapFactory.emptyPrefixMap() ;
+        pmap.add("foo", "bar") ;
+    }
+    
+    @Test(expected=UnsupportedOperationException.class) 
+    public void other_11()
+    {
+        PrefixMap pmap = PrefixMapFactory.emptyPrefixMap() ;
+        pmap.getMapping().put("ex", IRIResolver.iriFactory.construct("http://example/"))
 ;
+    }
+    
+}

Added: jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestPrefixMapWrapper.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestPrefixMapWrapper.java?rev=1451345&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestPrefixMapWrapper.java
(added)
+++ jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestPrefixMapWrapper.java
Thu Feb 28 21:06:01 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.riot.system;
+
+/**
+ * Test {@linkplain PrefixMapWrapper}
+ *
+ */
+public class TestPrefixMapWrapper extends AbstractTestPrefixMap {
+
+    @Override
+    protected PrefixMap getPrefixMap() {
+        return new PrefixMapWrapper(new PrefixMapStd());
+    }
+}



Mime
View raw message