org.sdas.core.client
Class SDASClient

java.lang.Object
  extended by org.sdas.core.client.SDASClient
All Implemented Interfaces:
ISDASProtocol

public class SDASClient
extends java.lang.Object
implements ISDASProtocol

This class allows to connect and interact with a SDAS XML-RPC Server. All methods for getting data, searching parameters and events are fully implemented here.


Nested Class Summary
 class SDASClient.HttpAuthenticateProxy
           
 
Field Summary
 
Fields inherited from interface org.sdas.core.common.ISDASProtocol
SERVER_HANDLER_ID
 
Constructor Summary
SDASClient(java.lang.String hostname, int port)
          Creates a new instance of SDASClient.
SDASClient(java.lang.String hostname, int port, int timeout, boolean synchronizePlugins, java.lang.String proxyURL, int proxyPort, java.lang.String proxyUser, java.lang.String proxyPass, java.lang.String credentialsFile)
          Creates a new instance of SDASClient.
SDASClient(java.lang.String hostname, int port, int timeout, java.lang.String credentialsFile)
          Creates a new instance of SDASClient.
SDASClient(java.lang.String hostname, int port, java.lang.String credentialsFile)
          Creates a new instance of SDASClient.
SDASClient(java.lang.String hostname, int port, java.lang.String proxyURL, int proxyPort)
          Creates a new instance of SDASClient.
SDASClient(java.lang.String hostname, int port, java.lang.String proxyURL, int proxyPort, java.lang.String proxyUser, java.lang.String proxyPass)
          Creates a new instance of SDASClient.
 
Method Summary
 java.lang.String authenticate(java.lang.String[][] credentials)
           
 void deletePlugins()
          Delete all the plug-ins from the plug-in dir
 void fetchPlugins()
          Fetch the plug-ins from the server and saves them on the plug-in directory
 IData[] getData(java.lang.String parameterUniqueID, IHEvent event)
          Fetches a data structure from the SDAS server.
 IData[] getData(java.lang.String parameterUniqueID, java.lang.String eventUniqueID, int eventNumber)
          Fetches a data structure from the SDAS server.
 IData[][] getMultipleData(java.lang.String[] parameterUniqueID, IHEvent event)
          Fetches several data structures from the SDAS server.
 IData[][] getMultipleData(java.lang.String[] parameterUniqueID, IHEvent[] event)
          Fetches several data structures from the SDAS server.
 IData[][] getMultipleData(java.lang.String[] parameterUniqueID, java.lang.String[] eventUniqueID, int[] eventNumber)
          Fetches several data structures from the SDAS server.
 IData[][] getMultipleData(java.lang.String[] parameterUniqueID, java.lang.String eventUniqueID, int eventNumber)
          Fetches several data structures from the SDAS server.
 IData[][] getMultipleData(java.lang.String parameterUniqueID, java.lang.String[] eventUniqueID, int[] eventNumber)
          Fetches several data structures, all for the same parameter, from the SDAS server.
 IData[][] getMultipleData(java.lang.String parameterUniqueID, java.lang.String eventUniqueID, int[] eventNumber)
          Fetches several data structures, all for the same parameter, from the SDAS server.
 byte[][] getPluginFiles()
          Returns all the plug-in files as byte arrays.
 IUserData getUserData(IData data)
          Return data as a user data structure
 void logout()
           
 boolean parameterExists(java.lang.String parameterUniqueID, java.lang.String eventUniqueID, int eventNumber)
          Checks if a parameter exists for a particular event.
 boolean putData(IData data)
          Stores this data on the server.
 void reloadPlugins()
          Reloads all the plugins
 java.lang.String[] searchDataByEvent(IHEvent event)
          Searches data by an event.
 java.lang.String[] searchDataByEvent(java.lang.String eventUniqueID, int eventNumber)
          Searches data by an event.
 IDescriptorUID[] searchDeclaredEventsByDescription(java.lang.String search)
          Searches declared events by the description.
 IDescriptorUID[] searchDeclaredEventsByDescription(java.lang.String search, java.lang.String locale)
          Searches declared events by the description and locale.
 IDescriptorUID[] searchDeclaredEventsByName(java.lang.String search)
          Searches declared events by the name.
 IDescriptorUID[] searchDeclaredEventsByName(java.lang.String search, java.lang.String locale)
          Searches declared events by the name and locale.
 IDescriptorUID[] searchDeclaredEventsByUniqueID(java.lang.String uniqueID)
          Searches declared events by the unique identifier.
 IHEvent[] searchEventsByEventNumber(int number)
          Searches events by the event number.
 IHEvent[] searchEventsByEventTimeWindow(ITimeStamp tstart, ITimeStamp tend)
          Searches events whose time stamp is inside a time window.
 int searchMaxEventNumber(java.lang.String uniqueID)
          Searches the maximum event number for an event defined by this uniqueID.
 int searchMinEventNumber(java.lang.String uniqueID)
          Searches the minimum event number for an event defined by this uniqueID.
 IParameter[] searchParametersByDescription(java.lang.String search)
          Searches parameters by the description.
 IParameter[] searchParametersByDescription(java.lang.String search, java.lang.String locale)
          Searches parameters by the description and locale.
 IParameter[] searchParametersByName(java.lang.String search)
          Searches parameters by the name.
 IParameter[] searchParametersByName(java.lang.String search, java.lang.String locale)
          Searches parameters by the name and locale.
 IParameter[] searchParametersByUniqueID(java.lang.String uniqueID)
          Search parameters by the unique identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SDASClient

