Search in sources :

Example 1 with MuonEventSourceRepository

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;
}
Also used : SignatureAttribute(javassist.bytecode.SignatureAttribute) ClassFile(javassist.bytecode.ClassFile) MuonEventSourceRepository(io.muoncore.newton.eventsource.muon.MuonEventSourceRepository)

Aggregations

MuonEventSourceRepository (io.muoncore.newton.eventsource.muon.MuonEventSourceRepository)1 ClassFile (javassist.bytecode.ClassFile)1 SignatureAttribute (javassist.bytecode.SignatureAttribute)1