Search in sources :

Example 1 with EzyClass

use of com.tvd12.ezyfox.reflect.EzyClass in project ezyfox-server by youngmonkeys.

the class EzyExceptionHandlerImplementer method doImplement.

protected EzyUncaughtExceptionHandler doImplement() throws Exception {
    ClassPool pool = ClassPool.getDefault();
    String implClassName = getImplClassName();
    CtClass implClass = pool.makeClass(implClassName);
    EzyClass superClass = new EzyClass(getSuperClass());
    String exceptionHandlerFieldContent = makeExceptionHandlerFieldContent();
    String setExceptionHandlerMethodContent = makeSetExceptionHandlerMethodContent();
    String handleExceptionMethodContent = makeHandleExceptionMethodContent();
    printComponentContent(implClassName);
    printComponentContent(exceptionHandlerFieldContent);
    printComponentContent(setExceptionHandlerMethodContent);
    printComponentContent(handleExceptionMethodContent);
    implClass.setSuperclass(pool.get(superClass.getName()));
    implClass.addField(CtField.make(exceptionHandlerFieldContent, implClass));
    implClass.addMethod(CtNewMethod.make(setExceptionHandlerMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(handleExceptionMethodContent, implClass));
    Class answerClass = implClass.toClass();
    implClass.detach();
    EzyAsmUncaughtExceptionHandler handler = (EzyAsmUncaughtExceptionHandler) answerClass.newInstance();
    setRepoComponent(handler);
    return handler;
}
Also used : CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass) ClassPool(javassist.ClassPool) CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass)

Example 2 with EzyClass

use of com.tvd12.ezyfox.reflect.EzyClass in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlerImplementer method doImplement.

