Search in sources :

Example 1 with HandlerArtifactProcessor

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

the class JaxWsAnnotationProcessor method generateEntryPoint.

/**
 * Generates the entry point and associated artifacts for the given definition.
 */
protected void generateEntryPoint(final EntryPointDefinition entryPointDefinition, final RoundEnvironment roundEnv) throws JClassAlreadyExistsException, ClassNotFoundException, IOException {
    final JCodeModel model = new JCodeModel();
    // Create EntryPoint class.
    final TypeElement _endpointInterface = entryPointDefinition.getEndpointInterface();
    final JClass endpointInterface = model.ref(_endpointInterface.getQualifiedName().toString());
    final JDefinedClass entryPoint = model._class(entryPointDefinition.getEntryPointQualifiedName())._implements(endpointInterface);
    // Add annotations to the EntryPoint.
    addAnnotations(model, entryPoint, entryPointDefinition, roundEnv);
    // Create handler chain.
    final HandlerChain _handlerChainAnnotation = _endpointInterface.getAnnotation(HandlerChain.class);
    if (_handlerChainAnnotation != null) {
        m_logger.info("Handler file not generated because provided as binding file [file={}, entryPoint={}, endpointInterface={}]", _handlerChainAnnotation.file(), entryPointDefinition.getEntryPointQualifiedName(), entryPointDefinition.getEndpointInterfaceQualifiedName());
    } else if (!entryPointDefinition.getHandlerChain().isEmpty() || entryPointDefinition.isAuthenticationEnabled()) {
        entryPoint.annotate(HandlerChain.class).param("file", new HandlerArtifactProcessor().generateHandlerArtifacts(entryPoint, entryPointDefinition, processingEnv, m_logger));
    }
    // Add JavaDoc to the EntryPoint.
    AptUtil.addJavaDoc(entryPoint, createJavaDocForEntryPoint(entryPointDefinition));
    // Inject WebServiceContext
    final JFieldVar webServiceContext = entryPoint.field(JMod.PROTECTED, WebServiceContext.class, WEBSERVICE_CONTEXT_FIELD_NAME);
    webServiceContext.annotate(Resource.class);
    // Overwrite all methods declared on the PortType interface.
    for (final Element _element : _endpointInterface.getEnclosedElements()) {
        if (!(ElementKind.METHOD.equals(_element.getKind()))) {
            continue;
        }
        final ExecutableElement _method = (ExecutableElement) _element;
        final String methodName = _method.getSimpleName().toString();
        final JType returnType = JTypeParser.parseType(model, _method.getReturnType());
        // Create the method.
        final JMethod method = entryPoint.method(JMod.PUBLIC, returnType, methodName);
        method.annotate(Override.class);
        // Add the method parameters.
        for (final VariableElement _param : _method.getParameters()) {
            method.param(JMod.FINAL, JTypeParser.parseType(model, _param.asType()), _param.getSimpleName().toString());
        }
        // Add exception throw clauses.
        final List<JClass> throwTypes = new ArrayList<>();
        for (final TypeMirror _throwType : _method.getThrownTypes()) {
            final JClass throwType = model.ref(_throwType.toString());
            throwTypes.add(throwType);
            method._throws(throwType);
        }
        // Create the method implementation.
        addEntryPointMethodImplementation(model, webServiceContext, method, throwTypes, TypeKind.VOID.equals(_method.getReturnType().getKind()), _endpointInterface.getQualifiedName().toString());
    }
    // Create the method to handle undeclared errors.
    addHandleUndeclaredFaultMethod(model, entryPoint);
    // Create the method to lookup the RunContext.
    addLookupRunContextMethod(model, entryPoint, webServiceContext);
    // Build and persist this compilation unit.
    AptUtil.buildAndPersist(model, processingEnv.getFiler());
    m_logger.info("Entry point successfully generated. [entryPoint={}, endpointInterface={}, entryPointDefinition={}]", entryPoint.fullName(), endpointInterface.fullName(), entryPointDefinition.getQualifiedName());
}
Also used : JDefinedClass(com.sun.codemodel.JDefinedClass) TypeElement(javax.lang.model.element.TypeElement) JClass(com.sun.codemodel.JClass) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) ArrayList(java.util.ArrayList) VariableElement(javax.lang.model.element.VariableElement) JCodeModel(com.sun.codemodel.JCodeModel) HandlerChain(javax.jws.HandlerChain) JFieldVar(com.sun.codemodel.JFieldVar) TypeMirror(javax.lang.model.type.TypeMirror) HandlerArtifactProcessor(org.eclipse.scout.jaxws.apt.internal.HandlerArtifactProcessor) JMethod(com.sun.codemodel.JMethod) JType(com.sun.codemodel.JType)

Aggregations

JClass (com.sun.codemodel.JClass)1 JCodeModel (com.sun.codemodel.JCodeModel)1 JDefinedClass (com.sun.codemodel.JDefinedClass)1 JFieldVar (com.sun.codemodel.JFieldVar)1 JMethod (com.sun.codemodel.JMethod)1 JType (com.sun.codemodel.JType)1 ArrayList (java.util.ArrayList)1 HandlerChain (javax.jws.HandlerChain)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1 HandlerArtifactProcessor (org.eclipse.scout.jaxws.apt.internal.HandlerArtifactProcessor)1