public abstract class AbstractPluginOptions extends Object implements Cloneable, IQuimpSerialize
The principal idea is to have separate class that would hold all parameters plugin uses. Such
class, if derived from AbstractPluginOptions
allows to produce self-representation as
JSon that can be displayed in macro recorder as plugin parameters string. Reverse operation -
creating instance of option class from JSon string is also supported.
Additional features provided by this template are removing quotes from JSon string and
allowing parameters that contain spaces. In the first case such de-quoted string can be easily
passed as a parameter string in macro (which is also string) without the need of escaping quotes.
De-quoted strings can be also deserialzied. Second feature allows using EscapedPath
annotation for fields of String type which then are automatically enclosed in specified escape
character. This allows to use white spaces in these fields.
Use beforeSerialize()
and afterSerialize()
to prepare object before
converting to options string and after converting it back.
Methods serialize2Macro()
and
deserialize2Macro(String, AbstractPluginOptions)
are intended for creating parameter
strings, which can be then displayed in Macro Recorder, and creating instance of Option object
from such strings (specified by user in macro). Remaining two other methods:
serialize()
and deserialize(String, AbstractPluginOptions)
stand for normal
conversion to and from JSon (both take under account EscapedPath
annotation).
This abstract class by default provides paramFile
field that
holds path to the configuration file.
There are following restriction to parameter string and concrete options class:
serialize()
makes shallow copy of
object otherwise. Implement your own clone if you use arrays or collections.
See also com.github.celldynamics.quimp.plugin.AbstractPluginOptionsTest
Modifier and Type | Field and Description |
---|---|
static String |
KEY
Default key used to denote options string in IJ macro recorder.
|
static org.slf4j.Logger |
LOGGER
The Constant logger.
|
static int |
MAXITER
Maximal length of parameter string.
|
String |
paramFile
Name and path of QCONF file.
|
Constructor and Description |
---|
AbstractPluginOptions() |
Modifier and Type | Method and Description |
---|---|
void |
afterSerialize()
This method is called after restoring object from JSON but before returning the object.
|
void |
beforeSerialize()
This method is called just before JSON is generated.
|
static <T extends AbstractPluginOptions> |
deserialize(String json,
T t)
Create AbstractPluginOptions reference from JSon.
|
static <T extends AbstractPluginOptions> |
deserialize2Macro(String json,
T t)
Deserialize JSon produced by
serialize2Macro() , that is json without quotations. |
String |
escapeJsonMacro(String json)
Remove quotes and white characters from JSon file.
|
static String |
removeSpacesMacro(String param)
Remove white characters from string except those enclosed in ().
|
String |
serialize()
Create JSon string from this object.
|
String |
serialize2Macro()
Serialize this class and produce JSon without spaces (except escaped strings) and without
quotes.
|
static String |
unescapeJsonMacro(String json)
Reverse
escapeJsonMacro(String) . |
public static final transient org.slf4j.Logger LOGGER
public static final transient String KEY
public static final transient int MAXITER
@EscapedPath public String paramFile
public String serialize()
Fields annotated by EscapedPath
will be enclosed by escape characters. If
EscapedPath
is applied to non string data type, it is ignored.
This method return regular JSon (but with escaped Strings if annotation is set).
Complementary method serialize2Macro()
return JSon file without quotes supposed to be
used as parameter string in macro.
EscapedPath
,
serialize2Macro()
public String serialize2Macro()
Return is intended to show in macro recorder. Note that IJ require key to assign a parameter string to it. Recommended way of use this method is:
Recorder.setCommand("Generate mask");
Recorder.recordOption(AbstractPluginOptions.KEY, opts.serialize2Macro());
EscapedPath
,
escapeJsonMacro(String)
,
serialize()
,
deserialize2Macro(String, AbstractPluginOptions)
public static <T extends AbstractPluginOptions> T deserialize(String json, T t)
This method return object from regular JSon. All fields annotated with EscapedPath
will have escaping characters removed. Complementary method
deserialize2Macro(String, AbstractPluginOptions)
accept JSon file without quotes
and it is supposed to be used as processor of parameter string specified in macro.
json
- JSon string produced by serialize()
t
- type of restored objectEscapedPath
,
deserialize2Macro(String, AbstractPluginOptions)
public static <T extends AbstractPluginOptions> T deserialize2Macro(String json, T t) throws QuimpPluginException
serialize2Macro()
, that is json without quotations.
This method accepts that input string can contain a key specified by "opts". See
serialize2Macro()
.
json
- JSon to deserializet
- type of objectEscapedPath
does not contain
escape characters.QuimpPluginException
- on deserialization error. As JSon will be produced by user in
macro script this usually will be problem with escaping or forming proper JSon.public String escapeJsonMacro(String json)
Note that none of value can contain quote. Spaces in Strings for fields annotated by
EscapedPath
are preserved.
json
- file to be processedpublic static String removeSpacesMacro(String param)
String can not start with (. Integrity (number of opening and closing brackets) is not checked.
TODO This should accept chars set in EscapedPath
. (defined in class annotation)
param
- string to processpublic static String unescapeJsonMacro(String json)
escapeJsonMacro(String)
. Add removed quotes. Do not verify integrity of
produced JSon.json
- JSon returned by escapeJsonMacro(String)
public void beforeSerialize()
IQuimpSerialize
beforeSerialize
in interface IQuimpSerialize
Serializer.save(String)
public void afterSerialize() throws Exception
IQuimpSerialize
afterSerialize
in interface IQuimpSerialize
Exception
- from wrapped object in any problem. This is implementation dependentSerializer.load(String)
Copyright © 2002–2019 Department of Computer Science, Warwick University. All rights reserved.