User Tools

Site Tools


usingahashmapinavalueobject

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
usingahashmapinavalueobject [2026/01/25 20:04] – wikiadminusingahashmapinavalueobject [2026/01/25 21:07] (current) – [Setting up the ValueObject "MAP" Property] wikiadmin
Line 5: Line 5:
 Some beans have mapTriggers (i.e., TriggeredHistorical) which requires a ValueObject input with a MAP property). There is a TriggeredHistorical example here: [[usingdatabaseserverbeansinscripting|Scripting for Database Servers (in MIStudio and TransSECS)]] which needs a LinkedHashMap. Some beans have mapTriggers (i.e., TriggeredHistorical) which requires a ValueObject input with a MAP property). There is a TriggeredHistorical example here: [[usingdatabaseserverbeansinscripting|Scripting for Database Servers (in MIStudio and TransSECS)]] which needs a LinkedHashMap.
  
-===== Setting up the ValueObject "MAP" Property =====+==== Setting up the ValueObject "MAP" Property ====
  
 ValueObjects can have user defined "properties" attached to them by using the .setProperty() method on the ValueObject. For this article we will use a property called "MAP" which is a Java HashMap object. A LinkedHashMap is required by some ErgoTech beans as can be seen in the JavaDocs, but for this example we only need the regular HashMap. ValueObjects can have user defined "properties" attached to them by using the .setProperty() method on the ValueObject. For this article we will use a property called "MAP" which is a Java HashMap object. A LinkedHashMap is required by some ErgoTech beans as can be seen in the JavaDocs, but for this example we only need the regular HashMap.
Line 15: Line 15:
 </code> </code>
  
-For each ValueObject type you will also need to declare these definitions (for this example we will use a LongValueObject and a StringValueObject)+For this example we will create one ValueObject (a LongValueObject) and add a HashMap to it which will contain the values we want to pass to our script.
  
 +<code javascript>
 +LongValueObject = Java.type("com.ergotech.vib.valueobjects.LongValueObject");
 +</code>
  
 +<code javascript>
  
 +//fill a HashMap with our key,value pairs
  
 +map = new HashMap();
 +map.put("age",50);
 +map.put("name","Joe Doe");
 +map.put("color",java.awt.Color.green); //you can put Objects into the HashMap
  
 +//add the "map" to a ValueObject so we can pass this to the script
 +
 +vo = new LongValueObject(100); //the value can be used by the script, or ignored
 +
 +vo.setProperty("MAP",map); //this is all you need to do before you send the value to the script
 +
 +//send it to the script
 +
 +/Devices/UtilityServers_Servers/CalculateSomething->setValueObject(vo); //must use setValueObject so the MAP property is not striped (not, for example, setLongValue())
 +
 +</code>
 +
 +==== Using the MAP property in your Script ====
 +
 +An example of a script which extracts the MAP property and gets the various values based on the key
 +
 +<code javascript>
 +
 +if (incomingValue.getQuality()==0) {
 +
 + //following from the above example, incomingValue is a LongValueObject with a property called "MAP" which contains a HashMap of key/value pairs
 +
 +vo = incomingValue;
 +map = incomingValue.getProperty("MAP");
 +
 +//you can test what class map is as a sanity check
 +print("The MAP property is a "+map.getClass().getName()); //works as long as map is not null
 +
 +value1 = map.get("name");
 +value2 = map.get("age");
 +color = map.get("color"); //this is an awt Color object
 +//test color, get the r,g,b values
 +print("color is:" + "r:"+color.getRed()+" g:"+color.getGreen()+" b:"+color.getBlue());
 +
 +//you can use the values passed in the MAP property in your script....
 +
 +}
 +incomingValue;
 +
 +
 +</code>
  
usingahashmapinavalueobject.1769389473.txt.gz · Last modified: by wikiadmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki