org.apache.clerezza.rdf.core
Class LiteralFactory

java.lang.Object
  extended by org.apache.clerezza.rdf.core.LiteralFactory
Direct Known Subclasses:
SimpleLiteralFactory

public abstract class LiteralFactory
extends Object

This class provides methods to convert java objects to typed literals and vice versa. While the default implementation will provide literal objects storing the data's lexical form in memory, other implementations may create literal optimized for processing within the store. Note: this class uses the notion of "Convertor" (in the Exception naming), but does not currently provide a mechanism to register such Convertors. An implementation is said to provide Convertors for the types it supports.

Since:
0.3
Author:
reto

Constructor Summary
LiteralFactory()
           
 
Method Summary
abstract
<T> T
createObject(Class<T> type, TypedLiteral literal)
          Converts a literal to an instance of the specified class
abstract  TypedLiteral createTypedLiteral(Object value)
          Create a typed literal for the specified object
static LiteralFactory getInstance()
          Get a LiteralFactory.
static void setInstance(LiteralFactory instance)
          Set the instance returned by getInstance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LiteralFactory

public LiteralFactory()
Method Detail

getInstance

public static LiteralFactory getInstance()
Get a LiteralFactory. If this has not been set using setInstance it returns an instance of org.apache.clerezza.model.impl.SimpleLiteralFactory.

Returns:
a concrete LiteralFactory

setInstance

public static void setInstance(LiteralFactory instance)
Set the instance returned by getInstance.

Parameters:
instance - the new default LiteralFactory

createTypedLiteral

public abstract TypedLiteral createTypedLiteral(Object value)
                                         throws NoConvertorException
Create a typed literal for the specified object

Parameters:
value - the value of the literal to be created
Returns:
a TypedLiteral representing the value
Throws:
NoConvertorException - thrown if value is of an invalid type

createObject

public abstract <T> T createObject(Class<T> type,
                                   TypedLiteral literal)
                        throws NoConvertorException,
                               InvalidLiteralTypeException
Converts a literal to an instance of the specified class

Type Parameters:
T -
Parameters:
type - the Class of the returned object
literal - the literal to be converted
Returns:
a java object representing the value of the literal
Throws:
NoConvertorException - thrown if type is unsupported
InvalidLiteralTypeException - if the literal type doesn't match the requested java type


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.