if (result != null) {
// Should always be the case
// Manipulation preparation
Manipulator manipulator = new Manipulator(m_classLoader);
try {
manipulator.prepare(bytecode);
} catch (IOException e) {
m_reporter.error("Cannot analyze the class " + info.getClassName() + " : " + e.getMessage());
return;
}
// Inner class preparation
for (String inner : manipulator.getInnerClasses()) {
// Get the bytecode and start manipulation
String resourcePath = inner + ".class";
String outerClassInternalName = info.getClassName().replace('.', '/');
byte[] innerClassBytecode;
try {
innerClassBytecode = m_store.read(resourcePath);
manipulator.prepareInnerClass(inner, innerClassBytecode);
} catch (IOException e) {
m_reporter.error("Cannot find or analyze inner class '" + resourcePath + "'");
return;
}
}
// Now manipulate the classes.
try {
byte[] out = manipulator.manipulate(bytecode);
// Call the visitor
result.visitManipulatedResource(info.getResourcePath(), out);
} catch (IOException e) {
m_reporter.error("Cannot manipulate the class " + info.getClassName() + " : " + e.getMessage());
return;
}
// Visit inner classes
for (String inner : manipulator.getInnerClasses()) {
// Get the bytecode and start manipulation
String resourcePath = inner + ".class";
String outerClassInternalName = info.getClassName().replace('.', '/');
byte[] innerClassBytecode;
try {
innerClassBytecode = m_store.read(resourcePath);
} catch (IOException e) {
m_reporter.error("Cannot find inner class '" + resourcePath + "'");
return;
}
// Manipulate inner class
// Notice that (for performance reason) re-use the class version information
// discovered in the main class instead of re-parsing the inner class to find
// its own class version
try {
byte[] manipulated = manipulator.manipulateInnerClass(inner, innerClassBytecode);
// Propagate manipulated resource
result.visitManipulatedResource(resourcePath, manipulated);
} catch (IOException e) {
m_reporter.error("Cannot manipulate inner class '" + resourcePath + "'");
return;
}
}
// Compute manipulation metadata
result.visitClassStructure(manipulator.getManipulationMetadata());
// All resources have been manipulated for this component
result.visitEnd();
}
}