LEONARDI Application Composer - 8.9.0.40 by W4 S.A.

leon.peer.file
Class LyFileRequestEncoder

java.lang.Object
  extended by leon.peer.LyRequestEncoder
      extended by leon.peer.file.LyFileRequestEncoder
Direct Known Subclasses:
LyXmlRequestEncoder

public class LyFileRequestEncoder
extends LyRequestEncoder

This class is used for local files as data provider. Methods for creation, deletion and modification are not overriden since they don't have to write anything in the corresponding files. The specific method saveObjects must be called in order to make the objects persistent in a file.

See Also:
LyRequestEncoder

Field Summary
static java.lang.String __VERSION
           
 LyEnvironment _environment
          Current environment if any, otherwise use dataprovider environment.
 java.lang.String _fieldSep
          Separator used between fields.
 java.lang.String _valueSep
          Separator used between values.
static java.lang.String EMPTY_CHARSET
          Empty char set.
static int EXPORT_ENCODING
          Value for export encoding (used in encodeValue).
static int RAW_ENCODING
          Value for raw encoding (used in encodeValue).
static int SPREADSHEET_ENCODING
          Value for spreadsheet encoding (used in encodeValue).
static int TEXT_ENCODING
          Value for text encoding (used in encodeValue).
static int XML_EXPORT_ENCODING
          Value for xml encoding (used in encodeValue).
 
Constructor Summary
LyFileRequestEncoder(LyDataProvider provider, LyDataSource dataSource, java.lang.String fieldSep, java.lang.String valueSep)
          Constructor.
 
Method Summary
 java.lang.String asciiEncode(java.lang.String str)
          Encode String in a quoted printable like manner Avoid conflicts in file.
 boolean createObject(java.lang.Object object)
          To create a new object.
 java.util.Vector<LyField> decodeHeader(java.lang.String line)
          Read a line and return a set of FieldInfos.
 LyValueSet decodeValue(java.lang.String line, java.util.Vector<LyField> fields, int l, boolean spreadSheetDecoding)
          Read a line and return a set of values.
 java.util.Vector<java.lang.Object> decodeValues(java.util.Vector<java.lang.String> lines, java.util.Vector<LyField> fields)
          Read a set of lines and return a set of objects.
 java.util.Vector<java.lang.Object> decodeValues(java.util.Vector<java.lang.String> lines, java.util.Vector<LyField> fields, boolean checkObject)
          Read a set of lines and return a set of objects.
 boolean deleteObject(java.lang.Object object)
          To delete an object.
 java.lang.String encodeHeader(java.util.Vector<?> fields, int type)
          Return a line describing the FieldInfos.
 java.lang.String encodeValue(java.lang.Object object, java.util.Vector<?> fields, int type)
          Return a line describing the ValueSet.
 java.util.Vector<java.lang.String> encodeValues(java.util.Vector<java.lang.Object> objects, java.util.Vector<LyField> fields, int type)
          Read a set of lines and return a set of objects.
 java.lang.Object fromString(LyField field, java.lang.String str)
           
 java.lang.Object fromString(LyField field, java.lang.String str, boolean spreadSheetDecoding)
           
 LyEnvironment getEnvironment()
          Utility method to get current environment.
 java.lang.String getFieldSeparator()
          Gets the fields separator.
 boolean getObject(LyObjectId objectId, java.util.Vector<LyField> fields)
          Get an object.
 boolean getObjects(java.util.Vector<LyField> fields, LySort sort, LyFilter filter, int n)
          Get a set of objects.
 boolean getSize()
          Return the number of objects from the file.
 boolean getSize(LyFilter filter)
          Return the number of objects from the file .
 java.lang.String getValueSeparator()
          Gets the values separator.
 void init()
          Initialisation of the data of the instance.
 java.util.Vector<java.lang.String> readFromConnection()
          Sends a request to the file connection for reading data.
 boolean saveObjects(java.util.Vector<java.lang.Object> objects, java.util.Vector<LyField> fields, int type)
          Method used to saved all the objects contained in the corresponding data source cache.
 void setEnvironment(LyEnvironment env)
          Utility method to set current environment.
 void setHeaderMark(java.lang.String headerMark)
          Sets the header mark.
 boolean setObject(java.lang.Object object)
          To set an object.
 boolean setObjects(java.util.Vector<java.lang.Object> objects)
          To set a set of objects.
 void setResponse(LyResponse response)
          Set the request encoder response.
 boolean writeToConnection(java.util.Vector<java.lang.Object> objects, java.util.Vector<LyField> fields, int type)
          Sends a request to the file connection for writing data.
 boolean writeToConnection(java.util.Vector<java.lang.String> lines)
          Sends a request to the file connection for writing data.
 
