Package ghidra.framework.options
Class GProperties
java.lang.Object
ghidra.framework.options.GProperties
- Direct Known Subclasses:
JSonProperties,XmlProperties
Class for saving name/value pairs as XML or Json. Classes that want to be
able to save their state can do so using the GProperies object.
The idea is that each state variable in the class
is first saved into a GProperties object via a String key. Then the GProperties
object is written out as XML or Json. When the GProperties object is
restored, the GProperties object is constructed with an XML Element or JsonObject
that contains all of the name/value pairs. There are convenience subclasses for reading
these from a file (XmlProperties and JsonProperties).
Since the "get" methods require a default value, the object that is recovering its
state variables will be successfully initialized even if
the given key,value pair is not found in the SaveState object.
Note: Names for property names are assumed to be unique. When a putXXX() method is called, if a value already exists for a name, it will be overwritten.
The GProperties supports the following types:
java primitives
arrays of java primitives
String
Color
Font
KeyStroke
File
Date
Enum
GProperties (values can be nested GProperties)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic DateFormatprotected static final Stringprotected static final String -
Constructor Summary
ConstructorsConstructorDescriptionGProperties(com.google.gson.JsonObject root) Construct a new GProperties object using the given JSonObject.GProperties(String name) Creates a new GProperties object with a non-default name.GProperties(org.jdom.Element root) Construct a new GProperties object using the given XML element. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all objects from this GPropertiesprotected org.jdom.ElementcreateElement(String key, Object value) protected org.jdom.ElementcreateElementFromElement(String internalKey, org.jdom.Element internalElement) protected <T> TbooleangetBoolean(String name, boolean defaultValue) Gets the boolean value for the given name.boolean[]getBooleans(String name, boolean[] defaultValue) Gets the boolean array for the given name.byteGets the byte value for the given name.byte[]Gets the byte array for the given name.Gets the Color value for the given name.Gets the Date value for the given name.doubleGets the double value for the given name.double[]getDoubles(String name, double[] defaultValue) Gets the double array for the given name.<T extends Enum<T>>
TGets the Enum value for the given name.Gets the File value for the given name.floatGets the float value for the given name.float[]Gets the float array for the given name.Gets the Font value for the given name.getGProperties(String name) intGets the int value for the given name.int[]Gets the int array for the given name.getKeyStroke(String name, KeyStroke defaultValue) Gets the KeyStroke value for the given name.longGets the long value for the given name.long[]Gets the long array for the given name.getName()Returns the name of this GPropertiesString[]getNames()Return the names of the properties in this GPropertiesshortGets the short value for the given name.short[]Gets the short array for the given name.Gets the String value for the given name.String[]getStrings(String name, String[] defaultValue) Gets the String array for the given name.org.jdom.ElementgetXmlElement(String name) Returns the root of an XML sub-tree associated with the given name.booleanReturns true if there is a value for the given namebooleanisEmpty()Returns true if this GProperties contains no elementsprotected voidprocessElement(org.jdom.Element elem) voidputBoolean(String name, boolean value) Associates a boolean value with the given name.voidputBooleans(String name, boolean[] value) Associates a boolean array with the given name.voidAssociates a byte value with the given name.voidAssociates a byte array with the given name.voidAssociates a Color value with the given name.voidAssociates a Date value with the given name.voidAssociates a double value with the given name.voidputDoubles(String name, double[] value) Associates a double value with the given name.voidAssociates an Enum with the given name.voidAssociates a File value with the given name.voidAssociates a float value with the given name.voidAssociates a float array with the given name.voidAssociates a Font value with the given name.voidputGProperties(String name, GProperties value) Associates a sub SaveState value with the given name.voidAssociates an integer value with the given name.voidAssociates an integer array with the given name.voidputKeyStroke(String name, KeyStroke value) Associates a KeyStroke value with the given name.voidAssociates a long value with the given name.voidAssociates a long array with the given name.voidAssociates a short value with the given name.voidAssociates a short array with the given name.voidAssociates a String value with the given name.voidputStrings(String name, String[] value) Associates a String array with the given name.voidputXmlElement(String name, org.jdom.Element element) Adds an XML element to the this GProperties.voidRemove the object identified by the given namecom.google.gson.JsonObjectSave this object to an JsonObjectvoidsaveToJsonFile(File file) Outputs this GProperties to a file using Jsonorg.jdom.ElementSave this object to an XML element.voidsaveToXmlFile(File file) Write the properties to a file as XMLintsize()Return the number of properties in this GPropertiestoString()
-
Field Details
-
TYPE
- See Also:
-
NAME
- See Also:
-
DATE_FORMAT
-
map
-
-
Constructor Details
-
GProperties
Creates a new GProperties object with a non-default name. The name serves no real purpose other than as a hint as to what the GProperties represents- Parameters:
name- of this GProperties object
-
GProperties
public GProperties(org.jdom.Element root) Construct a new GProperties object using the given XML element.- Parameters:
root- XML contents of GProperties
-
GProperties
public GProperties(com.google.gson.JsonObject root) Construct a new GProperties object using the given JSonObject.- Parameters:
root- JSonObject representing a GProperties
-
-
Method Details
-
processElement
protected void processElement(org.jdom.Element elem) -
saveToJsonFile
Outputs this GProperties to a file using JsonFor example, a GProperties that is created with:
ss = new GProperties("foo") ss.putString("Name", "Bob"); ss.putBoolean("Retired", true); ss.putInt("Age", 65); ss.putEnum("Endian", Endian.BIG); would produce a Json file with the following text { "GPROPERTIES NAME": "foo", "VALUES": { "Name": "Bob" "Retired": true, "Age": 65, "Endian": "BIG", }, "TYPES": { "Name": "String" "Retired": "boolean", "Age": "int", "Endian": "enum", }, "ENUM CLASSES": { "Endian": "ghidra.program.model.lang.Endian" } }- Parameters:
file- the file to save to- Throws:
IOException- if an error occurs writing to the given file
-
saveToXmlFile
Write the properties to a file as XML- Parameters:
file- the file to write to.- Throws:
IOException- if the file could not be written
-
saveToXml
public org.jdom.Element saveToXml()Save this object to an XML element.- Returns:
- Element XML element containing the properties
-
createElement
-
saveToJson
public com.google.gson.JsonObject saveToJson()Save this object to an JsonObject- Returns:
- JsonObject containing the properties
-
createElementFromElement
protected org.jdom.Element createElementFromElement(String internalKey, org.jdom.Element internalElement) -
isEmpty
public boolean isEmpty()Returns true if this GProperties contains no elements- Returns:
- true if there are no properties in this GProperties
-
remove
Remove the object identified by the given name- Parameters:
name- the name of the property to remove
-
clear
public void clear()Clear all objects from this GProperties -
size
public int size()Return the number of properties in this GProperties- Returns:
- The number of properties in this GProperties
-
getName
Returns the name of this GProperties- Returns:
- the name of this GProperties
-
getNames
Return the names of the properties in this GProperties- Returns:
- the names of the properties in this GProperties
-
putInt
Associates an integer value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putByte
Associates a byte value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putShort
Associates a short value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putLong
Associates a long value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putString
Associates a String value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putColor
Associates a Color value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putDate
Associates a Date value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putFile
Associates a File value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putKeyStroke
Associates a KeyStroke value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putFont
Associates a Font value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putBoolean
Associates a boolean value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putFloat
Associates a float value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putDouble
Associates a double value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putGProperties
Associates a sub SaveState value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
getInt
Gets the int value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the int value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getByte
Gets the byte value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the byte value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getShort
Gets the short value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the short value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getLong
Gets the long value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the long value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getBoolean
Gets the boolean value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the boolean value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getString
Gets the String value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the String value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getColor
Gets the Color value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the Color value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getDate
Gets the Date value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the Date value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getFile
Gets the File value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the File value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getKeyStroke
Gets the KeyStroke value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the KeyStroke value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getFont
Gets the Font value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the Font value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getFloat
Gets the float value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the float value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getDouble
Gets the double value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the double value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
putInts
Associates an integer array with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putBytes
Associates a byte array with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putShorts
Associates a short array with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putLongs
Associates a long array with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putStrings
Associates a String array with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putEnum
Associates an Enum with the given name.- Parameters:
name- The name in the name,value pair.value- The Enum value in the name,value pair.
-
putBooleans
Associates a boolean array with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putFloats
Associates a float array with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
putDoubles
Associates a double value with the given name.- Parameters:
name- The name in the name,value pair.value- The value in the name,value pair.
-
getInts
Gets the int array for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the int array associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getBytes
Gets the byte array for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the byte array associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getShorts
Gets the short array for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the short array associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getLongs
Gets the long array for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the long array associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getBooleans
Gets the boolean array for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the boolean array associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getStrings
Gets the String array for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the String array associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getEnum
Gets the Enum value for the given name.- Parameters:
name- the name of the pair.defaultValue- the default Enum value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the Enum value associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getFloats
Gets the float array for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the float array associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
getDoubles
Gets the double array for the given name.- Parameters:
name- the name of the pair.defaultValue- the default value to be returned if the name does not exist in the map, or it does not contain the proper object type.- Returns:
- the double array associated with the given name or the defaultValue passed in if the name doesn't exist or is the wrong type.
-
hasValue
Returns true if there is a value for the given name- Parameters:
name- true the name of the property to check for a value- Returns:
- true if this GProperties has a value for the given name
-
putXmlElement
Adds an XML element to the this GProperties. Used by plugins that have more complicated state information that needs to be saved.- Parameters:
name- the name to associate with the elementelement- XML element which is the root of an XML sub-tree.
-
getXmlElement
Returns the root of an XML sub-tree associated with the given name.- Parameters:
name- The name associated with the desired Element.- Returns:
- The root of an XML sub-tree associated with the given name.
-
getGProperties
-
toString
-
getAsType
-