org.openanzo.utils
Class StatementUtils

java.lang.Object
  extended by org.openanzo.utils.StatementUtils

public class StatementUtils
extends java.lang.Object

Basic utilities for Statements and Literal

Author:
Matthew Roy ( mroy@cambridgesemantics.com )

Constructor Summary
StatementUtils()
           
 
Method Summary
static void addAllMatches(java.util.Collection<org.openrdf.model.Statement> matches, java.util.Iterator<org.openrdf.model.Statement> statements, org.openrdf.model.Resource s, org.openrdf.model.URI p, org.openrdf.model.Value o)
          Add all statements from Iterator into collection that match the given subj,prop,obj pattern
static boolean areTypesCompatible(org.openrdf.model.URI t1, org.openrdf.model.URI t2)
          Determine if 2 URI datatypes are compatible
static java.util.Calendar convertToCalendar(org.openrdf.model.Literal dateTime)
          Convert the literal to a Calendar object
static java.util.Date convertToDate(org.openrdf.model.Literal dateTime)
          Convert the literal to a Date object
static java.lang.Long convertToTimestamp(org.openrdf.model.Literal dateTime)
          Convert an XSD:DateTime Literal to its long representation
static org.openrdf.model.Literal convertToXsdDateTime(org.openrdf.model.ValueFactory valueFactory, java.sql.Timestamp timestamp)
          Convert a timestamp to an XSD:DateTime Literal
static java.lang.String convertToXsdDateTimeString(java.util.Calendar calendar)
          Convert a calendar to its XSD:dateTime string representation
static java.lang.String convertToXsdDateTimeString(java.util.Date date)
          Convert a Date object to an XSD:dateTime string representation
static org.openrdf.model.Literal getLiteral(java.lang.Object value, java.lang.String returnType, java.lang.String rangeUri)
          Convert the Literal object to the expected type
static
<T> java.lang.Object
getLiteralValue(org.openrdf.model.Literal literal, java.lang.Class<T> expectedType)
          Convert the Literal object to the expected type
static java.lang.Class<?> getNativeType(org.openrdf.model.URI datatype)
          Get the Native Object type that this datatype should be converted
static java.lang.Object getNativeValue(org.openrdf.model.Literal literal)
          Try to convert Literal to native object based on datatype
static boolean match(org.openrdf.model.Statement statement, org.openrdf.model.Resource subj, org.openrdf.model.URI prop, org.openrdf.model.Value obj, org.openrdf.model.Resource context)
          Determine if given statement matches given subject,prop,obj,namedgraph pattern
static void writeStatements(java.util.Collection<org.openrdf.model.Statement> statements, java.io.OutputStream outputStream)
          Write contents of graph to writer using N3 serialization
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatementUtils

public StatementUtils()
Method Detail

writeStatements

public static void writeStatements(java.util.Collection<org.openrdf.model.Statement> statements,
                                   java.io.OutputStream outputStream)
Write contents of graph to writer using N3 serialization

Parameters:
statements - to write to outputStream
outputStream - to which statements are to be written

addAllMatches

public static void addAllMatches(java.util.Collection<org.openrdf.model.Statement> matches,
                                 java.util.Iterator<org.openrdf.model.Statement> statements,
                                 org.openrdf.model.Resource s,
                                 org.openrdf.model.URI p,
                                 org.openrdf.model.Value o)
Add all statements from Iterator into collection that match the given subj,prop,obj pattern

Parameters:
matches - Collection of statements to which matches are added
statements - Iterator of statements to determine matches
s - Subject of statements to match, or null for any
p - Predicate of statements to match, or null for any
o - Object of statements to match, or null for any

match

public static boolean match(org.openrdf.model.Statement statement,
                            org.openrdf.model.Resource subj,
                            org.openrdf.model.URI prop,
                            org.openrdf.model.Value obj,
                            org.openrdf.model.Resource context)
Determine if given statement matches given subject,prop,obj,namedgraph pattern

Parameters:
statement - Statement to compare against match parameters
subj - Subject to match, or null for any
prop - Predicate to match, or null for any
obj - Object to match, or null for any
context - NamedGraph to match, or null for any
Returns:
true if statement provided matches the 4 parameters passed

getLiteralValue

public static <T> java.lang.Object getLiteralValue(org.openrdf.model.Literal literal,
                                                   java.lang.Class<T> expectedType)
Convert the Literal object to the expected type

Type Parameters:
T - Expected type
Parameters:
literal - object to convert
expectedType - expect type of converted object
Returns:
converted literal value

areTypesCompatible

public static final boolean areTypesCompatible(org.openrdf.model.URI t1,
                                               org.openrdf.model.URI t2)
Determine if 2 URI datatypes are compatible

Parameters:
t1 - first datatype to compare
t2 - second datatype to compare
Returns:
true if the 2 datatypes are compatible

getLiteral

public static org.openrdf.model.Literal getLiteral(java.lang.Object value,
                                                   java.lang.String returnType,
                                                   java.lang.String rangeUri)
Convert the Literal object to the expected type

Parameters:
value - native object to convert into Literal object
returnType - expected type of converted object
rangeUri - dataType to set on return Literal
Returns:
converted literal value

getNativeValue

public static java.lang.Object getNativeValue(org.openrdf.model.Literal literal)
Try to convert Literal to native object based on datatype

Parameters:
literal - Literal to convert
Returns:
native value of object based on datatype, or a string if no match

getNativeType

public static java.lang.Class<?> getNativeType(org.openrdf.model.URI datatype)
Get the Native Object type that this datatype should be converted

Parameters:
datatype - to determine native type for
Returns:
Native type class for this rdf datatype

convertToDate

public static java.util.Date convertToDate(org.openrdf.model.Literal dateTime)
Convert the literal to a Date object

Parameters:
dateTime - Literal to convert to date
Returns:
date representation of Literal

convertToCalendar

public static java.util.Calendar convertToCalendar(org.openrdf.model.Literal dateTime)
Convert the literal to a Calendar object

Parameters:
dateTime - Literal to convert to Calendar
Returns:
Calendar representation of Literal

convertToXsdDateTimeString

public static java.lang.String convertToXsdDateTimeString(java.util.Calendar calendar)
Convert a calendar to its XSD:dateTime string representation

Parameters:
calendar - Calendar to convert
Returns:
XSD:dateTime string representation of Calendar

convertToXsdDateTimeString

public static java.lang.String convertToXsdDateTimeString(java.util.Date date)
Convert a Date object to an XSD:dateTime string representation

Parameters:
date - Date to convert
Returns:
SD:dateTime string representation of Date

convertToXsdDateTime

public static org.openrdf.model.Literal convertToXsdDateTime(org.openrdf.model.ValueFactory valueFactory,
                                                             java.sql.Timestamp timestamp)
Convert a timestamp to an XSD:DateTime Literal

Parameters:
valueFactory - Valuefactory used to create literal object
timestamp - Timestamp to convert
Returns:
XSD:DateTime Literal

convertToTimestamp

public static java.lang.Long convertToTimestamp(org.openrdf.model.Literal dateTime)
Convert an XSD:DateTime Literal to its long representation

Parameters:
dateTime - XSD:DateTime Literal to convert
Returns:
long representation of literal


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.