Methods inherited from class leon.peer.LyRequestEncoder
deleteObjects, getClassBinding, getDataClass, getProvider, getResponse, isSynchronous, loadObject, setClassBinding, setDataClass, toString, toString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__VERSION

public static final java.lang.String __VERSION
See Also:
Constant Field Values

RAW_ENCODING

public static final int RAW_ENCODING
Value for raw encoding (used in encodeValue).

See Also:
Constant Field Values

TEXT_ENCODING

public static final int TEXT_ENCODING
Value for text encoding (used in encodeValue).

See Also:
Constant Field Values

SPREADSHEET_ENCODING

public static final int SPREADSHEET_ENCODING
Value for spreadsheet encoding (used in encodeValue).

See Also:
Constant Field Values

EXPORT_ENCODING

public static final int EXPORT_ENCODING
Value for export encoding (used in encodeValue).

See Also:
Constant Field Values

XML_EXPORT_ENCODING

public static final int XML_EXPORT_ENCODING
Value for xml encoding (used in encodeValue).

See Also:
Constant Field Values

EMPTY_CHARSET

public static final java.lang.String EMPTY_CHARSET
Empty char set.

See Also:
Constant Field Values

_fieldSep

public java.lang.String _fieldSep
Separator used between fields.


_valueSep

public java.lang.String _valueSep
Separator used between values.


_environment

public LyEnvironment _environment
Current environment if any, otherwise use dataprovider environment.

Constructor Detail

LyFileRequestEncoder

public LyFileRequestEncoder(LyDataProvider provider,
                            LyDataSource dataSource,
                            java.lang.String fieldSep,
                            java.lang.String valueSep)
Constructor.

Parameters:
classInfo - ClassInfo used by the request encoder.
fieldSep - separator used between fields.
valuedSep - separator used between values.
Method Detail

setHeaderMark

public void setHeaderMark(java.lang.String headerMark)
Sets the header mark.

Parameters:
headerMark - new header mark.

getFieldSeparator

public java.lang.String getFieldSeparator()
Gets the fields separator.

Returns:
the fields separator.

getValueSeparator

public java.lang.String getValueSeparator()
Gets the values separator.

Returns:
the values separator.

init

public void init()
Initialisation of the data of the instance.


setResponse

public void setResponse(LyResponse response)
Set the request encoder response. Inherited method from LyRequestEncoder to set properties to the response.

Overrides:
setResponse in class LyRequestEncoder
Parameters:
the - response

getObject

public boolean getObject(LyObjectId objectId,
                         java.util.Vector<LyField> fields)
Get an object.

Specified by:
getObject in class LyRequestEncoder
Parameters:
objectId - object identifier
fields - the fields to load (if null, load all)
Returns:
true if the request was correctly sent to the external data provider.

getObjects

public boolean getObjects(java.util.Vector<LyField> fields,
                          LySort sort,
                          LyFilter filter,
                          int n)
Get a set of objects.

Specified by:
getObjects in class LyRequestEncoder
Parameters:
fields - the fields to load (if null, load all)
sort - indicates sorting criterion, or null if default sort is used.
filter - indicates filtering criterion, or null if there is no filter.
n - maximum number of objects to get.
Returns:
true if the request was correctly sent to the external data provider.

getSize

public boolean getSize()
Return the number of objects from the file.

Returns:
true if the request was correctly sent to the external data provider.

getSize

public boolean getSize(LyFilter filter)
Return the number of objects from the file .

Specified by:
getSize in class LyRequestEncoder
Parameters:
filter - indicates filtering criterion, or null if there is no filter.
Returns:
true if the request was correctly sent to the external data provider.

createObject

public boolean createObject(java.lang.Object object)
To create a new object.

Specified by:
createObject in class LyRequestEncoder
Parameters:
object - the new object to create
Returns:
true if the request was correctly sent to the external data provider.

setObject

public boolean setObject(java.lang.Object object)
To set an object.

Specified by:
setObject in class LyRequestEncoder
Parameters:
object - the object to set
Returns:
true if the request was correctly sent to the external data provider.

setObjects

public boolean setObjects(java.util.Vector<java.lang.Object> objects)
To set a set of objects.

