jcolibri.connector
Class PlainTextConnector

java.lang.Object
  extended by jcolibri.connector.PlainTextConnector
All Implemented Interfaces:
Connector

public class PlainTextConnector
extends java.lang.Object
implements Connector

Implements a generic PlainText Connector.

It manages the persistence of the cases automatically into textual files. Features:

This connector uses the property in the initFromXMLfile() parameter to obtain the configuration file. This file is a xml that follows the Schema defined in /doc/configfilesSchemas/PlainTextConnector.xsd:

This class does not implement any cache mechanims, so cases are read and written directly. This can be very inefficient in some operations (mainly in reading)

Some methods will fail when executing the connector with a case base file inside a jar file. The retrieve() methods will work properly but the methods that write in the file will fail. Extract the file to the file system and run the connector with that location to solve these problems.

For an example see Test6.

Version:
2.0
Author:
Juan Antonio Recio García
See Also:
PlainTextTypeConverter, TypeAdaptor, Test6

Field Summary
protected  java.lang.String PROP_DELIM
           
protected  java.lang.String PROP_FILEPATH
           
 
Constructor Summary
PlainTextConnector()
           
 
Method Summary
 void close()
          Cleanup any resource that the connector might be using, and suspends the service
 void deleteCases(java.util.Collection<CBRCase> cases)
          Deletes cases from the case base.
 void initFromXMLfile(java.net.URL file)
          Initialices the connector with the given XML file
 java.util.Collection<CBRCase> retrieveAllCases()
          Retrieves all cases from the text file.
 java.util.Collection<CBRCase> retrieveSomeCases(CaseBaseFilter filter)
          Retrieves some cases depending on the filter.
 void storeCases(java.util.Collection<CBRCase> cases)
          Stores the cases in the data base.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_FILEPATH

protected java.lang.String PROP_FILEPATH

PROP_DELIM

protected java.lang.String PROP_DELIM
Constructor Detail

PlainTextConnector

public PlainTextConnector()
Method Detail

initFromXMLfile

public void initFromXMLfile(java.net.URL file)
                     throws InitializingException
Description copied from interface: Connector
Initialices the connector with the given XML file

Specified by:
initFromXMLfile in interface Connector
Parameters:
file - XMl file with the settings
Throws:
InitializingException - Raised if the connector can not be initialezed.

close

public void close()
Description copied from interface: Connector
Cleanup any resource that the connector might be using, and suspends the service

Specified by:
close in interface Connector

storeCases

public void storeCases(java.util.Collection<CBRCase> cases)
Stores the cases in the data base. Note that this method does not control that the case name (== primary key) is repeated, so developers must be careful with this.

Specified by:
storeCases in interface Connector
Parameters:
cases - Cases to store.
Throws:
UnImplementedException

deleteCases

public void deleteCases(java.util.Collection<CBRCase> cases)
Deletes cases from the case base. It only uses the case name (primary key) to remove the row. Note that this method is very inefficient because it reads all the database, removes the rows in memory, and writes it again into the text file.

Specified by:
deleteCases in interface Connector
Parameters:
cases - Cases to delete

retrieveAllCases

public java.util.Collection<CBRCase> retrieveAllCases()
Retrieves all cases from the text file. It maps data types using the PlainTextTypeConverter class.

Specified by:
retrieveAllCases in interface Connector
Returns:
Retrieved cases.

retrieveSomeCases

public java.util.Collection<CBRCase> retrieveSomeCases(CaseBaseFilter filter)
Description copied from interface: Connector
Retrieves some cases depending on the filter. TODO.

Specified by:
retrieveSomeCases in interface Connector

GAIA - Group for Artificial Intelligence Applications
http://gaia.fdi.ucm.es