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 StringKEY_CLASSthe key for the class name.static StringKEY_OPTIONSthe key for the options.protected booleanm_OutputFullwhether 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 voidaddArray(AbstractArgumentOption option, String key, Object values)Adds the array.protected voidaddArray(String key, Object[] values)Adds the array.protected voidaddArray(net.minidev.json.JSONObject obj, String key, Object[] values)Adds the array.protected voidaddPair(String key, Object value)Adds the named key/value pair.StringgetDefaultFormatExtension()Returns the default file extension (without the dot).StringgetFormatDescription()Returns the description of the file format.String[]getFormatExtensions()Returns the file extensions (without the dot).booleangetOutputFull()Returns whether to output all values or just ones that differ from the default ones.StringglobalInfo()Returns a string describing the object.protected voidinitialize()Initializes the members.protected net.minidev.json.JSONObjectinitOutput()Initializes the output data structure.static voidmain(String[] args)Executes the producer from commandline.protected net.minidev.json.JSONObjectnewObject(Object obj)Creates a new JSON object.protected voidpreProduce()Hook-method before starting visiting options.ObjectprocessOption(AbstractArgumentOption option)Visits an argument option.ObjectprocessOption(BooleanOption option)Visits a boolean option.ObjectprocessOption(ClassOption option)Visits a class option.voidsetOutputFull(boolean value)Sets whether to output all values or just ones that differ from the default ones.StringtoString()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:
globalInfoin interfaceOptionProducer<net.minidev.json.JSONObject,Object>- Specified by:
globalInfoin classAbstractOptionProducer<net.minidev.json.JSONObject,Object>- Returns:
- a description suitable for displaying in the gui
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein 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:
initOutputin 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:
processOptionin interfaceOptionProducer<net.minidev.json.JSONObject,Object>- Specified by:
processOptionin 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:
processOptionin interfaceOptionProducer<net.minidev.json.JSONObject,Object>- Specified by:
processOptionin 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:
processOptionin interfaceOptionProducer<net.minidev.json.JSONObject,Object>- Specified by:
processOptionin 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:
toStringin interfaceOptionProducer<net.minidev.json.JSONObject,Object>- Specified by:
toStringin 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:
preProducein classAbstractOptionProducer<net.minidev.json.JSONObject,Object>- See Also:
AbstractOptionProducer.initOutput()
-
getFormatDescription
public String getFormatDescription()
Returns the description of the file format.- Specified by:
getFormatDescriptionin interfaceFileFormatHandler- Returns:
- the description
-
getDefaultFormatExtension
public String getDefaultFormatExtension()
Returns the default file extension (without the dot).- Specified by:
getDefaultFormatExtensionin interfaceFileFormatHandler- Returns:
- the default extension
-
getFormatExtensions
public String[] getFormatExtensions()
Returns the file extensions (without the dot).- Specified by:
getFormatExtensionsin 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
-
-