Overrides:
setObjects in class LyRequestEncoder
Parameters:
objects - the objects to set
Returns:
true if the request was correctly sent to the external data provider.

deleteObject

public boolean deleteObject(java.lang.Object object)
To delete an object.

Specified by:
deleteObject in class LyRequestEncoder
Parameters:
object - the object to delete
Returns:
true if the request was correctly sent to the external data provider.

saveObjects

public boolean saveObjects(java.util.Vector<java.lang.Object> objects,
                           java.util.Vector<LyField> fields,
                           int type)
Method used to saved all the objects contained in the corresponding data source cache.

Parameters:
fields - fields to save (if null save all).
type - indicates the file format
Returns:
true if the request was correctly sent to the external data provider.

readFromConnection

public java.util.Vector<java.lang.String> readFromConnection()
Sends a request to the file connection for reading data.

Returns:
lines read from the file.

writeToConnection

public boolean writeToConnection(java.util.Vector<java.lang.String> lines)
Sends a request to the file connection for writing data.

Parameters:
lines - lines to write on the file.
Returns:
lines read from the file.

writeToConnection

public boolean writeToConnection(java.util.Vector<java.lang.Object> objects,
                                 java.util.Vector<LyField> fields,
                                 int type)
Sends a request to the file connection for writing data.

Parameters:
objects - the set of objects to encode.
fields - FieldInfos to save (if null save all).
type - indicates the file format.
Returns:
lines read from the file.

decodeValues

public java.util.Vector<java.lang.Object> decodeValues(java.util.Vector<java.lang.String> lines,
                                                       java.util.Vector<LyField> fields)
Read a set of lines and return a set of objects.

Parameters:
lines - lines to read.
fields - the fields to load (if null, load all)
Returns:
the objects read from the lines.

decodeValues

public java.util.Vector<java.lang.Object> decodeValues(java.util.Vector<java.lang.String> lines,
                                                       java.util.Vector<LyField> fields,
                                                       boolean checkObject)
Read a set of lines and return a set of objects.

Parameters:
lines - lines to read.
fields - the fields to load (if null, load all)
checkObject - indicates if we must check if object is already in data source
Returns:
the objects read from the lines.

decodeHeader

public java.util.Vector<LyField> decodeHeader(java.lang.String line)
Read a line and return a set of FieldInfos. The line must contain the attributes names separed by a specific separator.

Parameters:
line - line to read.
Returns:
the set of FieldInfos read from the lines.

decodeValue

public LyValueSet decodeValue(java.lang.String line,
                              java.util.Vector<LyField> fields,
                              int l,
                              boolean spreadSheetDecoding)
Read a line and return a set of values.

Parameters:
line - line to read.
fields - the list of FieldInfos.
l - position of line in the file.
spreadSheetDecoding - indicates if spreadsheet decoding mode is set
Returns:
the set of values read from the lines.

fromString

public java.lang.Object fromString(LyField field,
                                   java.lang.String str)

fromString

public java.lang.Object fromString(LyField field,
                                   java.lang.String str,
                                   boolean spreadSheetDecoding)

encodeValues

public java.util.Vector<java.lang.String> encodeValues(java.util.Vector<java.lang.Object> objects,
                                                       java.util.Vector<LyField> fields,
                                                       int type)
Read a set of lines and return a set of objects.

Parameters:
objects - the set of objects to encode.
fields - FieldInfos to save (if null save all).
type - indicates the file format.
Returns:
the set of lines describing the set of objects.

encodeHeader

public java.lang.String encodeHeader(java.util.Vector<?> fields,
                                     int type)
Return a line describing the FieldInfos.

Parameters:
fields - the FieldInfos to encode.
type - indicates the file format.
Returns:
a String describing the FieldInfos.

encodeValue

public java.lang.String encodeValue(java.lang.Object object,
                                    java.util.Vector<?> fields,
                                    int type)
Return a line describing the ValueSet.

Parameters:
values - the ValueSet to encode.
fields - the FieldInfos to encode.
type - indicates the file format.
Returns:
the line describing the ValueSet.

asciiEncode

public java.lang.String asciiEncode(java.lang.String str)
Encode String in a quoted printable like manner Avoid conflicts in file.


getEnvironment

public LyEnvironment getEnvironment()
Utility method to get current environment.

Returns:
Current environment.

setEnvironment

public void setEnvironment(LyEnvironment env)
Utility method to set current environment.

Parameters:
env - Current environment.

(c) January 2013 - W4 S.A.

Website: W4 S.A., contact us: support@w4global.com