public abstract class PersistorToFile extends AbstractRuntimeDataPersistor
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
filename
The name of file to hold the information of a Persistable object.
|
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.io.File |
persistFile
The file holds the information of a Persistable object.
|
protected java.io.Reader |
reader
The Reader object of the project file.
|
protected java.io.Writer |
writer
The Writer object of the test file.
|
runtime
Modifier | Constructor and Description |
---|---|
protected |
PersistorToFile(RuntimeDataInterface runtime,
java.lang.String filename) |
Modifier and Type | Method and Description |
---|---|
protected void |
beforeUnpickle() |
protected Persistable |
doUnpickle() |
boolean |
equals(java.lang.Object o)
If they have the same filename, then we consider them equivalent
|
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. |
PersistenceType |
getType()
The persistence Type.
|
protected boolean |
isIgnoredFiled(java.lang.String className,
java.lang.String field)
Check if the filed is being ignored at the moment for un-pickle.
|
void |
persist(Persistable persistable)
Persist a Persistable object.
|
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 file in the test/bench folder.
|
Persistable |
unpickle(java.util.Map<java.lang.String,java.util.List<java.lang.String>> ignoredFields)
Provided default implementation, simply throw out a SAFSException.
|
protected abstract 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.String filename
protected java.io.File persistFile
protected java.io.Writer writer
protected java.io.Reader reader
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> ignoredFieldsForUnpickle
#isIgnoredFiled(String)
protected PersistorToFile(RuntimeDataInterface runtime, java.lang.String filename)
public 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, java.io.IOException
write(Persistable)
.SAFSException
java.io.IOException
protected abstract void write(Persistable persistable) throws SAFSException, java.io.IOException
writeHeader(Persistable)
is called beforewriteTailer(Persistable)
is called afterSAFSException
java.io.IOException
protected void writeTailer(Persistable persistable) throws SAFSException, java.io.IOException
write(Persistable)
.SAFSException
java.io.IOException
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, java.io.IOException
SAFSException
java.io.IOException
protected Persistable doUnpickle() throws SAFSException, java.io.IOException
SAFSException
java.io.IOException
protected boolean isIgnoredFiled(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()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
Copyright © SAS Institute. All Rights Reserved.