548 lines
22 KiB
Java
548 lines
22 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* javax.baja.nre.util.TextUtil
|
|
*/
|
|
package com.tridium.sys.schema;
|
|
|
|
import com.tridium.asm.Buffer;
|
|
import com.tridium.sys.module.AutoClassLoader;
|
|
import com.tridium.sys.schema.Compiler;
|
|
import com.tridium.sys.schema.ComplexSlotMap;
|
|
import com.tridium.sys.schema.ComplexType;
|
|
import com.tridium.sys.schema.Introspector;
|
|
import com.tridium.sys.schema.MethodMap;
|
|
import com.tridium.sys.schema.NAction;
|
|
import com.tridium.sys.schema.NProperty;
|
|
import com.tridium.sys.schema.NSlot;
|
|
import com.tridium.sys.schema.NTopic;
|
|
import com.tridium.sys.schema.Utils;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Method;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import javax.baja.nre.util.TextUtil;
|
|
import javax.baja.sys.BDouble;
|
|
import javax.baja.sys.BFloat;
|
|
import javax.baja.sys.BInteger;
|
|
import javax.baja.sys.BLong;
|
|
import javax.baja.sys.Slot;
|
|
import javax.baja.sys.Type;
|
|
|
|
/*
|
|
* Illegal identifiers - consider using --renameillegalidents true
|
|
*/
|
|
public class ComplexIntrospector
|
|
extends Introspector {
|
|
MethodMap methods;
|
|
NSlot[] slots;
|
|
NProperty[] properties;
|
|
NAction[] actions;
|
|
NTopic[] topics;
|
|
ComplexSlotMap slotMap;
|
|
boolean isComponent;
|
|
HashMap superSlotsToFix;
|
|
static /* synthetic */ Class class$javax$baja$sys$BComponent;
|
|
static /* synthetic */ Class class$javax$baja$sys$BObject;
|
|
static /* synthetic */ Class class$javax$baja$sys$BBoolean;
|
|
static /* synthetic */ Class class$javax$baja$sys$BInteger;
|
|
static /* synthetic */ Class class$javax$baja$sys$BLong;
|
|
static /* synthetic */ Class class$javax$baja$sys$BFloat;
|
|
static /* synthetic */ Class class$javax$baja$sys$BDouble;
|
|
static /* synthetic */ Class class$javax$baja$sys$BString;
|
|
static /* synthetic */ Class class$javax$baja$sys$BValue;
|
|
static /* synthetic */ Class class$javax$baja$sys$Context;
|
|
|
|
Type introspect() throws Exception {
|
|
this.mapSlots();
|
|
this.generateSlotMapClass();
|
|
return this.makeType();
|
|
}
|
|
|
|
protected Type makeType() {
|
|
return new ComplexType(this);
|
|
}
|
|
|
|
protected void mapSlots() throws Exception {
|
|
ArrayList<NProperty> arrayList = new ArrayList<NProperty>();
|
|
ArrayList<NProperty> arrayList2 = new ArrayList<NProperty>();
|
|
ArrayList<NProperty> arrayList3 = new ArrayList<NProperty>();
|
|
ArrayList<NProperty> arrayList4 = new ArrayList<NProperty>();
|
|
Field[] fieldArray = this.resolveFields();
|
|
int n = 0;
|
|
while (n < fieldArray.length) {
|
|
Field field = fieldArray[n];
|
|
if (field != null) {
|
|
Class<?> clazz = field.getType();
|
|
NSlot nSlot = null;
|
|
try {
|
|
NSlot nSlot2;
|
|
if (clazz == propertyClass) {
|
|
nSlot2 = this.mapProperty((NProperty)this.getSlotField(field));
|
|
arrayList2.add((NProperty)nSlot2);
|
|
nSlot = nSlot2;
|
|
} else if (clazz == actionClass) {
|
|
nSlot2 = this.mapAction((NAction)this.getSlotField(field));
|
|
arrayList3.add((NProperty)nSlot2);
|
|
nSlot = nSlot2;
|
|
} else if (clazz == topicClass) {
|
|
nSlot2 = this.mapTopic((NTopic)this.getSlotField(field));
|
|
arrayList4.add((NProperty)nSlot2);
|
|
nSlot = nSlot2;
|
|
}
|
|
}
|
|
catch (Exception exception) {
|
|
this.err("" + field);
|
|
throw exception;
|
|
}
|
|
if (nSlot != null) {
|
|
nSlot.index = arrayList.size();
|
|
arrayList.add((NProperty)nSlot);
|
|
}
|
|
}
|
|
++n;
|
|
}
|
|
this.slots = arrayList.toArray(new NSlot[arrayList.size()]);
|
|
this.properties = arrayList2.toArray(new NProperty[arrayList2.size()]);
|
|
this.actions = arrayList3.toArray(new NAction[arrayList3.size()]);
|
|
this.topics = arrayList4.toArray(new NTopic[arrayList4.size()]);
|
|
if (this.superSlotsToFix != null) {
|
|
this.fixSuperSlots();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Unable to fully structure code
|
|
*/
|
|
protected Field[] resolveFields() {
|
|
var1_1 = new ArrayList<Class>();
|
|
var2_2 = this.cls;
|
|
if (true) ** GOTO lbl8
|
|
do {
|
|
var1_1.add((Class)var2_2);
|
|
var2_2 = var2_2.getSuperclass();
|
|
lbl8:
|
|
// 2 sources
|
|
|
|
if ((v0 = ComplexIntrospector.class$javax$baja$sys$BObject) != null) continue;
|
|
v0 = ComplexIntrospector.class("[Ljavax.baja.sys.BObject;", false);
|
|
} while (var2_2 != v0 && var2_2 != null);
|
|
var2_2 = new ArrayList<E>();
|
|
var3_3 = new HashMap<String, Integer>();
|
|
var4_4 = var1_1.size() - 1;
|
|
while (var4_4 >= 0) {
|
|
var5_5 = ((Class)var1_1.get(var4_4)).getDeclaredFields();
|
|
var6_6 = 0;
|
|
while (var6_6 < var5_5.length) {
|
|
var7_7 = var5_5[var6_6];
|
|
var8_8 = var7_7.getType();
|
|
if (this.isPublicStaticFinal(var7_7) && (var8_8 == ComplexIntrospector.propertyClass || var8_8 == ComplexIntrospector.actionClass || var8_8 == ComplexIntrospector.topicClass)) {
|
|
var9_9 = (Integer)var3_3.get(var7_7.getName());
|
|
if (var9_9 != null) {
|
|
var10_10 = var9_9;
|
|
this.checkSuperSlotInitialized((Field)var2_2.get(var10_10));
|
|
var2_2.set(var10_10, var7_7);
|
|
} else {
|
|
var3_3.put(var7_7.getName(), new Integer(var2_2.size()));
|
|
var2_2.add(var7_7);
|
|
}
|
|
}
|
|
++var6_6;
|
|
}
|
|
--var4_4;
|
|
}
|
|
return var2_2.toArray(new Field[var2_2.size()]);
|
|
}
|
|
|
|
protected Slot getSlotField(Field field) throws Exception {
|
|
NSlot nSlot = null;
|
|
try {
|
|
nSlot = (NSlot)field.get(null);
|
|
}
|
|
catch (Exception exception) {
|
|
throw this.err("Cannot access slot field \"" + field + "\": " + exception);
|
|
}
|
|
if (nSlot == null) {
|
|
throw this.err("Slot field is null (insure loadType is last)", field.getName());
|
|
}
|
|
nSlot.name = field.getName();
|
|
nSlot.displayName = TextUtil.toFriendly((String)nSlot.name);
|
|
return nSlot;
|
|
}
|
|
|
|
protected NProperty mapProperty(NProperty nProperty) {
|
|
String string = nProperty.name;
|
|
String string2 = TextUtil.capitalize((String)string);
|
|
Method method = this.methods.getMethod("get" + string2, MethodMap.noParams);
|
|
if (method == null && (method = this.methods.getMethod("is" + string2, MethodMap.noParams)) != null && method.getReturnType() != Boolean.TYPE) {
|
|
throw this.err("Only boolean properties may support 'is' getter", string);
|
|
}
|
|
if (method == null) {
|
|
throw this.err("No getter for property", string);
|
|
}
|
|
if (method.getParameterTypes().length != 0) {
|
|
throw this.err("Parameters not allowed on getter", string);
|
|
}
|
|
TypeSpec typeSpec = new TypeSpec(method.getReturnType());
|
|
if (typeSpec.isError()) {
|
|
throw this.err("Unsupported type for property", string);
|
|
}
|
|
if (!this.isComponent && typeSpec.isPotentialComponent()) {
|
|
throw this.err("Structs may not contain potential component types", string);
|
|
}
|
|
if (typeSpec.isBWrapper()) {
|
|
throw this.err("Use primitive, not BObject wrapper for " + string);
|
|
}
|
|
Method method2 = this.methods.getMethod("set" + string2, typeSpec.cls);
|
|
if (method2 == null) {
|
|
throw this.err("No setter for property", string);
|
|
}
|
|
if (method2.getReturnType() != Void.TYPE) {
|
|
throw this.err("Setter must have void return type", string);
|
|
}
|
|
nProperty.typeClass = typeSpec.cls;
|
|
nProperty.typeAccess = typeSpec.typeAccess;
|
|
Class clazz = null;
|
|
switch (nProperty.typeAccess) {
|
|
case 0: {
|
|
Class clazz2 = class$javax$baja$sys$BBoolean;
|
|
if (clazz2 == null) {
|
|
clazz2 = class$javax$baja$sys$BBoolean = ComplexIntrospector.class("[Ljavax.baja.sys.BBoolean;", false);
|
|
}
|
|
clazz = clazz2;
|
|
break;
|
|
}
|
|
case 2: {
|
|
Class clazz3 = class$javax$baja$sys$BInteger;
|
|
if (clazz3 == null) {
|
|
clazz3 = class$javax$baja$sys$BInteger = ComplexIntrospector.class("[Ljavax.baja.sys.BInteger;", false);
|
|
}
|
|
clazz = clazz3;
|
|
break;
|
|
}
|
|
case 3: {
|
|
Class clazz4 = class$javax$baja$sys$BLong;
|
|
if (clazz4 == null) {
|
|
clazz4 = clazz = (class$javax$baja$sys$BLong = ComplexIntrospector.class("[Ljavax.baja.sys.BLong;", false));
|
|
}
|
|
if (!(nProperty.value instanceof BInteger)) break;
|
|
nProperty.value = BLong.make(((BInteger)nProperty.value).getInt());
|
|
break;
|
|
}
|
|
case 4: {
|
|
Class clazz5 = class$javax$baja$sys$BFloat;
|
|
if (clazz5 == null) {
|
|
clazz5 = clazz = (class$javax$baja$sys$BFloat = ComplexIntrospector.class("[Ljavax.baja.sys.BFloat;", false));
|
|
}
|
|
if (!(nProperty.value instanceof BInteger)) break;
|
|
nProperty.value = BFloat.make(((BInteger)nProperty.value).getInt());
|
|
break;
|
|
}
|
|
case 5: {
|
|
Class clazz6 = class$javax$baja$sys$BDouble;
|
|
if (clazz6 == null) {
|
|
clazz6 = clazz = (class$javax$baja$sys$BDouble = ComplexIntrospector.class("[Ljavax.baja.sys.BDouble;", false));
|
|
}
|
|
if (!(nProperty.value instanceof BInteger)) break;
|
|
nProperty.value = BDouble.make(((BInteger)nProperty.value).getInt());
|
|
break;
|
|
}
|
|
case 6: {
|
|
Class clazz7 = class$javax$baja$sys$BString;
|
|
if (clazz7 == null) {
|
|
clazz7 = class$javax$baja$sys$BString = ComplexIntrospector.class("[Ljavax.baja.sys.BString;", false);
|
|
}
|
|
clazz = clazz7;
|
|
break;
|
|
}
|
|
case 7: {
|
|
clazz = nProperty.typeClass;
|
|
break;
|
|
}
|
|
default: {
|
|
throw new IllegalStateException();
|
|
}
|
|
}
|
|
Class<?> clazz8 = nProperty.value.getClass();
|
|
if (!clazz.isAssignableFrom(clazz8)) {
|
|
throw this.err("Property default value is of wrong type " + clazz8.getName() + " != " + clazz.getName(), string);
|
|
}
|
|
nProperty.init();
|
|
return nProperty;
|
|
}
|
|
|
|
protected NTopic mapTopic(NTopic nTopic) throws Exception {
|
|
String string = nTopic.name;
|
|
String string2 = TextUtil.capitalize((String)string);
|
|
Method method = this.methods.getMethod("fire" + string2, MethodMap.wildcard);
|
|
if (method == null) {
|
|
throw this.err("Missing fire method: fire" + string2, string);
|
|
}
|
|
if (method.getReturnType() != Void.TYPE) {
|
|
throw this.err("Fire method must have void return type", string);
|
|
}
|
|
Class<?>[] classArray = method.getParameterTypes();
|
|
if (classArray.length != 1) {
|
|
throw this.err("Fire method must have exactly one parameter", string);
|
|
}
|
|
nTopic.eventClass = classArray[0];
|
|
return nTopic;
|
|
}
|
|
|
|
protected NAction mapAction(NAction nAction) throws Exception {
|
|
Method method;
|
|
String string = nAction.name;
|
|
String string2 = TextUtil.capitalize((String)string);
|
|
Method method2 = this.methods.getMethod(string, MethodMap.noParams);
|
|
if (method2 == null) {
|
|
method2 = this.methods.getMethod(string, MethodMap.wildcard);
|
|
}
|
|
if (method2 == null) {
|
|
throw this.err("Missing action method", string);
|
|
}
|
|
if (!this.isPublic(method2)) {
|
|
throw this.err("Action method must be public", string);
|
|
}
|
|
if (this.isStatic(method2)) {
|
|
throw this.err("Action method must be not be static", string);
|
|
}
|
|
Class<?> clazz = method2.getReturnType();
|
|
if (clazz == Void.TYPE) {
|
|
nAction.returnClass = null;
|
|
} else {
|
|
Class clazz2 = class$javax$baja$sys$BValue;
|
|
if (clazz2 == null) {
|
|
clazz2 = class$javax$baja$sys$BValue = ComplexIntrospector.class("[Ljavax.baja.sys.BValue;", false);
|
|
}
|
|
if (!clazz2.isAssignableFrom(clazz)) {
|
|
throw this.err("Action return type must be BValue", string);
|
|
}
|
|
nAction.returnClass = clazz;
|
|
}
|
|
Class<?>[] classArray = method2.getParameterTypes();
|
|
if (classArray.length > 1) {
|
|
throw this.err("Action must specify zero or one parameter", string);
|
|
}
|
|
if (classArray.length == 0) {
|
|
if (nAction.parameterDefault != null) {
|
|
throw this.err("Action has parameter default, but no parameter", string);
|
|
}
|
|
} else {
|
|
if (nAction.parameterDefault == null) {
|
|
throw this.err("Action has parameter, but no parameter default", string);
|
|
}
|
|
Class clazz3 = class$javax$baja$sys$BValue;
|
|
if (clazz3 == null) {
|
|
clazz3 = class$javax$baja$sys$BValue = ComplexIntrospector.class("[Ljavax.baja.sys.BValue;", false);
|
|
}
|
|
if (!clazz3.isAssignableFrom(classArray[0])) {
|
|
throw this.err("Action parameter type must be BValue", string);
|
|
}
|
|
if (!classArray[0].isAssignableFrom(nAction.parameterDefault.getClass())) {
|
|
throw this.err("Action parameter default has invalid type", string);
|
|
}
|
|
nAction.parameterClass = classArray[0];
|
|
}
|
|
if ((method = classArray.length == 0 ? this.methods.getMethod("do" + string2, MethodMap.noParams) : this.methods.getMethod("do" + string2, classArray[0])) == null) {
|
|
if (classArray.length == 0) {
|
|
String string3 = "do" + string2;
|
|
Class[] classArray2 = new Class[1];
|
|
Class clazz4 = class$javax$baja$sys$Context;
|
|
if (clazz4 == null) {
|
|
clazz4 = class$javax$baja$sys$Context = ComplexIntrospector.class("[Ljavax.baja.sys.Context;", false);
|
|
}
|
|
classArray2[0] = clazz4;
|
|
method = this.methods.getMethod(string3, classArray2);
|
|
} else {
|
|
String string4 = "do" + string2;
|
|
Class[] classArray3 = new Class[2];
|
|
classArray3[0] = classArray[0];
|
|
Class clazz5 = class$javax$baja$sys$Context;
|
|
if (clazz5 == null) {
|
|
clazz5 = class$javax$baja$sys$Context = ComplexIntrospector.class("[Ljavax.baja.sys.Context;", false);
|
|
}
|
|
classArray3[1] = clazz5;
|
|
method = this.methods.getMethod(string4, classArray3);
|
|
}
|
|
if (method == null) {
|
|
throw this.err("Missing action do method", "do" + string2);
|
|
}
|
|
nAction.doTakesContext = true;
|
|
}
|
|
if (!this.isPublic(method)) {
|
|
throw this.err("Do action method must be public", string2);
|
|
}
|
|
if (this.isStatic(method)) {
|
|
throw this.err("Do action method must be not be static", string2);
|
|
}
|
|
if (clazz != method.getReturnType()) {
|
|
throw this.err("Action method and do method have mismatched signature", nAction.name);
|
|
}
|
|
return nAction;
|
|
}
|
|
|
|
protected void checkSuperSlotInitialized(Field field) {
|
|
try {
|
|
NSlot nSlot = (NSlot)field.get(null);
|
|
if (nSlot.name == null) {
|
|
ArrayList<NSlot> arrayList;
|
|
if (this.superSlotsToFix == null) {
|
|
this.superSlotsToFix = new HashMap();
|
|
}
|
|
if ((arrayList = (ArrayList<NSlot>)this.superSlotsToFix.get(field.getName())) == null) {
|
|
arrayList = new ArrayList<NSlot>();
|
|
this.superSlotsToFix.put(field.getName(), arrayList);
|
|
}
|
|
arrayList.add(nSlot);
|
|
}
|
|
}
|
|
catch (Throwable throwable) {
|
|
throwable.printStackTrace();
|
|
}
|
|
}
|
|
|
|
protected void fixSuperSlots() {
|
|
Iterator iterator = this.superSlotsToFix.keySet().iterator();
|
|
while (iterator.hasNext()) {
|
|
String string = (String)iterator.next();
|
|
ArrayList arrayList = (ArrayList)this.superSlotsToFix.get(string);
|
|
int n = 0;
|
|
while (n < arrayList.size()) {
|
|
NSlot nSlot = (NSlot)arrayList.get(n);
|
|
int n2 = 0;
|
|
while (n2 < this.slots.length) {
|
|
NSlot nSlot2 = this.slots[n2];
|
|
if (nSlot2.name.equals(string)) {
|
|
nSlot.copyFrom(nSlot2);
|
|
break;
|
|
}
|
|
++n2;
|
|
}
|
|
++n;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void generateSlotMapClass() throws Exception {
|
|
String string = this.cls.getName().replace('.', '_');
|
|
String string2 = "auto." + string;
|
|
String string3 = "auto/" + string;
|
|
String string4 = this.isComponent ? "com/tridium/sys/schema/ComponentSlotMap" : "com/tridium/sys/schema/ComplexSlotMap";
|
|
Buffer buffer = new Compiler(string4, string3, this.cls, this.slots).compile();
|
|
Class clazz = AutoClassLoader.load(this.cls, string2, buffer);
|
|
this.slotMap = (ComplexSlotMap)clazz.newInstance();
|
|
}
|
|
|
|
static /* synthetic */ Class class(String string, boolean bl) {
|
|
try {
|
|
Class<?> clazz = Class.forName(string);
|
|
if (!bl) {
|
|
clazz = clazz.getComponentType();
|
|
}
|
|
return clazz;
|
|
}
|
|
catch (ClassNotFoundException classNotFoundException) {
|
|
throw new NoClassDefFoundError(classNotFoundException.getMessage());
|
|
}
|
|
}
|
|
|
|
public ComplexIntrospector(int n, Class clazz) {
|
|
super(n, clazz);
|
|
this.methods = new MethodMap(clazz);
|
|
Class clazz2 = class$javax$baja$sys$BComponent;
|
|
if (clazz2 == null) {
|
|
clazz2 = class$javax$baja$sys$BComponent = ComplexIntrospector.class("[Ljavax.baja.sys.BComponent;", false);
|
|
}
|
|
this.isComponent = clazz2.isAssignableFrom(clazz);
|
|
}
|
|
|
|
/*
|
|
* Illegal identifiers - consider using --renameillegalidents true
|
|
*/
|
|
static class TypeSpec {
|
|
final Class cls;
|
|
final int typeAccess;
|
|
static /* synthetic */ Class class$javax$baja$sys$BComponent;
|
|
static /* synthetic */ Class class$javax$baja$sys$BObject;
|
|
static /* synthetic */ Class class$javax$baja$sys$BValue;
|
|
static /* synthetic */ Class class$javax$baja$sys$BComplex;
|
|
|
|
boolean isError() {
|
|
boolean bl = false;
|
|
if (this.typeAccess == -1) {
|
|
bl = true;
|
|
}
|
|
return bl;
|
|
}
|
|
|
|
boolean isBWrapper() {
|
|
String string = this.cls.getName();
|
|
if (string.startsWith("javax.baja.sys.B")) {
|
|
string = string.substring(15);
|
|
boolean bl = false;
|
|
if (string.equals("BBoolean") || string.equals("BInteger") || string.equals("BLong") || string.equals("BFloat") || string.equals("BDouble") || string.equals("BString")) {
|
|
bl = true;
|
|
}
|
|
return bl;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
boolean isPotentialComponent() {
|
|
boolean bl;
|
|
block8: {
|
|
block7: {
|
|
bl = false;
|
|
Class clazz = class$javax$baja$sys$BComponent;
|
|
if (clazz == null) {
|
|
clazz = class$javax$baja$sys$BComponent = TypeSpec.class("[Ljavax.baja.sys.BComponent;", false);
|
|
}
|
|
if (clazz.isAssignableFrom(this.cls)) break block7;
|
|
Class clazz2 = class$javax$baja$sys$BObject;
|
|
if (clazz2 == null) {
|
|
clazz2 = class$javax$baja$sys$BObject = TypeSpec.class("[Ljavax.baja.sys.BObject;", false);
|
|
}
|
|
if (this.cls == clazz2) break block7;
|
|
Class clazz3 = class$javax$baja$sys$BValue;
|
|
if (clazz3 == null) {
|
|
clazz3 = class$javax$baja$sys$BValue = TypeSpec.class("[Ljavax.baja.sys.BValue;", false);
|
|
}
|
|
if (this.cls == clazz3) break block7;
|
|
Class clazz4 = class$javax$baja$sys$BComplex;
|
|
if (clazz4 == null) {
|
|
clazz4 = class$javax$baja$sys$BComplex = TypeSpec.class("[Ljavax.baja.sys.BComplex;", false);
|
|
}
|
|
if (this.cls != clazz4) break block8;
|
|
}
|
|
bl = true;
|
|
}
|
|
return bl;
|
|
}
|
|
|
|
public String toString() {
|
|
return this.cls.getName();
|
|
}
|
|
|
|
static /* synthetic */ Class class(String string, boolean bl) {
|
|
try {
|
|
Class<?> clazz = Class.forName(string);
|
|
if (!bl) {
|
|
clazz = clazz.getComponentType();
|
|
}
|
|
return clazz;
|
|
}
|
|
catch (ClassNotFoundException classNotFoundException) {
|
|
throw new NoClassDefFoundError(classNotFoundException.getMessage());
|
|
}
|
|
}
|
|
|
|
TypeSpec(Class clazz) {
|
|
this.cls = clazz;
|
|
this.typeAccess = Utils.getTypeAccess(clazz);
|
|
}
|
|
}
|
|
}
|
|
|