You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2011/10/30 16:53:52 UTC

svn commit: r1195185 - in /incubator/jena/Jena2/jena/trunk/src: main/java/com/hp/hpl/jena/datatypes/ main/java/com/hp/hpl/jena/datatypes/xsd/ main/java/com/hp/hpl/jena/datatypes/xsd/impl/ test/java/com/hp/hpl/jena/graph/test/

Author: andy
Date: Sun Oct 30 15:53:52 2011
New Revision: 1195185

URL: http://svn.apache.org/viewvc?rev=1195185&view=rev
Log:
JENA-148

Added:
    incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/xsd/impl/XSDPlainType.java   (with props)
Modified:
    incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/BaseDatatype.java
    incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/xsd/XSDDatatype.java
    incubator/jena/Jena2/jena/trunk/src/test/java/com/hp/hpl/jena/graph/test/TestTypedLiterals.java

Modified: incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/BaseDatatype.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/BaseDatatype.java?rev=1195185&r1=1195184&r2=1195185&view=diff
==============================================================================
--- incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/BaseDatatype.java (original)
+++ incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/BaseDatatype.java Sun Oct 30 15:53:52 2011
@@ -136,11 +136,16 @@ public class BaseDatatype implements RDF
      * This default requires value and datatype equality.
      */
     @Override
