Search in sources :

Example 1 with JConditionalEx

use of org.eclipse.scout.jaxws.apt.internal.codemodel.JConditionalEx in project scout.rt by eclipse.

the class JaxWsAnnotationProcessor method addEntryPointMethodImplementation.

/**
 * Creates the implementation of a entry point method.
 */
protected void addEntryPointMethodImplementation(final JCodeModel model, final JFieldVar webServiceContext, final JMethod method, final List<JClass> throwTypes, final boolean voidMethod, final String endpointInterfaceName) {
    final JBlock methodBody = method.body();
    final JInvocation runContext = JExpr.invoke(LOOKUP_RUN_CONTEXT_METHOD_NAME);
    final JTryBlock tryBlock = methodBody._try();
    // Invoke port type on behalf of RunContext.
    final JInvocation runContextInvocation = createRunContextInvocation(model, runContext, voidMethod, method, endpointInterfaceName);
    if (voidMethod) {
        tryBlock.body().add(runContextInvocation);
    } else {
        tryBlock.body()._return(runContextInvocation);
    }
    // Create exception handling.
    final JCatchBlock catchBlock = tryBlock._catch(model.ref(Exception.class));
    final JVar caughtException = catchBlock.param("e");
    final JBlock catchBody = catchBlock.body();
    if (throwTypes.isEmpty()) {
        // webservice method has no faults declared.
        catchBody._throw(JExpr.invoke(HANDLE_UNDECLARED_FAULT_METHOD_NAME).arg(caughtException));
    } else {
        // handle declared webservice faults.
        final JConditionalEx condition = new JConditionalEx(catchBody);
        for (final JClass throwType : throwTypes) {
            condition._elseif(caughtException._instanceof(throwType))._throw(JExprEx.cast(throwType, caughtException));
        }
        condition._else()._throw(JExpr.invoke(HANDLE_UNDECLARED_FAULT_METHOD_NAME).arg(caughtException));
    }
}
Also used : JClass(com.sun.codemodel.JClass) JBlock(com.sun.codemodel.JBlock) JInvocation(com.sun.codemodel.JInvocation) JTryBlock(com.sun.codemodel.JTryBlock) JCatchBlock(com.sun.codemodel.JCatchBlock) JClassAlreadyExistsException(com.sun.codemodel.JClassAlreadyExistsException) IOException(java.io.IOException) JVar(com.sun.codemodel.JVar) JConditionalEx(org.eclipse.scout.jaxws.apt.internal.codemodel.JConditionalEx)

Aggregations

JBlock (com.sun.codemodel.JBlock)1 JCatchBlock (com.sun.codemodel.JCatchBlock)1 JClass (com.sun.codemodel.JClass)1 JClassAlreadyExistsException (com.sun.codemodel.JClassAlreadyExistsException)1 JInvocation (com.sun.codemodel.JInvocation)1 JTryBlock (com.sun.codemodel.JTryBlock)1 JVar (com.sun.codemodel.JVar)1 IOException (java.io.IOException)1 JConditionalEx (org.eclipse.scout.jaxws.apt.internal.codemodel.JConditionalEx)1