public abstract class PersistorToString extends AbstractPersistor
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
ignoredFieldsForUnpickle
Holding the fields which are ignored for each class.
|
protected java.lang.StringBuilder |
stringFormat
The string format of a Persistable object.
|
protected java.io.Reader |
stringFormatReader
The Reader containing string format of a Persistable object.
|
Constructor and Description |
---|
PersistorToString() |
PersistorToString(java.io.Reader stringFormatReader) |
PersistorToString(java.lang.String stringFormat) |
Modifier and Type | Method and Description |
---|---|
protected void |
beforeUnpickle()
Prepare the parser with the string format of a Persistable object.
|
protected Persistable |
doUnpickle()
Convert the string format of a Persistable object to Persistable object.
|
protected java.lang.String |
escape(java.lang.String value)
When writing a string to a file, some special characters MUST be escaped, such as
new line "\n", "\r", "\r\n", or double quote ", or <?XML>...</XML> etc.
What characters to escape and how to escape, these depend on the format of the persistence file, and the parser of the file. |
java.lang.String |
getPersistenceName()
The name of the persistence material holding the content of an Object.
It can be a file name or a variable name etc. It could be useful when deleting the persistence. |
java.lang.String |
getStringFormat() |
java.io.Reader |
getStringFormatReader() |
PersistenceType |
getType()
The persistence Type.
|
protected boolean |
isIgnoredField(java.lang.String className,
java.lang.String field)
Check if the field is being ignored at the moment for un-pickle.
|
protected abstract java.lang.String |
parse(Persistable persistable,
boolean needLeadingNameForContainer)
Convert a Persistable Object to a string.
|
void |
persist(Persistable persistable)
Persist a Persistable object.
|
void |
setStringFormat(java.lang.String stringFormat) |
void |
setStringFormatReader(java.io.Reader stringFormatReader) |
protected boolean |
stringNeedQuoted()
If the string value needs to be quoted before writing into a kind of persistence.
JSON file requires that for string value. In JSON file, For example: "key" : "stringValue" is good "key" : stringValue is bad |
void |
unpersist()
Try to delete a persistence StringBuffer.
|
Persistable |
unpickle(java.util.Map<java.lang.String,java.util.List<java.lang.String>> ignoredFields)
Provided default implementation, simply throw out a SAFSException.
|
protected void |
write(Persistable persistable)
Write the Persistable object into a persistent material.
writeHeader(Persistable) is called beforewriteTailer(Persistable) is called after |
protected void |
writeHeader(Persistable persistable)
This is called before
write(Persistable) . |
protected void |
writeTailer(Persistable persistable)
This is called after
write(Persistable) . |
validate
protected java.lang.StringBuilder stringFormat
protected java.io.Reader stringFormatReader
stringFormat
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> ignoredFieldsForUnpickle
#isIgnoredFiled(String)
public PersistorToString()
public PersistorToString(java.lang.String stringFormat)
public PersistorToString(java.io.Reader stringFormatReader)
public java.lang.String getStringFormat()
public void setStringFormat(java.lang.String stringFormat)
stringFormat
- the stringFormat of a Persistable object.public java.io.Reader getStringFormatReader()
public void setStringFormatReader(java.io.Reader stringFormatReader)
stringFormatReader
- the stringFormatReader to setpublic void persist(Persistable persistable) throws SAFSException
Persistor
persist
in interface Persistor
persist
in class AbstractPersistor
persistable
- Persistable, the object to persistSAFSException
- when persistence fails or something wrong happens.protected void writeHeader(Persistable persistable) throws SAFSException
write(Persistable)
.SAFSException
protected final void write(Persistable persistable) throws SAFSException
writeHeader(Persistable)
is called beforewriteTailer(Persistable)
is called afterSAFSException
protected void writeTailer(Persistable persistable) throws SAFSException
write(Persistable)
.SAFSException
protected boolean stringNeedQuoted()
protected java.lang.String escape(java.lang.String value)
stringNeedQuoted()
returns true.value
- String, the value to escape.stringNeedQuoted()
public void unpersist() throws SAFSException
unpersist
in interface Persistor
unpersist
in class AbstractPersistor
SAFSException
- when failing to delete the persistence or something wrong happens.public Persistable unpickle(java.util.Map<java.lang.String,java.util.List<java.lang.String>> ignoredFields) throws SAFSException
AbstractPersistor
unpickle
in interface Persistor
unpickle
in class AbstractPersistor
ignoredFields
- Map<String, List<String>>, a Map containing the fields of each class to be ignored when un-pickling.SAFSException
protected void beforeUnpickle() throws SAFSException
SAFSException
protected Persistable doUnpickle() throws SAFSException
SAFSException
protected abstract java.lang.String parse(Persistable persistable, boolean needLeadingNameForContainer) throws SAFSException
persistable
- needLeadingNameForContainer
- SAFSException
protected boolean isIgnoredField(java.lang.String className, java.lang.String field)
className
- String, the className to checkfield
- String, the field to checkignoredFieldsForUnpickle
public PersistenceType getType()
Persistor
public java.lang.String getPersistenceName()
Persistor
Persistor.unpersist()
Copyright © SAS Institute. All Rights Reserved.