* Modifies the class initialization method (creating one if necessary)
* to initialize the static fields of the PersistenceCapable instance and
* to register it with the impl helper.
*/
private void addStaticInitializer() {
Code code = getOrCreateClassInitCode(true);
if (_meta.getPCSuperclass() != null) {
if (getCreateSubclass()) {
code.constant().setValue(0);
code.putstatic().setField(INHERIT, int.class);
} else {
// pcInheritedFieldCount = <superClass>.pcGetManagedFieldCount()
code.invokestatic().setMethod(getType(_meta.
getPCSuperclassMetaData()).getName(),
PRE + "GetManagedFieldCount", int.class.getName(), null);
code.putstatic().setField(INHERIT, int.class);
}
// pcPCSuperclass = <superClass>;
code.classconstant().setClass(getType(_meta.
getPCSuperclassMetaData()));
code.putstatic().setField(SUPER, Class.class);
}
// pcFieldNames = new String[] { "<name1>", "<name2>", ... };
FieldMetaData[] fmds = _meta.getDeclaredFields();
code.constant().setValue(fmds.length);
code.anewarray().setType(String.class);
for (int i = 0; i < fmds.length; i++) {
code.dup();
code.constant().setValue(i);
code.constant().setValue(fmds[i].getName());
code.aastore();
}
code.putstatic().setField(PRE + "FieldNames", String[].class);
// pcFieldTypes = new Class[] { <type1>.class, <type2>.class, ... };
code.constant().setValue(fmds.length);
code.anewarray().setType(Class.class);
for (int i = 0; i < fmds.length; i++) {
code.dup();
code.constant().setValue(i);
code.classconstant().setClass(fmds[i].getDeclaredType());
code.aastore();
}
code.putstatic().setField(PRE + "FieldTypes", Class[].class);
// pcFieldFlags = new byte[] { <flag1>, <flag2>, ... };
code.constant().setValue(fmds.length);
code.newarray().setType(byte.class);
for (int i = 0; i < fmds.length; i++) {
code.dup();
code.constant().setValue(i);
code.constant().setValue(getFieldFlag(fmds[i]));
code.bastore();
}
code.putstatic().setField(PRE + "FieldFlags", byte[].class);
// PCRegistry.register (cls,
// pcFieldNames, pcFieldTypes, pcFieldFlags,
// pcPCSuperclass, alias, new XXX ());
code.classconstant().setClass(_managedType);
code.getstatic().setField(PRE + "FieldNames", String[].class);
code.getstatic().setField(PRE + "FieldTypes", Class[].class);
code.getstatic().setField(PRE + "FieldFlags", byte[].class);
code.getstatic().setField(SUPER, Class.class);
if (_meta.isMapped())
code.constant().setValue(_meta.getTypeAlias());
else
code.constant().setNull();
if (_pc.isAbstract())
code.constant().setNull();
else {
code.anew().setType(_pc);
code.dup();
code.invokespecial().setMethod("<init>", void.class, null);
}
code.invokestatic().setMethod(HELPERTYPE, "register", void.class,
new Class[]{ Class.class, String[].class, Class[].class,
byte[].class, Class.class, String.class, PCTYPE });
code.vreturn();
code.calculateMaxStack();
}