Package adams.core.option
Class JsonProducer
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.option.AbstractOptionProducer<O,I>
-
- adams.core.option.AbstractRecursiveOptionProducer<net.minidev.json.JSONObject,Object>
-
- adams.core.option.JsonProducer
-
- All Implemented Interfaces:
CleanUpHandler
,FileFormatHandler
,LoggingSupporter
,OptionProducer<net.minidev.json.JSONObject,Object>
,RecursiveOptionProducer
,SizeOfHandler
,Serializable
public class JsonProducer extends AbstractRecursiveOptionProducer<net.minidev.json.JSONObject,Object> implements FileFormatHandler
Generates the JSON format.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
KEY_CLASS
the key for the class name.static String
KEY_OPTIONS
the key for the options.protected boolean
m_OutputFull
whether to output all values, not just ones that differ from the default values.-
Fields inherited from class adams.core.option.AbstractRecursiveOptionProducer
m_Nesting
-
Fields inherited from class adams.core.option.AbstractOptionProducer
m_Input, m_LastGenerated, m_Output, m_OutputVariableValues, m_SkippedProperties, m_UsePropertyNames
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description JsonProducer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addArray(AbstractArgumentOption option, String key, Object values)
Adds the array.protected void
addArray(String key, Object[] values)
Adds the array.protected void
addArray(net.minidev.json.JSONObject obj, String key, Object[] values)
Adds the array.protected void
addPair(String key, Object value)
Adds the named key/value pair.String
getDefaultFormatExtension()
Returns the default file extension (without the dot).String
getFormatDescription()
Returns the description of the file format.String[]
getFormatExtensions()
Returns the file extensions (without the dot).boolean
getOutputFull()
Returns whether to output all values or just ones that differ from the default ones.String
globalInfo()
Returns a string describing the object.protected void
initialize()
Initializes the members.protected net.minidev.json.JSONObject
initOutput()
Initializes the output data structure.static void
main(String[] args)
Executes the producer from commandline.protected net.minidev.json.JSONObject
newObject(Object obj)
Creates a new JSON object.protected void
preProduce()
Hook-method before starting visiting options.Object
processOption(AbstractArgumentOption option)
Visits an argument option.Object
processOption(BooleanOption option)
Visits a boolean option.Object
processOption(ClassOption option)
Visits a class option.void
setOutputFull(boolean value)
Sets whether to output all values or just ones that differ from the default ones.String
toString()
Returns the output generated from the visit.-
Methods inherited from class adams.core.option.AbstractRecursiveOptionProducer
cleanUp, generateLoggingString, getDebugIndentation, getDebugIndentation, getRecursionLevel, reset
-
Methods inherited from class adams.core.option.AbstractOptionProducer
checkInput, doProduce, doProduce, getCurrentValue, getInput, getOptionIdentifier, getOutput, getOutputVariableValues, getSkippedProperties, getUsePropertyNames, isDefaultValue, loggingLevelTipText, outputVariableValuesTipText, postProduce, postProduce, preProduce, produce, produce, runProducer, setLoggingLevel, setOutputVariableValues, setSkippedProperties, toString, write
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.option.OptionProducer
getLoggingLevel
-
-
-
-
Field Detail
-
KEY_CLASS
public static final String KEY_CLASS
the key for the class name.- See Also:
- Constant Field Values
-
KEY_OPTIONS
public static final String KEY_OPTIONS
the key for the options.- See Also:
- Constant Field Values
-
m_OutputFull
protected boolean m_OutputFull
whether to output all values, not just ones that differ from the default values.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceOptionProducer<net.minidev.json.JSONObject,Object>
- Specified by:
globalInfo
in classAbstractOptionProducer<net.minidev.json.JSONObject,Object>
- Returns:
- a description suitable for displaying in the gui
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractOptionProducer<net.minidev.json.JSONObject,Object>
-
setOutputFull
public void setOutputFull(boolean value)
Sets whether to output all values or just ones that differ from the default ones.- Parameters:
value
- true if all values are to be output
-
getOutputFull
public boolean getOutputFull()
Returns whether to output all values or just ones that differ from the default ones.- Returns:
- true if all values are to be output
-
initOutput
protected net.minidev.json.JSONObject initOutput()
Initializes the output data structure.- Specified by:
initOutput
in classAbstractOptionProducer<net.minidev.json.JSONObject,Object>
- Returns:
- the created data structure
-
addArray
protected void addArray(net.minidev.json.JSONObject obj, String key, Object[] values)
Adds the array.- Parameters:
key
- the identifier for the arrayvalues
- the values of the array
-
addArray
protected void addArray(String key, Object[] values)
Adds the array.- Parameters:
key
- the identifier for the arrayvalues
- the values of the array
-
addArray
protected void addArray(AbstractArgumentOption option, String key, Object values)
Adds the array.- Parameters:
option
- the associated optionkey
- the identifier for the arrayvalues
- the values of the array
-
addPair
protected void addPair(String key, Object value)
Adds the named key/value pair.- Parameters:
key
- the identifier for the valuevalue
- the value
-
newObject
protected net.minidev.json.JSONObject newObject(Object obj)
Creates a new JSON object.- Parameters:
obj
- the object to add to a JSONObject structure- Returns:
- the JSON object
-
processOption
public Object processOption(BooleanOption option)
Visits a boolean option.- Specified by:
processOption
in interfaceOptionProducer<net.minidev.json.JSONObject,Object>
- Specified by:
processOption
in classAbstractOptionProducer<net.minidev.json.JSONObject,Object>
- Parameters:
option
- the boolean option- Returns:
- always null
-
processOption
public Object processOption(ClassOption option)
Visits a class option.- Specified by:
processOption
in interfaceOptionProducer<net.minidev.json.JSONObject,Object>
- Specified by:
processOption
in classAbstractOptionProducer<net.minidev.json.JSONObject,Object>
- Parameters:
option
- the class option- Returns:
- always null
-
processOption
public Object processOption(AbstractArgumentOption option)
Visits an argument option.- Specified by:
processOption
in interfaceOptionProducer<net.minidev.json.JSONObject,Object>
- Specified by:
processOption
in classAbstractOptionProducer<net.minidev.json.JSONObject,Object>
- Parameters:
option
- the argument option- Returns:
- always null
-
toString
public String toString()
Returns the output generated from the visit.- Specified by:
toString
in interfaceOptionProducer<net.minidev.json.JSONObject,Object>
- Specified by:
toString
in classAbstractOptionProducer<net.minidev.json.JSONObject,Object>
- Returns:
- the output, null in case of an error
-
preProduce
protected void preProduce()
Hook-method before starting visiting options.- Overrides:
preProduce
in classAbstractOptionProducer<net.minidev.json.JSONObject,Object>
- See Also:
AbstractOptionProducer.initOutput()
-
getFormatDescription
public String getFormatDescription()
Returns the description of the file format.- Specified by:
getFormatDescription
in interfaceFileFormatHandler
- Returns:
- the description
-
getDefaultFormatExtension
public String getDefaultFormatExtension()
Returns the default file extension (without the dot).- Specified by:
getDefaultFormatExtension
in interfaceFileFormatHandler
- Returns:
- the default extension
-
getFormatExtensions
public String[] getFormatExtensions()
Returns the file extensions (without the dot).- Specified by:
getFormatExtensions
in interfaceFileFormatHandler
- Returns:
- the extensions
-
main
public static void main(String[] args)
Executes the producer from commandline.- Parameters:
args
- the commandline arguments, use -help for help
-
-