use of io.muoncore.newton.eventsource.muon.MuonEventSourceRepository in project newton by muoncore.
the class EnableNewtonRegistrar method makeRepo.
private Class makeRepo(Class param) {
ClassPool defaultClassPool = ClassPool.getDefault();
defaultClassPool.appendClassPath(new LoaderClassPath(param.getClassLoader()));
defaultClassPool.appendClassPath(new LoaderClassPath(MuonEventSourceRepository.class.getClassLoader()));
defaultClassPool.appendSystemPath();
try {
CtClass superInterface = defaultClassPool.getCtClass(MuonEventSourceRepository.class.getName());
String repoName = param.getName() + "Repository";
try {
return Class.forName(repoName);
} catch (ClassNotFoundException e) {
CtClass repositoryInterface = defaultClassPool.makeClass(repoName, superInterface);
ClassFile classFile = repositoryInterface.getClassFile();
String sig = "Ljava/lang/Object;Lio/muoncore/newton/eventsource/muon/MuonEventSourceRepository<L" + getSigName(param) + ";>;";
SignatureAttribute signatureAttribute = new SignatureAttribute(classFile.getConstPool(), sig);
classFile.addAttribute(signatureAttribute);
return repositoryInterface.toClass();
}
} catch (NotFoundException | CannotCompileException e) {
log.error("Unable to register a newton repository", e);
}
return null;
}
Aggregations