org.openanzo.serialization
Class SerializationUtils

java.lang.Object
  extended by org.openanzo.serialization.SerializationUtils

public class SerializationUtils
extends java.lang.Object

Utility methods used to serialize and deserialize data

Author:
Matthew Roy ( mroy@cambridgesemantics.com )

Field Summary
static int ANY
          Constant for the WILDCARD Any type
static boolean BASE64_ENABLED
          Should the contents of elements be encoded as Base64
static int BNODE
          Constant for BLANKNode object type
static boolean GZIP_ENABLED
          Should contents of elements be gziped
static int LIT
          Constant for Literal object type
static int TRANSPORT_N3
          Constant for N3 serialization type
static int TRANSPORT_NTRIPLE
          Constant for NTriple serialization type
static int TRANSPORT_RDFXML
          Constant for RDFXML serialization type
static int TRANSPORT_TRIX
          Constant for NTriple serialization type
static int TRANSPORT_TYPE
          Default serialization type for system
static int URI
          Constant for URI object type
 
Constructor Summary
SerializationUtils()
           
 
Method Summary
static org.openrdf.model.Value convertAnyToUri(org.openrdf.model.Value node)
          Convert a NULL value to the ANY uri
static org.openrdf.model.Value convertUriToAny(org.openrdf.model.Value node)
          Convert Constants.ANY_URI to a null
static org.openrdf.model.Value createValueFromData(int type, java.lang.String nodeString, java.lang.String dataType, java.lang.String lang)
          Create a Value object from decoded data
static java.lang.String decode(java.lang.String encodedString)
          Decode encoded string to decoded string
static java.lang.String deserialize(javax.xml.soap.SOAPElement sourceElement)
          Deserialize SOAP element to a string
static void deserializeToHandler(javax.xml.soap.SOAPElement sourceElement, IRepositoryHandler handler)
          Deserialize SOAP element to an XML stream, and parse stream to IRepositoryHandler
static java.util.Map<org.openrdf.model.URI,java.util.ArrayList<org.openrdf.model.Statement>>[] deserializeToIterator(javax.xml.soap.SOAPElement serializedStatements)
          Deserialize SOAP element to an map of URIs and statements for those URIs
static org.openrdf.query.TupleQueryResult deserializeToResultSet(javax.xml.soap.SOAPElement sourceElement)
          Deserialize SOAP element to query results
static org.openrdf.query.TupleQueryResult deserializeToResultSet(java.lang.String encodedData)
          Deserialize encoded queryresults to a TupleQueryResult using system default encoding and system default serialization format
static java.util.Collection<org.openrdf.model.Statement> deserializeToStatements(javax.xml.soap.SOAPElement statementsElement)
          Deserialize SOAP element to a graph
static java.util.Collection<org.openrdf.model.Statement> deserializeToStatements(java.lang.String encodedData)
          Deserialize an encoded string to a graph using system default encoding and system default serialization format
static java.io.InputStream deserializeToStream(javax.xml.soap.SOAPElement addElement)
          Deserialize SOAP element to an input stream that can be processed by other methods
static org.openrdf.model.Value deserializeToValue(org.apache.axis.message.MessageElement encodedValue)
          Deserialize SOAP element to a Value
static java.lang.String formatNode(org.openrdf.model.Value value)
          Get the formated string version of Value
static java.lang.String getDefaultFormat()
          Get the default RDF format type
static org.openrdf.rio.RDFFormat getDefaultFormatter()
          Get the default RDF formatter
static java.util.Set<IPrecondition> parsePreconditionStatements(java.util.Collection<org.openrdf.model.Statement> statements)
          Parse a set of statements into the Preconditions that are encoded within
static org.openrdf.query.TupleQueryResult readQueryResults(java.io.InputStream inputStream)
          Read data from inputStream into a new TupleQueryResult
static void readStatements(java.util.Collection<org.openrdf.model.Statement> statements, java.io.InputStream inputStream)
          Read data from reader into a set of statements
static void serialize(java.util.Collection<org.openrdf.model.Statement> statements, javax.xml.soap.SOAPElement childElement, boolean useElementTextNode)
          Serialize the contents of a graph to a SOAP element using system default encoding style
static void serialize(java.io.OutputStream outputStream, java.io.ByteArrayOutputStream sourceStream, javax.xml.soap.SOAPElement element)
          Serialize a stream to a SOAP element using system default encoding
static java.lang.String serialize(java.lang.String string)
          Serialize a string based on system default encoding style
static void serialize(java.lang.String string, javax.xml.soap.SOAPElement childElement, boolean useElementTextNode)
          Serialize a string to a SOAP element using system default encoding style