-    public boolean isEqual(LiteralLabel value1, LiteralLabel value2) {
-        return value1.getDatatype() == value2.getDatatype()
-             && value1.getValue().equals(value2.getValue());
+    public boolean isEqual(LiteralLabel litLabel1, LiteralLabel litLabel2) {
+        return isEqualPlain(litLabel1, litLabel2) ;
     }
     
+    /** The default for equality - same datatype, same value */ 
+    protected static boolean isEqualPlain(LiteralLabel litLabel1, LiteralLabel litLabel2) {
+        return litLabel1.getDatatype() == litLabel2.getDatatype()
+        && litLabel1.getValue().equals(litLabel2.getValue());
+}
+    
     /**
          Default implementation of getHashCode() delegates to the default from
          the literal label.

Modified: incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/xsd/XSDDatatype.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/xsd/XSDDatatype.java?rev=1195185&r1=1195184&r2=1195185&view=diff
==============================================================================
--- incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/xsd/XSDDatatype.java (original)
+++ incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/xsd/XSDDatatype.java Sun Oct 30 15:53:52 2011
@@ -109,7 +109,10 @@ public class XSDDatatype extends BaseDat
     public static final XSDDatatype XSDnormalizedString = new XSDBaseStringType("normalizedString", String.class);
     
     /** Datatype representing xsd:anyURI */
-    public static final XSDDatatype XSDanyURI = new XSDDatatype("anyURI", URI.class);  
+    // If you see this, remove commented lines.
+    // Merely temporary during switch over and testing.   
+    //public static final XSDDatatype XSDanyURI = new XSDDatatype("anyURI", URI.class);  
+    public static final XSDDatatype XSDanyURI = new XSDPlainType("anyURI");
     
     /** Datatype representing xsd:token */
     public static final XSDDatatype XSDtoken = new XSDBaseStringType("token");
@@ -118,7 +121,10 @@ public class XSDDatatype extends BaseDat
     public static final XSDDatatype XSDName = new XSDBaseStringType("Name");
 
     /** Datatype representing xsd:QName */
-    public static final XSDDatatype XSDQName = new XSDDatatype("QName");
+    // If you see this, remove commented lines.
+    // Merely temporary during switch over and testing.   
+    // public static final XSDDatatype XSDQName = new XSDDatatype("QName");
+    public static final XSDDatatype XSDQName = new XSDPlainType("QName");
 
     /** Datatype representing xsd:language */
     public static final XSDDatatype XSDlanguage = new XSDBaseStringType("language");
@@ -136,10 +142,16 @@ public class XSDDatatype extends BaseDat
     public static final XSDDatatype XSDNCName = new XSDBaseStringType("NCName");
 
     /** Datatype representing xsd:IDREF */
-    public static final XSDDatatype XSDIDREF = new XSDDatatype("IDREF");
+    // If you see this, remove commented lines.
+    // Merely temporary during switch over and testing.   
+    //public static final XSDDatatype XSDIDREF = new XSDDatatype("IDREF");
+    public static final XSDDatatype XSDIDREF = new XSDPlainType("IDREF");
 
     /** Datatype representing xsd:NOTATION */
-    public static final XSDDatatype XSDNOTATION = new XSDDatatype("NOTATION");
+    // If you see this, remove commented lines.
+    // Merely temporary during switch over and testing.   
+    //public static final XSDDatatype XSDNOTATION = new XSDDatatype("NOTATION");
+    public static final XSDDatatype XSDNOTATION = new XSDPlainType("NOTATION");
 
     /** Datatype representing xsd:hexBinary */
     public static final XSDDatatype XSDhexBinary = new XSDhexBinary("hexBinary");

Added: incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/xsd/impl/XSDPlainType.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/xsd/impl/XSDPlainType.java?rev=1195185&view=auto
==============================================================================
--- incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/xsd/impl/XSDPlainType.java (added)
+++ incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/xsd/impl/XSDPlainType.java Sun Oct 30 15:53:52 2011
@@ -0,0 +1,45 @@
+/**
+ * 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 com.hp.hpl.jena.datatypes.xsd.impl;
+
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
+import com.hp.hpl.jena.graph.impl.LiteralLabel ;
+
+/** A datatype that does not use the Xerces machinary for isEqual, yet is still an XSDDatatype.
+ * Assumes no derived XSD datatypes.
+ */  
+
+public class XSDPlainType extends XSDDatatype
+{
+    public XSDPlainType(String typeName)
+    {
+        super(typeName) ;
+    }
+    /**
+     * Compares two instances of values of the given datatype.
+     * This default requires value and datatype equality.
+     * This is the same as BaseDatatype
+     */
+    @Override
+    public boolean isEqual(LiteralLabel litLabel1, LiteralLabel litLabel2) {
+        // This is the function from BaseDatatype!
+        return isEqualPlain(litLabel1, litLabel2) ;
+    }
+}
+

Propchange: incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/datatypes/xsd/impl/XSDPlainType.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Jena2/jena/trunk/src/test/java/com/hp/hpl/jena/graph/test/TestTypedLiterals.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/jena/trunk/src/test/java/com/hp/hpl/jena/graph/test/TestTypedLiterals.java?rev=1195185&r1=1195184&r2=1195185&view=diff
==============================================================================
--- incubator/jena/Jena2/jena/trunk/src/test/java/com/hp/hpl/jena/graph/test/TestTypedLiterals.java (original)
+++ incubator/jena/Jena2/jena/trunk/src/test/java/com/hp/hpl/jena/graph/test/TestTypedLiterals.java Sun Oct 30 15:53:52 2011
@@ -9,25 +9,36 @@
  *****************************************************************/
 package com.hp.hpl.jena.graph.test;
 
-import com.hp.hpl.jena.datatypes.*;
-import com.hp.hpl.jena.datatypes.xsd.*;
-import com.hp.hpl.jena.datatypes.xsd.impl.XMLLiteralType;
-import com.hp.hpl.jena.graph.*;
-import com.hp.hpl.jena.graph.impl.*;
-import com.hp.hpl.jena.graph.query.*;
-import com.hp.hpl.jena.rdf.model.*;
-import com.hp.hpl.jena.shared.impl.JenaParameters;
-import com.hp.hpl.jena.vocabulary.XSD;
-import com.hp.hpl.jena.enhanced.EnhNode;
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import java.math.*;
-import java.util.*;
-import java.io.*;
-
-import org.apache.xerces.impl.dv.util.HexBin;
+import java.io.* ;
+import java.math.BigDecimal ;
+import java.math.BigInteger ;
+import java.util.* ;
+
+import junit.framework.TestCase ;
+import junit.framework.TestSuite ;
+import org.apache.xerces.impl.dv.util.HexBin ;
+
+import com.hp.hpl.jena.datatypes.BaseDatatype ;
+import com.hp.hpl.jena.datatypes.DatatypeFormatException ;
+import com.hp.hpl.jena.datatypes.RDFDatatype ;
+import com.hp.hpl.jena.datatypes.TypeMapper ;
+import com.hp.hpl.jena.datatypes.xsd.IllegalDateTimeFieldException ;
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
+import com.hp.hpl.jena.datatypes.xsd.XSDDateTime ;
+import com.hp.hpl.jena.datatypes.xsd.XSDDuration ;
+import com.hp.hpl.jena.datatypes.xsd.impl.XMLLiteralType ;
+import com.hp.hpl.jena.enhanced.EnhNode ;
+import com.hp.hpl.jena.graph.Factory ;
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.graph.impl.LiteralLabel ;
+import com.hp.hpl.jena.graph.impl.LiteralLabelFactory ;
+import com.hp.hpl.jena.graph.query.Domain ;
+import com.hp.hpl.jena.graph.query.Query ;
+import com.hp.hpl.jena.rdf.model.* ;
+import com.hp.hpl.jena.shared.impl.JenaParameters ;
+import com.hp.hpl.jena.vocabulary.XSD ;
    
 /**
  * Unit test for the typed literal machinery - including RDFDatatype,
@@ -968,6 +979,13 @@ public class TestTypedLiterals extends T
         assertTrue(orig.isIsomorphicWith(m2));
     }
     
+    /** Test that XSD anyURI is not sameValueAs XSD string (Xerces returns a string as the value for both) */ 
+    public void testXSDanyURI() {
+        Node node1 = Node.createLiteral("http://example/", null, XSDDatatype.XSDanyURI) ;
+        Node node2 = Node.createLiteral("http://example/", null, XSDDatatype.XSDstring) ;
+        assertFalse(node1.sameValueAs(node2)) ;
+    }
+    
     /**
      * Test a user error report concerning date/time literals
      */