The core & mysterious part of my library is this:
Line#69-107:
/**
* "GVEntity" means "an entity of the GlobalVariable object" for short.
*
* insert a public static property with "name" of type java.lang.Object
* into the internal.GlobalVarialbe runtime.
*
* e.g, GVH.addGVEntity('my_new_variable', 'foo') makes
* 1) internal.GlobalVariable.my_new_variable to be present and to have value 'foo'
* 2) internal.GlobalVariable.getMy_new_variale() to return 'foo'
* 3) internal.GlobalVariable.setMy_new_variable('bar') to set 'bar' as the value
*
* @param name
* @param value
*/
int addGVEntity(String name, Object value) {
// check if the "name" is declared as a property of internal.GlobalVariable object statically or not
if (staticGVEntitiesKeySet().contains(name)) {
// Yes, the internal.GlobalVariable object has "name" already.
// No need to add the name. Just update the value
GlobalVariable[name] = value
return 0
} else {
// No, the "name" is not present. Let's add a new property using Groovy's ExpandoMetaClass
// the characters in the name must be valid as a Groovy variable name
validateGVEntityName(name)
// obtain the ExpandoMetaClass of the internal.GlobalVariable class
MetaClass mc = GlobalVariable.metaClass
// register the Getter method for the name
String getterName = getGetterName(name)
mc.'static'."${getterName}" = { -> return additionalGVEntities[name] }
// register the Setter method for the name
String setterName = getSetterName(name)
mc.'static'."${setterName}" = { newValue ->
additionalGVEntities[name] = newValue
}
// store the value into the storage
additionalGVEntities.put(name, value)
return 1
}
}