static info.aduna.collections.iterators.CloseableIterator<org.openrdf.model.Statement> serializePreconditions(java.util.Set<IPrecondition> preconditions)
          Serialize a set of IPreconditions to a set of statements
static void serializeStatementsToElement(boolean additions, org.openrdf.model.URI namedGraphUri, java.util.Collection<org.openrdf.model.Statement> statements, javax.xml.soap.SOAPElement childElement, boolean useElementTextNode)
          Serialize the contents of graph containing Anzo additions or deletions into a SOAP element
static void serializeTransactions(ITransaction[] transactions, javax.xml.soap.SOAPElement destinationElement)
          Serialize an array of ITransactions to SOAP element
static boolean serializeTransactionsStream(ITransaction[] transactions, java.io.OutputStream stream)
          Serialize an array of ITransactions to an output stream
static void serializeValue(org.openrdf.model.Value[] values, javax.xml.soap.SOAPElement encodedElement)
          Serialize Value array to SOAPElement
static void serializeValue(org.openrdf.model.Value value, javax.xml.soap.SOAPElement encodedElement)
          Serialize Value to SOAPElement
static void setEncoding(javax.xml.soap.SOAPElement childElement)
          Set the encoding style of a SOAP element to the system default encoding style
static java.lang.String statementsToString(java.util.Collection<org.openrdf.model.Statement> statements)
          Serialize statements to a string using system default serialization format
static java.io.OutputStream wrapSerializerStream(java.io.ByteArrayOutputStream outputStream)
          Wrap outputStream with GZIP stream if gzip enabled
static void writeStatements(java.util.Iterator<org.openrdf.model.Statement> statements, java.io.OutputStream outputStream)
          Write contents of statements into outputStream using system default serialization
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GZIP_ENABLED

public static final boolean GZIP_ENABLED
Should contents of elements be gziped

See Also:
Constant Field Values

BASE64_ENABLED

public static final boolean BASE64_ENABLED
Should the contents of elements be encoded as Base64

See Also:
Constant Field Values

TRANSPORT_RDFXML

public static final int TRANSPORT_RDFXML
Constant for RDFXML serialization type

See Also:
Constant Field Values

TRANSPORT_N3

public static final int TRANSPORT_N3
Constant for N3 serialization type

See Also:
Constant Field Values

TRANSPORT_NTRIPLE

public static final int TRANSPORT_NTRIPLE
Constant for NTriple serialization type

See Also:
Constant Field Values

TRANSPORT_TRIX

public static final int TRANSPORT_TRIX
Constant for NTriple serialization type

See Also:
Constant Field Values

TRANSPORT_TYPE

public static int TRANSPORT_TYPE
Default serialization type for system


URI

public static final int URI
Constant for URI object type

See Also:
Constant Field Values

BNODE

public static final int BNODE
Constant for BLANKNode object type

See Also:
Constant Field Values

LIT

public static final int LIT
Constant for Literal object type

See Also:
Constant Field Values

ANY

public static final int ANY
Constant for the WILDCARD Any type

See Also:
Constant Field Values
Constructor Detail

SerializationUtils

public SerializationUtils()
Method Detail

getDefaultFormat

public static java.lang.String getDefaultFormat()
Get the default RDF format type

Returns:
the default RDF format type

getDefaultFormatter

public static org.openrdf.rio.RDFFormat getDefaultFormatter()
Get the default RDF formatter

Returns:
the default RDF formatter

setEncoding

public static void setEncoding(javax.xml.soap.SOAPElement childElement)
                        throws AnzoException
Set the encoding style of a SOAP element to the system default encoding style

Parameters:
childElement -
Throws:
AnzoException

serialize

public static java.lang.String serialize(java.lang.String string)
                                  throws AnzoException
Serialize a string based on system default encoding style

Parameters:
string - to serialize
Returns:
serialized string
Throws:
AnzoException

serialize

public static void serialize(java.lang.String string,
                             javax.xml.soap.SOAPElement childElement,
                             boolean useElementTextNode)
                      throws AnzoException
Serialize a string to a SOAP element using system default encoding style

Parameters:
string - String to encode
childElement - Element to which data is added
useElementTextNode - Use a text node for element, or simply set element value
Throws:
AnzoException

serialize

public static void serialize(java.util.Collection<org.openrdf.model.Statement> statements,
                             javax.xml.soap.SOAPElement childElement,
                             boolean useElementTextNode)
                      throws AnzoException
Serialize the contents of a graph to a SOAP element using system default encoding style

Parameters:
statements - Set of statements to serialize
childElement - SOAP element to which data is added
useElementTextNode - Use a text node for element, or simply set element value
Throws:
AnzoException

serializeStatementsToElement

