// Add any new fields
List fields = enhancer.getFieldsList();
Iterator fieldsIter = fields.iterator();
while (fieldsIter.hasNext())
{
ClassField field = (ClassField)fieldsIter.next();
if (field.getName().equals(enhancer.getDetachedStateFieldName()) && hasJdoDetachedState)
{
// No need to add this field since exists
continue;
}
if (DataNucleusEnhancer.LOGGER.isDebugEnabled())
{
DataNucleusEnhancer.LOGGER.debug(LOCALISER.msg("Enhancer.AddField",
((Class)field.getType()).getName() + " " + field.getName()));
}
cv.visitField(field.getAccess(), field.getName(), Type.getDescriptor((Class)field.getType()), null, null);
}
if (!hasStaticInitialisation)
{
// Add a static initialisation block for the class since nothing added yet
InitClass method = InitClass.getInstance(enhancer);
method.initialise(cv);
method.execute();
method.close();
}
if (!hasDefaultConstructor && enhancer.hasOption(ClassEnhancer.OPTION_GENERATE_DEFAULT_CONSTRUCTOR))
{
// Add a default constructor
DefaultConstructor ctr = DefaultConstructor.getInstance(enhancer);
ctr.initialise(cv);
ctr.execute();
ctr.close();
}
// Add any new methods
List methods = enhancer.getMethodsList();
Iterator methodsIter = methods.iterator();
while (methodsIter.hasNext())
{
ASMClassMethod method = (ASMClassMethod)methodsIter.next();
method.initialise(cv);
method.execute();
method.close();
}
if (Serializable.class.isAssignableFrom(enhancer.cls))
{
// Class is Serializable
if (!hasSerialVersionUID)
{
// Needs "serialVersionUID" field
Long uid = null;
try
{
uid = (Long) AccessController.doPrivileged(new PrivilegedAction()
{
public Object run()
{
return Long.valueOf(ObjectStreamClass.lookup(enhancer.getClassEnhanced()).getSerialVersionUID());
}
});
}
catch (Throwable e)
{
DataNucleusEnhancer.LOGGER.warn(StringUtils.getStringFromStackTrace(e));
}
ClassField cf = new ClassField(enhancer, enhancer.getSerialVersionUidFieldName(),
Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, long.class, uid);
if (DataNucleusEnhancer.LOGGER.isDebugEnabled())
{
DataNucleusEnhancer.LOGGER.debug(LOCALISER.msg("Enhancer.AddField",
((Class)cf.getType()).getName() + " " + cf.getName()));
}
cv.visitField(cf.getAccess(), cf.getName(), Type.getDescriptor((Class)cf.getType()), null, cf.getInitialValue());
}
if (!hasWriteObject)
{
ASMClassMethod method = WriteObject.getInstance(enhancer);
method.initialise(cv);