@SuppressWarnings("rawtypes")
protected EzyAsmRequestHandler doImplement() throws Exception {
    ClassPool pool = ClassPool.getDefault();
    String implClassName = getImplClassName();
    CtClass implClass = pool.makeClass(implClassName);
    EzyClass superClass = new EzyClass(getSuperClass());
    String controllerFieldContent = makeControllerFieldContent();
    String setControllerMethodContent = makeSetControllerMethodContent();
    String handleRequestMethodContent = makeHandleRequestMethodContent();
    String handleExceptionMethodContent = makeHandleExceptionMethodContent();
    String getRequestDataTypeMethodContent = makeGetRequestDataTypeMethodContent();
    printComponentContent(controllerFieldContent);
    printComponentContent(setControllerMethodContent);
    printComponentContent(handleRequestMethodContent);
    printComponentContent(handleExceptionMethodContent);
    printComponentContent(getRequestDataTypeMethodContent);
    implClass.setSuperclass(pool.get(superClass.getName()));
    implClass.addField(CtField.make(controllerFieldContent, implClass));
    implClass.addMethod(CtNewMethod.make(setControllerMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(handleRequestMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(handleExceptionMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(getRequestDataTypeMethodContent, implClass));
    Class answerClass = implClass.toClass();
    implClass.detach();
    EzyAsmRequestHandler handler = (EzyAsmRequestHandler) answerClass.newInstance();
    handler.setCommand(handlerMethod.getCommand());
    handler.setResponseFactory(responseFactory);
    setRepoComponent(handler);
    return handler;
}
Also used : CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass) ClassPool(javassist.ClassPool) CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass)

Example 3 with EzyClass

use of com.tvd12.ezyfox.reflect.EzyClass in project ezyhttp by youngmonkeys.

the class ExceptionHandlerImplementer method doImplement.

@SuppressWarnings("rawtypes")
protected UncaughtExceptionHandler doImplement() throws Exception {
    ClassPool pool = ClassPool.getDefault();
    String implClassName = getImplClassName();
    CtClass implClass = pool.makeClass(implClassName);
    EzyClass superClass = new EzyClass(getSuperClass());
    String exceptionHandlerFieldContent = makeExceptionHandlerFieldContent();
    String setExceptionHandlerMethodContent = makeSetExceptionHandlerMethodContent();
    String handleExceptionMethodContent = makeHandleExceptionMethodContent();
    String getResponseContentTypeMethodContent = makeGetResponseContentTypeMethodContent();
    printComponentContent(implClassName);
    printComponentContent(exceptionHandlerFieldContent);
    printComponentContent(setExceptionHandlerMethodContent);
    printComponentContent(handleExceptionMethodContent);
    printComponentContent(getResponseContentTypeMethodContent);
    implClass.setSuperclass(pool.get(superClass.getName()));
    implClass.addField(CtField.make(exceptionHandlerFieldContent, implClass));
    implClass.addMethod(CtNewMethod.make(setExceptionHandlerMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(handleExceptionMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(getResponseContentTypeMethodContent, implClass));
    Class answerClass = implClass.toClass();
    implClass.detach();
    AsmUncaughtExceptionHandler handler = (AsmUncaughtExceptionHandler) answerClass.newInstance();
    setRepoComponent(handler);
    return handler;
}
Also used : CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass) ClassPool(javassist.ClassPool) CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass)

Example 4 with EzyClass

use of com.tvd12.ezyfox.reflect.EzyClass in project ezyhttp by youngmonkeys.

the class RequestHandlerImplementer method doImplement.

@SuppressWarnings("rawtypes")
protected RequestHandler doImplement() throws Exception {
    ClassPool pool = ClassPool.getDefault();
    String implClassName = getImplClassName();
    CtClass implClass = pool.makeClass(implClassName);
    EzyClass superClass = new EzyClass(getSuperClass());
    String controllerFieldContent = makeControllerFieldContent();
    String setControllerMethodContent = makeSetControllerMethodContent();
    String handleRequestMethodContent = makeHandleRequestMethodContent();
    String handleExceptionMethodContent = makeHandleExceptionMethodContent();
    String getHttpMethodMethodContent = makeGetHttpMethodMethodContent();
    String getRequestURIMethodContent = makeGetRequestURIMethodContent();
    String getResponseContentTypeMethodContent = makeGetResponseContentTypeMethodContent();
    String isAsyncMethodContent = makeIsAsyncMethodContent();
    printComponentContent(controllerFieldContent);
    printComponentContent(setControllerMethodContent);
    printComponentContent(handleRequestMethodContent);
    printComponentContent(handleExceptionMethodContent);
    printComponentContent(getHttpMethodMethodContent);
    printComponentContent(getRequestURIMethodContent);
    printComponentContent(getResponseContentTypeMethodContent);
    printComponentContent(isAsyncMethodContent);
    implClass.setSuperclass(pool.get(superClass.getName()));
    implClass.addField(CtField.make(controllerFieldContent, implClass));
    implClass.addMethod(CtNewMethod.make(setControllerMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(handleRequestMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(handleExceptionMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(getHttpMethodMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(getRequestURIMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(getResponseContentTypeMethodContent, implClass));
    implClass.addMethod(CtNewMethod.make(isAsyncMethodContent, implClass));
    Class answerClass = implClass.toClass();
    implClass.detach();
    RequestHandler handler = (RequestHandler) answerClass.newInstance();
    handler.setHandlerMethod(handlerMethod.getMethod().getMethod());
    setRepoComponent(handler);
    return handler;
}
Also used : CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass) RequestHandler(com.tvd12.ezyhttp.server.core.handler.RequestHandler) AbstractRequestHandler(com.tvd12.ezyhttp.server.core.handler.AbstractRequestHandler) ClassPool(javassist.ClassPool) CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass)

Aggregations

EzyClass (com.tvd12.ezyfox.reflect.EzyClass)4 ClassPool (javassist.ClassPool)4 CtClass (javassist.CtClass)4 AbstractRequestHandler (com.tvd12.ezyhttp.server.core.handler.AbstractRequestHandler)1 RequestHandler (com.tvd12.ezyhttp.server.core.handler.RequestHandler)1