public static void serializeStatementsToElement(boolean additions,
                                                org.openrdf.model.URI namedGraphUri,
                                                java.util.Collection<org.openrdf.model.Statement> statements,
                                                javax.xml.soap.SOAPElement childElement,
                                                boolean useElementTextNode)
                                         throws AnzoException
Serialize the contents of graph containing Anzo additions or deletions into a SOAP element

Parameters:
additions - Are changes additions or deletions
namedGraphUri - URI of NamedGraph that changes affect
statements - Set of statements to serialize
childElement - SOAP element to which data is added
useElementTextNode - Use a text node for element, or simply set element value
Throws:
AnzoException

wrapSerializerStream

public static java.io.OutputStream wrapSerializerStream(java.io.ByteArrayOutputStream outputStream)
                                                 throws AnzoException
Wrap outputStream with GZIP stream if gzip enabled

Parameters:
outputStream - to wrap
Returns:
gzip wrapped outputStream
Throws:
AnzoException - if there was an IO error wrapping outputStream

serialize

public static void serialize(java.io.OutputStream outputStream,
                             java.io.ByteArrayOutputStream sourceStream,
                             javax.xml.soap.SOAPElement element)
                      throws AnzoException
Serialize a stream to a SOAP element using system default encoding

Parameters:
outputStream - stream to which data is written
sourceStream - source of data to write
element - soapElement to which encoded data is added
Throws:
AnzoException

deserializeToStatements

public static java.util.Collection<org.openrdf.model.Statement> deserializeToStatements(java.lang.String encodedData)
                                                                                 throws AnzoException
Deserialize an encoded string to a graph using system default encoding and system default serialization format

Parameters:
encodedData - data to decode
Returns:
Set of deserialized statements
Throws:
AnzoException - if there was an encoding or IO error deserializing data

deserializeToResultSet

public static org.openrdf.query.TupleQueryResult deserializeToResultSet(java.lang.String encodedData)
                                                                 throws AnzoException
Deserialize encoded queryresults to a TupleQueryResult using system default encoding and system default serialization format

Parameters:
encodedData - data to decode
Returns:
deserialized TupleQueryResult
Throws:
AnzoException - if there was an encoding or IO error deserializing data

deserializeToStream

public static java.io.InputStream deserializeToStream(javax.xml.soap.SOAPElement addElement)
                                               throws AnzoException
Deserialize SOAP element to an input stream that can be processed by other methods

Parameters:
addElement - SOAP element containing data
Returns:
inputStream to be processed
Throws:
AnzoException

deserializeToValue

public static org.openrdf.model.Value deserializeToValue(org.apache.axis.message.MessageElement encodedValue)
                                                  throws AnzoException
Deserialize SOAP element to a Value

Parameters:
encodedValue - SOAP encoded Value
Returns:
deserialized Value
Throws:
AnzoException

serializeValue

public static void serializeValue(org.openrdf.model.Value value,
                                  javax.xml.soap.SOAPElement encodedElement)
                           throws AnzoException
Serialize Value to SOAPElement

Parameters:
value - Value to encode
encodedElement - element to which encoded data is added
Throws:
AnzoException - if there was a SOAPException encoding value

serializeValue

public static void serializeValue(org.openrdf.model.Value[] values,
                                  javax.xml.soap.SOAPElement encodedElement)
                           throws AnzoException
Serialize Value array to SOAPElement

Parameters:
values - Value array to encode
encodedElement - element to which encoded data is added
Throws:
AnzoException - if there was a SOAPException encoding value

decode

public static java.lang.String decode(java.lang.String encodedString)
                               throws AnzoException
Decode encoded string to decoded string

Parameters:
encodedString -
Returns:
decoded string
Throws:
AnzoException - if there was an Encoding error decoding string

deserialize

public static java.lang.String deserialize(javax.xml.soap.SOAPElement sourceElement)
                                    throws AnzoException
Deserialize SOAP element to a string

Parameters:
sourceElement -
Returns:
deserialized string
Throws:
AnzoException - if there was an Encoding error decoding string

deserializeToStatements

public static java.util.Collection<org.openrdf.model.Statement> deserializeToStatements(javax.xml.soap.SOAPElement statementsElement)
                                                                                 throws AnzoException
Deserialize SOAP element to a graph

Parameters:
statementsElement - serialized statements to deserialize
Returns:
set of deserialized statements
Throws:
AnzoException - if there was an error deserializing data

deserializeToResultSet

public static org.openrdf.query.TupleQueryResult deserializeToResultSet(javax.xml.soap.SOAPElement sourceElement)
                                                                 throws AnzoException
Deserialize SOAP element to query results

Parameters:
sourceElement - source of serialized data
Returns:
deserialized query results
Throws:
AnzoException - if there was an error deserializing data