public SDASClient(java.lang.String hostname,
                  int port)
           throws java.net.MalformedURLException,
                  java.io.IOException,
                  BadCredentials
Creates a new instance of SDASClient. By default it automatically synchronizes all the plug-ins. Connects without credentials

Parameters:
hostname - the location of the SDAS server.
port - the port of the SDAS server.
Throws:
java.net.MalformedURLException - if an invalid hostname is entered.
java.io.IOException - if connection to the SDAS server cannot be established.
BadCredentials - if the credentials aren't accepted on the server.

SDASClient

public SDASClient(java.lang.String hostname,
                  int port,
                  java.lang.String credentialsFile)
           throws java.net.MalformedURLException,
                  java.io.IOException,
                  BadCredentials
Creates a new instance of SDASClient. By default it automatically synchronizes all the plug-ins

Parameters:
hostname - the location of the SDAS server.
port - the port of the SDAS server.
credentialsFile - the location of the file with the credentials information. This file is a list of key/values separated by comma
Throws:
java.net.MalformedURLException - if an invalid hostname is entered.
java.io.IOException - if connection to the SDAS server cannot be established.
BadCredentials - if the credentials aren't accepted on the server.

SDASClient

public SDASClient(java.lang.String hostname,
                  int port,
                  int timeout,
                  java.lang.String credentialsFile)
           throws java.net.MalformedURLException,
                  java.io.IOException,
                  BadCredentials
Creates a new instance of SDASClient. By default it automatically synchronizes all the plug-ins

Parameters:
hostname - the location of the SDAS server.
port - the port of the SDAS server.
timeout - the maximum time to successfully create a connection.
credentialsFile - the location of the file with the credentials information. This file is a list of key/values separated by comma
Throws:
java.net.MalformedURLException - if an invalid hostname is entered.
java.io.IOException - if connection to the SDAS server cannot be established.
BadCredentials - if the credentials aren't accepted on the server.

SDASClient

public SDASClient(java.lang.String hostname,
                  int port,
                  java.lang.String proxyURL,
                  int proxyPort)
           throws java.net.MalformedURLException,
                  java.io.IOException,
                  BadCredentials
Creates a new instance of SDASClient. By default it automatically synchronizes all the plug-ins

Parameters:
hostname - the location of the SDAS server.
port - the port of the SDAS server.
proxyURL - the proxy url
proxyPort - the proxy port
Throws:
java.net.MalformedURLException - if an invalid hostname is entered.
java.io.IOException - if connection to the SDAS server cannot be established.
BadCredentials - if the credentials aren't accepted on the server.

SDASClient

public SDASClient(java.lang.String hostname,
                  int port,
                  java.lang.String proxyURL,
                  int proxyPort,
                  java.lang.String proxyUser,
                  java.lang.String proxyPass)
           throws java.net.MalformedURLException,
                  java.io.IOException,
                  BadCredentials
Creates a new instance of SDASClient. By default it automatically synchronizes all the plug-ins

Parameters:
hostname - the location of the SDAS server.
port - the port of the SDAS server.
proxyURL - the proxy url
proxyPort - the proxy port
proxyUser - the proxy user
proxyPass - the proxy password
Throws:
java.net.MalformedURLException - if an invalid hostname is entered.
java.io.IOException - if connection to the SDAS server cannot be established.
BadCredentials - if the credentials aren't accepted on the server.

