use of org.apache.bcel.generic.ClassGen in project qpid-broker-j by apache.
the class LDAPSSLSocketFactoryGenerator method createSubClassByteCode.
/**
* Creates the LDAPSocketFactoryImpl class (subclass of {@link AbstractLDAPSSLSocketFactory}.
* A static method #getDefaulta, a static field _sslContent and no-arg constructor are added
* to the class.
*
* @param className
*
* @return byte code
*/
private static byte[] createSubClassByteCode(final String className) {
ClassGen classGen = new ClassGen(className, AbstractLDAPSSLSocketFactory.class.getName(), "<generated>", ACC_PUBLIC | ACC_SUPER, null);
ConstantPoolGen constantPoolGen = classGen.getConstantPool();
InstructionFactory factory = new InstructionFactory(classGen);
createSslContextStaticField(classGen, constantPoolGen);
createGetDefaultStaticMethod(classGen, constantPoolGen, factory);
classGen.addEmptyConstructor(ACC_PROTECTED);
JavaClass javaClass = classGen.getJavaClass();
ByteArrayOutputStream out = null;
try {
out = new ByteArrayOutputStream();
javaClass.dump(out);
return out.toByteArray();
} catch (IOException ioex) {
throw new IllegalStateException("Could not write to a ByteArrayOutputStream - should not happen", ioex);
} finally {
closeSafely(out);
}
}
Aggregations