250 lines
11 KiB
Java
250 lines
11 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* javax.baja.data.BIDataValue
|
|
* javax.baja.io.ValueDocDecoder
|
|
* javax.baja.naming.BOrd
|
|
* javax.baja.nre.util.TextUtil
|
|
* javax.baja.security.PermissionException
|
|
* javax.baja.sys.BComplex
|
|
* javax.baja.sys.BComponent
|
|
* javax.baja.sys.BFacets
|
|
* javax.baja.sys.BObject
|
|
* javax.baja.sys.BValue
|
|
* javax.baja.sys.Context
|
|
* javax.baja.sys.Flags
|
|
* javax.baja.sys.Property
|
|
* javax.baja.sys.Slot
|
|
* javax.baja.sys.Sys
|
|
* javax.baja.user.BUser
|
|
* javax.baja.util.BTypeSpec
|
|
*/
|
|
package com.tridium.program;
|
|
|
|
import com.tridium.program.Robot;
|
|
import java.util.ArrayList;
|
|
import javax.baja.data.BIDataValue;
|
|
import javax.baja.io.ValueDocDecoder;
|
|
import javax.baja.naming.BOrd;
|
|
import javax.baja.nre.util.TextUtil;
|
|
import javax.baja.security.PermissionException;
|
|
import javax.baja.sys.BComplex;
|
|
import javax.baja.sys.BComponent;
|
|
import javax.baja.sys.BFacets;
|
|
import javax.baja.sys.BObject;
|
|
import javax.baja.sys.BValue;
|
|
import javax.baja.sys.Context;
|
|
import javax.baja.sys.Flags;
|
|
import javax.baja.sys.Property;
|
|
import javax.baja.sys.Slot;
|
|
import javax.baja.sys.Sys;
|
|
import javax.baja.user.BUser;
|
|
import javax.baja.util.BTypeSpec;
|
|
|
|
public class BatchRobot
|
|
extends Robot {
|
|
public void run() throws Exception {
|
|
}
|
|
|
|
public void componentRename(BOrd bOrd, String string, String string2, boolean bl, boolean bl2) {
|
|
BComponent bComponent = bOrd.get((BObject)Sys.getStation()).asComponent();
|
|
BComponent bComponent2 = (BComponent)bComponent.getParent();
|
|
if (bl2) {
|
|
if (bl) {
|
|
if (bComponent.getName().equals(string)) {
|
|
bComponent2.rename(bComponent.getPropertyInParent(), string2, this.context);
|
|
}
|
|
} else if (bComponent.getName().equalsIgnoreCase(string)) {
|
|
bComponent2.rename(bComponent.getPropertyInParent(), string2, this.context);
|
|
}
|
|
} else if (bl && bComponent.getName().indexOf(string) != -1) {
|
|
int n = bComponent.getName().indexOf(string);
|
|
String string3 = bComponent.getName().substring(0, n) + string2 + bComponent.getName().substring(n + string.length());
|
|
bComponent2.rename(bComponent.getPropertyInParent(), string3, this.context);
|
|
this.log.println("[RENAME] " + bOrd + " -> " + string3);
|
|
} else if (!bl && bComponent.getName().toUpperCase().indexOf(string.toUpperCase()) != -1) {
|
|
int n = bComponent.getName().toUpperCase().indexOf(string.toUpperCase());
|
|
String string4 = bComponent.getName().substring(0, n) + string2 + bComponent.getName().substring(n + string.length());
|
|
bComponent2.rename(bComponent.getPropertyInParent(), string4, this.context);
|
|
this.log.println("[RENAME] " + bOrd + " -> " + string4);
|
|
}
|
|
}
|
|
|
|
public void add(BOrd bOrd, String string, String string2, String string3, boolean bl) throws Exception {
|
|
BValue bValue = (BValue)BTypeSpec.make((String)string2).getInstance();
|
|
bValue = ValueDocDecoder.unmarshal((String)string3);
|
|
BComponent bComponent = bOrd.get((BObject)Sys.getStation()).asComponent();
|
|
if (bComponent.getProperty(string) != null && bl) {
|
|
if (Flags.isReadonly((BComplex)bComponent, (Slot)bComponent.getProperty(string))) {
|
|
this.log.println("[SET] Skipping readonly slot: " + bOrd + '.' + string);
|
|
return;
|
|
}
|
|
if (bComponent.get(string).getType() != bValue.getType()) {
|
|
return;
|
|
}
|
|
if (bValue instanceof BFacets) {
|
|
bValue = this.mergeFacets((BFacets)bComponent.get(string), (BFacets)bValue);
|
|
}
|
|
bComponent.set(string, bValue);
|
|
this.log.println("[SET] " + bOrd + '.' + string + " -> " + string3);
|
|
} else if (bComponent.getProperty(string) == null) {
|
|
bComponent.add(string, bValue, this.context);
|
|
this.log.println("[ADD] " + bOrd + '.' + string + " -> " + bValue);
|
|
}
|
|
}
|
|
|
|
public void set(BOrd bOrd, String string, String string2, String string3, boolean bl, boolean bl2) throws Exception {
|
|
BValue bValue = (BValue)BTypeSpec.make((String)string2).getInstance();
|
|
bValue = ValueDocDecoder.unmarshal((String)string3);
|
|
String[] stringArray = TextUtil.split((String)string, (char)'.');
|
|
BComponent bComponent = bOrd.get((BObject)Sys.getStation()).asComponent();
|
|
Property property = null;
|
|
int n = stringArray.length;
|
|
int n2 = 0;
|
|
while (n2 < n - 1) {
|
|
property = bComponent.getProperty(stringArray[n2]);
|
|
if ((bComponent = (BComplex)bComponent.get(property)) == null) {
|
|
this.log.println("[SET][ERROR] " + bOrd + '.' + string + " does not exist!");
|
|
return;
|
|
}
|
|
++n2;
|
|
}
|
|
Property[] propertyArray = this.findProperties((BComplex)bComponent, stringArray[n - 1], bl, bl2);
|
|
int n3 = 0;
|
|
while (n3 < propertyArray.length) {
|
|
block10: {
|
|
if (bComponent instanceof BUser) {
|
|
try {
|
|
BUser bUser = (BUser)bComponent;
|
|
bUser.checkWrite((BComponent)bUser, (Slot)propertyArray[n3]);
|
|
}
|
|
catch (PermissionException permissionException) {
|
|
this.log.println("[SET] Insufficient permissions to change slot: " + bOrd + '.' + propertyArray[n3].getName());
|
|
break block10;
|
|
}
|
|
}
|
|
if (Flags.isReadonly((BComplex)bComponent, (Slot)propertyArray[n3])) {
|
|
this.log.println("[SET] Skipping readonly slot: " + bOrd + '.' + propertyArray[n3].getName());
|
|
} else if (bValue.getType() == bComponent.get(propertyArray[n3]).getType()) {
|
|
if (bValue instanceof BFacets) {
|
|
bValue = this.mergeFacets((BFacets)bComponent.get(propertyArray[n3]), (BFacets)bValue);
|
|
}
|
|
bComponent.set(propertyArray[n3], bValue, this.context);
|
|
this.log.println("[SET] " + bOrd + '.' + propertyArray[n3].getName() + " -> " + bValue);
|
|
}
|
|
}
|
|
++n3;
|
|
}
|
|
}
|
|
|
|
public void setFlag(BOrd bOrd, String string, int n, boolean bl, boolean bl2) throws Exception {
|
|
BComponent bComponent = bOrd.get((BObject)Sys.getStation()).asComponent();
|
|
if (bl) {
|
|
BComplex bComplex = bComponent.getParent();
|
|
Property property = bComponent.getPropertyInParent();
|
|
if (bComplex != null && property != null) {
|
|
int n2;
|
|
int n3 = n2 = bComplex.getFlags((Slot)property);
|
|
n3 = bl2 ? n2 | n : n2 & ~n;
|
|
bComplex.setFlags((Slot)property, n3, this.context);
|
|
this.log.println("[SET FLAGS] " + bOrd + ' ' + Flags.toDisplayString((int)n2, (Context)this.context) + " -> " + Flags.toDisplayString((int)n3, (Context)this.context));
|
|
} else {
|
|
this.log.println("[SET FLAGS][ERROR] " + bOrd + " cannot have slot flags edited!");
|
|
}
|
|
} else {
|
|
Slot slot = bComponent.getSlot(string);
|
|
if (slot != null) {
|
|
int n4;
|
|
int n5 = n4 = bComponent.getFlags(slot);
|
|
n5 = bl2 ? n4 | n : n4 & ~n;
|
|
bComponent.setFlags(slot, n5, this.context);
|
|
this.log.println("[SET FLAGS] " + bOrd + '.' + string + ' ' + Flags.toDisplayString((int)n4, (Context)this.context) + " -> " + Flags.toDisplayString((int)n5, (Context)this.context));
|
|
} else {
|
|
this.log.println("[SET FLAGS][ERROR] " + bOrd + '.' + string + " cannot have slot flags edited!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void rename(BOrd bOrd, String string, String string2, boolean bl, boolean bl2) {
|
|
BComponent bComponent = bOrd.get((BObject)Sys.getStation()).asComponent();
|
|
Property[] propertyArray = this.findProperties((BComplex)bComponent, string, bl, bl2);
|
|
String string3 = "";
|
|
String string4 = "";
|
|
int n = 0;
|
|
while (n < propertyArray.length) {
|
|
string3 = propertyArray[n].getName();
|
|
if (propertyArray[n].isFrozen()) {
|
|
this.log.println("[RENAME] Skipping frozen slot: " + string3);
|
|
} else if (Flags.isReadonly((BComplex)bComponent, (Slot)propertyArray[n])) {
|
|
this.log.println("[RENAME] Skipping readonly slot: " + bOrd + '.' + propertyArray[n].getName());
|
|
} else {
|
|
if (bl2) {
|
|
string4 = string2;
|
|
} else {
|
|
int n2 = bl ? string3.indexOf(string) : string3.toUpperCase().indexOf(string.toUpperCase());
|
|
string4 = string3.substring(0, n2) + string2 + string3.substring(n2 + string.length());
|
|
}
|
|
bComponent.rename(propertyArray[n], string4, this.context);
|
|
this.log.println("[RENAME] " + bOrd + '.' + string3 + " -> " + string4);
|
|
}
|
|
++n;
|
|
}
|
|
}
|
|
|
|
public void remove(BOrd bOrd, String string, boolean bl, boolean bl2) {
|
|
BComponent bComponent = bOrd.get((BObject)Sys.getStation()).asComponent();
|
|
Property[] propertyArray = this.findProperties((BComplex)bComponent, string, bl, bl2);
|
|
int n = 0;
|
|
while (n < propertyArray.length) {
|
|
if (Flags.isReadonly((BComplex)bComponent, (Slot)propertyArray[n])) {
|
|
this.log.println("[REMOVE] Skipping readonly slot: " + bOrd + '.' + propertyArray[n].getName());
|
|
} else {
|
|
bComponent.remove(propertyArray[n], this.context);
|
|
this.log.println("[REMOVE] " + bOrd + '.' + propertyArray[n].getName() + " -> Removed");
|
|
}
|
|
++n;
|
|
}
|
|
}
|
|
|
|
public Property[] findProperties(BComplex bComplex, String string, boolean bl, boolean bl2) {
|
|
ArrayList<Property> arrayList = new ArrayList<Property>();
|
|
Property[] propertyArray = bComplex.getPropertiesArray();
|
|
int n = 0;
|
|
while (n < propertyArray.length) {
|
|
if (bl2) {
|
|
if (bl) {
|
|
if (propertyArray[n].getName().equals(string)) {
|
|
arrayList.add(propertyArray[n]);
|
|
}
|
|
} else if (propertyArray[n].getName().equalsIgnoreCase(string)) {
|
|
arrayList.add(propertyArray[n]);
|
|
}
|
|
} else if (bl) {
|
|
if (propertyArray[n].getName().indexOf(string) != -1) {
|
|
arrayList.add(propertyArray[n]);
|
|
}
|
|
} else if (propertyArray[n].getName().toUpperCase().indexOf(string.toUpperCase()) != -1) {
|
|
arrayList.add(propertyArray[n]);
|
|
}
|
|
++n;
|
|
}
|
|
return arrayList.toArray(new Property[arrayList.size()]);
|
|
}
|
|
|
|
public BFacets mergeFacets(BFacets bFacets, BFacets bFacets2) {
|
|
String[] stringArray = bFacets2.list();
|
|
int n = 0;
|
|
while (n < stringArray.length) {
|
|
String string = stringArray[n];
|
|
if (bFacets.get(string) != null) {
|
|
bFacets = BFacets.makeRemove((BFacets)bFacets, (String)string);
|
|
}
|
|
bFacets = BFacets.make((BFacets)bFacets, (String)string, (BIDataValue)((BIDataValue)bFacets2.get(string)));
|
|
++n;
|
|
}
|
|
return bFacets;
|
|
}
|
|
}
|
|
|