SDASClient

public SDASClient(java.lang.String hostname,
                  int port,
                  int timeout,
                  boolean synchronizePlugins,
                  java.lang.String proxyURL,
                  int proxyPort,
                  java.lang.String proxyUser,
                  java.lang.String proxyPass,
                  java.lang.String credentialsFile)
           throws java.net.MalformedURLException,
                  java.io.IOException,
                  BadCredentials
Creates a new instance of SDASClient.

Parameters:
hostname - the location of the SDAS server.
port - the port of the SDAS server.
timeout - the maximum time to successfully create a connection.
synchronizePlugins - if to fetch the plugins from the server
proxyURL - the proxy url
proxyPort - the proxy port
proxyUser - the proxy user
proxyPass - the proxy password
credentialsFile - the location of the file with the credentials information. This file is a list of key/values separated by comma
Throws:
java.net.MalformedURLException - if an invalid hostname is entered.
java.io.IOException - if connection to the SDAS server cannot be established.
BadCredentials - if the credentials aren't accepted on the server.
Method Detail

searchDeclaredEventsByDescription

public IDescriptorUID[] searchDeclaredEventsByDescription(java.lang.String search)
Searches declared events by the description.

Specified by:
searchDeclaredEventsByDescription in interface ISDASProtocol
Parameters:
search - the word(s) to search.
Returns:
an array with all the declared events information with a description that partially or fully matches the word(s) to search.

searchDeclaredEventsByDescription

public IDescriptorUID[] searchDeclaredEventsByDescription(java.lang.String search,
                                                          java.lang.String locale)
Searches declared events by the description and locale.

Specified by:
searchDeclaredEventsByDescription in interface ISDASProtocol
Parameters:
search - the word(s) to search.
locale - the locale in the format languageCode_countryCode, for example: pt_PT
Returns:
an array with all the declared events information with a description that partially or fully matches the word(s) to search in the requested locale.

searchDeclaredEventsByUniqueID

public IDescriptorUID[] searchDeclaredEventsByUniqueID(java.lang.String uniqueID)
Searches declared events by the unique identifier.

Specified by:
searchDeclaredEventsByUniqueID in interface ISDASProtocol
Parameters:
uniqueID - the unique identifier to search.
Returns:
an array with all the declared events information with a description that partially or fully matches the word(s) to search.

searchDeclaredEventsByName

public IDescriptorUID[] searchDeclaredEventsByName(java.lang.String search)
Searches declared events by the name.

Specified by:
searchDeclaredEventsByName in interface ISDASProtocol
Parameters:
search - the word(s) to search.
Returns:
an array with all the declared events information with a name that partially or fully matches the word(s) to search.

searchDeclaredEventsByName

public IDescriptorUID[] searchDeclaredEventsByName(java.lang.String search,
                                                   java.lang.String locale)
Searches declared events by the name and locale.

Specified by:
searchDeclaredEventsByName in interface ISDASProtocol
Parameters:
search - the word(s) to search.
locale - the locale in the format languageCode_countryCode, for example: pt_PT
Returns:
an array with all the declared events information with a name that partially or fully matches the word(s) to search in the requested locale.

searchEventsByEventNumber

public IHEvent[] searchEventsByEventNumber(int number)
Searches events by the event number.

Specified by:
searchEventsByEventNumber in interface ISDASProtocol
Parameters:
number - the number to search.
Returns:
all the events found that have this event number.

searchMaxEventNumber

public int searchMaxEventNumber(java.lang.String uniqueID)
Searches the maximum event number for an event defined by this uniqueID.

Specified by:
searchMaxEventNumber in interface ISDASProtocol
Parameters:
uniqueID - the unique identifier of the event.
Returns:
the maximum event number or zero if the event isn't found.

searchMinEventNumber

public int searchMinEventNumber(java.lang.String uniqueID)
Searches the minimum event number for an event defined by this uniqueID.

Specified by:
searchMinEventNumber in interface ISDASProtocol
Parameters:
uniqueID - the unique identifier of the event.
Returns:
the minimum event number or zero if the event isn't found.

searchEventsByEventTimeWindow

public IHEvent[] searchEventsByEventTimeWindow(ITimeStamp tstart,
                                               ITimeStamp tend)
Searches events whose time stamp is inside a time window.

Specified by:
searchEventsByEventTimeWindow in interface ISDASProtocol
Parameters:
tstart - from this time.
tend - to this time.
Returns:
all the events whose time stamp is superior to tstart and inferior to tend.

searchParametersByUniqueID

public IParameter[] searchParametersByUniqueID(java.lang.String uniqueID)
Search parameters by the unique identifier.

Specified by:
searchParametersByUniqueID in interface ISDASProtocol
Parameters:
uniqueID - the unique identifier to search.
Returns:
an array with all the parameters with an unique identifier that partially of fully matches the uniqueID to search.

searchParametersByDescription

public IParameter[] searchParametersByDescription(java.lang.String search)
Searches parameters by the description.

Specified by:
searchParametersByDescription in interface ISDASProtocol
Parameters:
search - the word(s) to search.
Returns:
an array with all the parameters with a description that partially or fully matches the word(s) to search.

searchParametersByDescription

public IParameter[] searchParametersByDescription(java.lang.String search,
                                                  java.lang.String locale)
Searches parameters by the description and locale.

Specified by:
searchParametersByDescription in interface ISDASProtocol
Parameters:
search - the word(s) to search.
locale - the locale in the format languageCode_countryCode, for example: pt_PT
Returns:
an array with all the parameters with a description that partially or fully matches the word(s) to search in the requested locale.

searchParametersByName

public IParameter[] searchParametersByName(java.lang.String search)
Searches parameters by the name.

Specified by:
searchParametersByName in interface ISDASProtocol
Parameters:
search - the word(s) to search.
Returns:
an array with all the parameters with a name that partially or fully matches the word(s) to search.

searchParametersByName

public IParameter[] searchParametersByName(java.lang.String search,
                                           java.lang.String locale)
Searches parameters by the name and locale.

Specified by:
searchParametersByName in interface ISDASProtocol
Parameters:
search - the word(s) to search.
locale - the locale in the format languageCode_countryCode, for example: pt_PT
Returns:
an array with all the parameters with a name that partially or fully matches the word(s) to search in the requested locale.

searchDataByEvent

public java.lang.String[] searchDataByEvent(IHEvent event)
Searches data by an event. This method can be very time consuming. Avoid using it unless you really need it!

Specified by:
searchDataByEvent in interface ISDASProtocol
Parameters:
event - the event to search.
Returns:
an array with all the parameters unique identifiers whose data isn't null for this event.

searchDataByEvent

public java.lang.String[] searchDataByEvent(java.lang.String eventUniqueID,
                                            int eventNumber)
Searches data by an event. This method can be very time consuming. Avoid using it unless you really need it!

Specified by:
searchDataByEvent in interface ISDASProtocol
Parameters:
eventUniqueID - the event unique identifier.
eventNumber - the event number.
Returns:
an array with all the parameters unique identifiers whose data isn't null for this event.

getData

public IData[] getData(java.lang.String parameterUniqueID,
                       java.lang.String eventUniqueID,
                       int eventNumber)
Fetches a data structure from the SDAS server.

Specified by:
getData in interface ISDASProtocol
Parameters:
parameterUniqueID - the parameter unique identifier.
eventUniqueID - the event unique identifier.
eventNumber - the event number.
Returns:
the data structure returned by the server. If no data is returned from the server (for example a bad parameter uniqueID) an empty structure is returned.

getData

public IData[] getData(java.lang.String parameterUniqueID,
                       IHEvent event)
Fetches a data structure from the SDAS server.

Specified by:
getData in interface ISDASProtocol
Parameters:
parameterUniqueID - the parameter unique identifier.
event - the event for the desired data.
Returns:
the data structure returned by the server. If no data is returned from the server (for example a bad parameter uniqueID) an empty structure is returned.

getUserData

public IUserData getUserData(IData data)
Return data as a user data structure

Parameters:
data - the raw data as it is returned by SDAS
Returns:
A user data

getMultipleData

public IData[][] getMultipleData(java.lang.String[] parameterUniqueID,
                                 IHEvent event)
Fetches several data structures from the SDAS server.

Specified by:
getMultipleData in interface ISDASProtocol
Parameters:
parameterUniqueID - an array with all the parameters unique identifiers.
event - the event for the desired data.
Returns:
an array with all the data for the requested parameters. If data isn't available for any of the parameters an empty structure is added to the array.

getMultipleData