deserializeToIterator

public static java.util.Map<org.openrdf.model.URI,java.util.ArrayList<org.openrdf.model.Statement>>[] deserializeToIterator(javax.xml.soap.SOAPElement serializedStatements)
                                                                                                                     throws AnzoException
Deserialize SOAP element to an map of URIs and statements for those URIs

Parameters:
serializedStatements - source element containing serialized statements
Returns:
map of URIs and statements for those URIs
Throws:
AnzoException - if there was an error deserializing data

deserializeToHandler

public static void deserializeToHandler(javax.xml.soap.SOAPElement sourceElement,
                                        IRepositoryHandler handler)
                                 throws AnzoException
Deserialize SOAP element to an XML stream, and parse stream to IRepositoryHandler

Parameters:
sourceElement - source element containing serialized XML update data
handler - used to handle parsed data
Throws:
AnzoException - if there was an error deserializing or handling data

serializeTransactions

public static void serializeTransactions(ITransaction[] transactions,
                                         javax.xml.soap.SOAPElement destinationElement)
                                  throws AnzoException
Serialize an array of ITransactions to SOAP element

Parameters:
transactions - array of transaction to serialize
destinationElement - element to which serialized data is written
Throws:
AnzoException - if there was an error serializing data

serializePreconditions

public static info.aduna.collections.iterators.CloseableIterator<org.openrdf.model.Statement> serializePreconditions(java.util.Set<IPrecondition> preconditions)
Serialize a set of IPreconditions to a set of statements

Parameters:
preconditions - to serialize
Returns:
if there was an error serializing data

parsePreconditionStatements

public static java.util.Set<IPrecondition> parsePreconditionStatements(java.util.Collection<org.openrdf.model.Statement> statements)
Parse a set of statements into the Preconditions that are encoded within

Parameters:
statements - containing data for preconditions
Returns:
set of preconditions contained within statements

serializeTransactionsStream

public static boolean serializeTransactionsStream(ITransaction[] transactions,
                                                  java.io.OutputStream stream)
                                           throws AnzoException
Serialize an array of ITransactions to an output stream

Parameters:
transactions - transaction to serialize
stream - to which serialize data is written
Returns:
true if there was no data contained within array of transactions
Throws:
AnzoException - if there was an error serializing transactions

readStatements

public static void readStatements(java.util.Collection<org.openrdf.model.Statement> statements,
                                  java.io.InputStream inputStream)
                           throws AnzoException
Read data from reader into a set of statements

Parameters:
statements - read from input stream
inputStream - source of statements data
Throws:
AnzoException - if there was an error reading statements from the inputstream

readQueryResults

public static org.openrdf.query.TupleQueryResult readQueryResults(java.io.InputStream inputStream)
                                                           throws AnzoException
Read data from inputStream into a new TupleQueryResult

Parameters:
inputStream - containing queryResults
Returns:
a TupleQueryResult representing query results data
Throws:
AnzoException - if there was an error reading query results from the inputStream

writeStatements

public static void writeStatements(java.util.Iterator<org.openrdf.model.Statement> statements,
                                   java.io.OutputStream outputStream)
                            throws AnzoException
Write contents of statements into outputStream using system default serialization

Parameters:
statements - set of statements to write
outputStream - to which data is written
Throws:
AnzoException - if there was an error writing statements to the outputStream

statementsToString

public static java.lang.String statementsToString(java.util.Collection<org.openrdf.model.Statement> statements)
                                           throws AnzoException
Serialize statements to a string using system default serialization format

Parameters:
statements - set containing statements to serialize
Returns:
serialized string
Throws:
AnzoException - if there was an error writing statements to the string

formatNode

public static java.lang.String formatNode(org.openrdf.model.Value value)
Get the formated string version of Value

Parameters:
value - to format
Returns:
formated value string

createValueFromData

public static org.openrdf.model.Value createValueFromData(int type,
                                                          java.lang.String nodeString,
                                                          java.lang.String dataType,
                                                          java.lang.String lang)
Create a Value object from decoded data

Parameters:
type - Type of Value
nodeString - Value string for Value
dataType - Datatype if Literal
lang - Lang if Literal
Returns:
Value object for provided data

convertAnyToUri

public static org.openrdf.model.Value convertAnyToUri(org.openrdf.model.Value node)
Convert a NULL value to the ANY uri

Parameters:
node - Value to convert to Constants.ANY_URI if node is NULL
Returns:
converted value

convertUriToAny

public static org.openrdf.model.Value convertUriToAny(org.openrdf.model.Value node)
Convert Constants.ANY_URI to a null

Parameters:
node - Value to convert to null if Constants.ANY_URI
Returns:
value or null if equals Constants.ANY_URI


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