info.sswap.ontologies.data.impl
Class ResourceData

java.lang.Object
  extended by info.sswap.ontologies.data.impl.AbstractData
      extended by info.sswap.ontologies.data.impl.ResourceData
All Implemented Interfaces:
Accessor, Data, Parser, Serializer, Validator
Direct Known Subclasses:
HTTPBasicAuthImpl

public class ResourceData
extends AbstractData
implements Accessor

Support for reading and writing resource data (data at the URL of an individual; usually a SSWAPSubject or SSWAPObject).

Author:
Damian Gessler

Field Summary
protected  java.net.URLConnection urlConnection
           
 
Fields inherited from class info.sswap.ontologies.data.impl.AbstractData
DataFormatType, sswapDocument, sswapIndividual
 
Constructor Summary
ResourceData(SSWAPIndividual sswapIndividual)
          Constructs an individual suitable for reading/writing data
 
Method Summary
 java.net.URLConnection access(java.net.URLConnection urlConnection)
          Default implementation just passes urlConnection untouched.
 void close()
          Closes the URL connection and sets it to null.
protected  void finalize()
           
 java.net.URLConnection getConnection()
          Get the underlying URL connection.
protected  java.net.URL getURLConnection()
          Return the first, valid Accessor URL, or the individual's URL if there are no accessors.
 java.io.InputStream readData()
          Accesses, parses, and validates the data from the URL of the data individual.
 void writeData(java.io.InputStream inputStream)
          Accesses, validates, and serializes the data to the URL of the data individual.
 
Methods inherited from class info.sswap.ontologies.data.impl.AbstractData
getAccessors, getFormats, getIndividual, getParsers, getSerializers, getValidators, hasValue, inputStreamToString, parse, serialize, setValue, stringToInputStream, validate
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

urlConnection

protected java.net.URLConnection urlConnection
Constructor Detail

ResourceData

public ResourceData(SSWAPIndividual sswapIndividual)
             throws DataException
Constructs an individual suitable for reading/writing data

Parameters:
sswapIndividual - the subject data individual
Throws:
DataException - on any error establishing resource data support
Method Detail

readData

public java.io.InputStream readData()
                             throws java.io.IOException,
                                    DataException
Accesses, parses, and validates the data from the URL of the data individual. Order of processing is to call the access, parse, and validate methods, any of which may be overridden.

The data source must be of type data:DataFormat for any meaningful read; otherwise a read immediately "succeeds" with trivial empty content.

Specified by:
readData in interface Data
Returns:
InputStream a stream to read the data
Throws:
java.io.IOException - on any read error
DataException - on data error such as parsing, validating, etc.

writeData

public void writeData(java.io.InputStream inputStream)
               throws java.io.IOException,
                      DataException
Accesses, validates, and serializes the data to the URL of the data individual. Order of processing is to call the access, validate, and serialize methods, any of which may be overridden. Caller should close inputStream when done; opened URL connection will be closed automatically on success only. On failure (e.g., a thrown exception), use getConnection to get the underlying connection for error handling. Connection should be then closed by caller when done.

Specified by:
writeData in interface Data
Parameters:
inputStream - data to be written
Throws:
java.io.IOException - on any write error
DataException - on data error such as validating, serializing, etc.
See Also:
getConnection()

getURLConnection

protected java.net.URL getURLConnection()
                                 throws DataException
Return the first, valid Accessor URL, or the individual's URL if there are no accessors.

Returns:
url URL for the individual or one of its accessors
Throws:
DataException - inability to establish any URL for this individual

access

public java.net.URLConnection access(java.net.URLConnection urlConnection)
                              throws java.io.IOException,
                                     AccessorException
Default implementation just passes urlConnection untouched. Custom implementations may extend this class and override this method. Note that accessing is a filter: accepting the urlConnection to access and returning the urlConnection for the next downstream step to read or write.

Specified by:
access in interface Accessor
Parameters:
urlConnection - a URL connection opened on the data element individual (the individual itself or one of its Accessors)
Returns:
URLConnection open URL connection
Throws:
java.io.IOException - on any connection error
AccessorException - on any Accessor-specific error
See Also:
HTTPBasicAuthImpl

getConnection

public java.net.URLConnection getConnection()
Get the underlying URL connection. This method is usually only needed to act on read or write error conditions.

Returns:
the URL connection; null if not set

close

public void close()
Closes the URL connection and sets it to null.


finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable


Copyright (c) 2011, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.