public IData[][] getMultipleData(java.lang.String[] parameterUniqueID,
                                 IHEvent[] event)
Fetches several data structures from the SDAS server.

Specified by:
getMultipleData in interface ISDASProtocol
Parameters:
parameterUniqueID - an array with all the parameters unique identifiers.
event - an array with an event for each selected parameter. If you wish to use the same event for all the parameters see getMultipleData(java.lang.String[], IHEvent). The size of this array should be the same of parameterUniqueID.
Returns:
an array with all the data for the requested parameters. If data isn't available for any of the parameters an empty structure is added to the array.

getMultipleData

public IData[][] getMultipleData(java.lang.String[] parameterUniqueID,
                                 java.lang.String eventUniqueID,
                                 int eventNumber)
Fetches several data structures from the SDAS server.

Specified by:
getMultipleData in interface ISDASProtocol
Parameters:
parameterUniqueID - an array with all the parameters unique identifier.
eventUniqueID - the event unique identifier.
eventNumber - the event number.
Returns:
an array with all the data for the requested parameters. If data isn't available for any of the parameters an empty structure is added to the array.

getMultipleData

public IData[][] getMultipleData(java.lang.String[] parameterUniqueID,
                                 java.lang.String[] eventUniqueID,
                                 int[] eventNumber)
Fetches several data structures from the SDAS server.

Specified by:
getMultipleData in interface ISDASProtocol
Parameters:
parameterUniqueID - an array with all the parameters unique identifiers.
eventUniqueID - an array with all the events unique identifiers. If you wish to use the same event for all the parameters see getMultipleData(java.lang.String[], java.lang.String, int). The size of this array should be the same of parameterUniqueID.
eventNumber - an array with all the events numbers. The size of this array should be the same of eventUniqueID.
Returns:
an array with all the data for the requested parameters. If data isn't available for any of the parameters an empty structure is added to the array.

getMultipleData

public IData[][] getMultipleData(java.lang.String parameterUniqueID,
                                 java.lang.String eventUniqueID,
                                 int[] eventNumber)
Fetches several data structures, all for the same parameter, from the SDAS server.

Specified by:
getMultipleData in interface ISDASProtocol
Parameters:
parameterUniqueID - the parameter unique identifier.
eventUniqueID - the event unique identifier.
eventNumber - all the events number.
Returns:
all the data structures for this parameter in the selected event for the different event numbers. If data isn't available for any of the event numbers an empty structure is added to the array.

getMultipleData

public IData[][] getMultipleData(java.lang.String parameterUniqueID,
                                 java.lang.String[] eventUniqueID,
                                 int[] eventNumber)
Fetches several data structures, all for the same parameter, from the SDAS server.

Specified by:
getMultipleData in interface ISDASProtocol
Parameters:
parameterUniqueID - the parameter unique identifier.
eventUniqueID - an array with all the events unique identifiers. If you wish to use the same event for all the event numbers see getMultipleData(java.lang.String, java.lang.String, int[]).
eventNumber - an array with all the events numbers. The size of this array should be the same of eventUniqueID.
Returns:
all the data structures for this parameter for the different events. If data isn't available for any of the events an empty structure is added to the array.

parameterExists

public boolean parameterExists(java.lang.String parameterUniqueID,
                               java.lang.String eventUniqueID,
                               int eventNumber)
Description copied from interface: ISDASProtocol
Checks if a parameter exists for a particular event.

Specified by:
parameterExists in interface ISDASProtocol
Parameters:
parameterUniqueID - the parameter unique identifier.
eventUniqueID - the event unique identifier.
eventNumber - the events number.
Returns:
true if the parameter exists, false otherwise.

getPluginFiles

public byte[][] getPluginFiles()
Returns all the plug-in files as byte arrays.

Specified by:
getPluginFiles in interface ISDASProtocol
Returns:
all the plug-in files.

putData

public boolean putData(IData data)
Stores this data on the server.

Specified by:
putData in interface ISDASProtocol
Parameters:
data - The data to be stored;
Returns:
true on success

logout

public void logout()

authenticate

public java.lang.String authenticate(java.lang.String[][] credentials)

reloadPlugins

public void reloadPlugins()
Reloads all the plugins


fetchPlugins

public void fetchPlugins()
Fetch the plug-ins from the server and saves them on the plug-in directory


deletePlugins

public void deletePlugins()
Delete all the plug-ins from the plug-in dir