Index: src/nongnu/cashews/rdf/Literal.java
===================================================================
RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/rdf/Literal.java,v
retrieving revision 1.4
diff -u -3 -p -u -r1.4 Literal.java
--- src/nongnu/cashews/rdf/Literal.java 4 Apr 2005 00:59:33 -0000 1.4
+++ src/nongnu/cashews/rdf/Literal.java 4 Apr 2005 21:55:39 -0000
@@ -69,6 +69,19 @@ public class Literal
}
/**
+ * Constructs a Literal
using the specified lexical form
+ * and type.
+ *
+ * @param lexicalForm the lexical form of this literal.
+ * @param type the type of this literal.
+ */
+ public Literal(String lexicalForm, Type type)
+ {
+ this(lexicalForm);
+ setType(type);
+ }
+
+ /**
* Returns a textual representation of the literal.
*
* @return a textual representation.
Index: src/nongnu/cashews/rdf/Type.java
===================================================================
RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/rdf/Type.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 Type.java
--- src/nongnu/cashews/rdf/Type.java 4 Apr 2005 00:59:33 -0000 1.2
+++ src/nongnu/cashews/rdf/Type.java 4 Apr 2005 21:55:39 -0000
@@ -32,6 +32,7 @@ package nongnu.cashews.rdf;
* @author Andrew John Hughes (address@hidden)
*/
public interface Type
+ extends Cloneable
{
/**
Index: src/nongnu/cashews/rdf/TypeFactory.java
===================================================================
RCS file: src/nongnu/cashews/rdf/TypeFactory.java
diff -N src/nongnu/cashews/rdf/TypeFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/nongnu/cashews/rdf/TypeFactory.java 4 Apr 2005 21:55:39 -0000
@@ -0,0 +1,107 @@
+/* TypeFactory.java -- Factory for generating type instances.
+ Copyright (C) 2005 The University of Sheffield.
+
+ This file is part of the CASheW-s editor.
+
+ The CASheW-s editor is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ The CASheW-s editor is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with The CASheW-s editor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA.
+*/
+
+package nongnu.cashews.rdf;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * This factory generates a type instance for a URI. Type instances provide
+ * the conversion between the literal value and the actual value
+ * represented, by applying a lexical-to-value mapping. Unrecognised URIs
+ * are mapped to an instance of UnknownType
.
+ *
Type
instance corresponding to the supplied
+ * URI.
+ *
+ * @param uri the URI to lookup, in String
form.
+ */
+ public static Type getInstance(String URI)
+ {
+ Class extends Type> typeClass = typeClasses.get(URI);
+ if (typeClass == null)
+ return new UnknownType(URI);
+ else
+ try
+ {
+ return typeClass.getConstructor().newInstance();
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new IllegalArgumentException("There is no type for the "+
+ "specified URI with a "+
+ "no argument constructor:" + e,
+ e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new IllegalArgumentException("There is no type for the "+
+ "specified URI with an "+
+ "accessible constructor: " + e,
+ e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new IllegalArgumentException("A Type instance for this URI "+
+ "could not be instantiated: " + e,
+ e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new IllegalArgumentException("The constructor of the Type "+
+ "instance for this URI "+
+ "threw an exception: " + e,
+ e);
+ }
+ }
+
+}
Index: src/nongnu/cashews/rdf/UnknownType.java
===================================================================
RCS file: src/nongnu/cashews/rdf/UnknownType.java
diff -N src/nongnu/cashews/rdf/UnknownType.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/nongnu/cashews/rdf/UnknownType.java 4 Apr 2005 21:55:39 -0000
@@ -0,0 +1,96 @@
+/* UnknownType.java -- A Type implementation representing an unknown type.
+ Copyright (C) 2005 The University of Sheffield.
+
+ This file is part of the CASheW-s editor.
+
+ The CASheW-s editor is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ The CASheW-s editor is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with The CASheW-s editor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA.
+*/
+
+package nongnu.cashews.rdf;
+
+/**
+ *
+ * An UnknownType
instance results from a URI which does not
+ * match a known type. It implements the type by simply storing its URI
+ * and providing an identity mapping for getValue()
.
+ *
UnknownType
using the specified URI
+ * of the unknown type.
+ *
+ * @param uri the URI of the unknown type.
+ */
+ public UnknownType(String uri)
+ {
+ this.uri = uri;
+ }
+
+ /**
+ * Returns a textual representation of the unknown type.
+ *
+ * @return a textual representation.
+ */
+ public String toString()
+ {
+ return getClass().getName() +
+ "[uri = " +
+ uri +
+ "]";
+ }
+
+ /**
+ * Returns a deep copy of this unknown type.
+ *
+ * @return a clone of the unknown type.
+ */
+ public UnknownType clone()
+ {
+ try
+ {
+ return (UnknownType) super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw new IllegalStateException("Unexpected exception: " + e, e);
+ }
+ }
+
+ /**
+ * Retrieves the actual value of this type instance by applying a lexical to
+ * value mapping. For the unknown type, the mapping is simply an identity
+ * function, and the original lexical value is returned.
+ *
+ * @param lexical the lexical representation of the literal.
+ * @return the supplied lexical.
+ */
+ public String getValue(String lexical)
+ {
+ return lexical;
+ }
+
+}
Index: src/nongnu/cashews/rdf/XMLParser.java
===================================================================
RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/rdf/XMLParser.java,v
retrieving revision 1.5
diff -u -3 -p -u -r1.5 XMLParser.java
--- src/nongnu/cashews/rdf/XMLParser.java 4 Apr 2005 16:00:19 -0000 1.5
+++ src/nongnu/cashews/rdf/XMLParser.java 4 Apr 2005 21:55:39 -0000
@@ -218,6 +218,11 @@ public class XMLParser
private String predicateURI;
/**
+ * The type of the current literal.
+ */
+ private Type type;
+
+ /**
* Constructs a new RDFHandler
, using the specified
* handler for log messages.
*
@@ -240,6 +245,7 @@ public class XMLParser
inRDF = false;
inPredicate = false;
predicateURI = null;
+ type = null;
}
/**
@@ -316,6 +322,7 @@ public class XMLParser
}
else
{
+ /* Check for blank node object */
value = attributes.getValue(RDF_NAMESPACE, "nodeID");
if (value != null)
{
@@ -323,6 +330,10 @@ public class XMLParser
logger.fine("Created object: " + object);
}
}
+ /* Check for a type */
+ value = attributes.getValue(RDF_NAMESPACE, "datatype");
+ if (value != null)
+ type = TypeFactory.getInstance(value);
}
}
}
@@ -366,7 +377,10 @@ public class XMLParser
logger.finer("Characters: " + value);
if (inPredicate)
{
- object = new Literal(value);
+ if (type == null)
+ object = new Literal(value);
+ else
+ object = new Literal(value, type);
logger.fine("Created object: " + object);
}
}
@@ -403,6 +417,7 @@ public class XMLParser
inPredicate = false;
inSubject = true;
predicateURI = null;
+ type = null;
triple = new Triple(subject, predicate, object);
logger.fine("Created triple: " + triple);
graph.addTriple(triple);