Search in sources :

Example 11 with JAnnotationUse

use of com.sun.codemodel.JAnnotationUse in project scout.rt by eclipse.

the class JaxWsAnnotationProcessor method addAnnotations.

/**
 * Adds annotations to the EntryPoint.
 */
protected void addAnnotations(final JCodeModel model, final JDefinedClass entryPoint, final EntryPointDefinition entryPointDefinition, final RoundEnvironment roundEnv) {
    // Add 'Generated' annotation
    final JAnnotationUse generatedAnnotation = entryPoint.annotate(Generated.class);
    generatedAnnotation.param("value", JaxWsAnnotationProcessor.class.getName());
    generatedAnnotation.param("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:SSSZ").format(new Date()));
    generatedAnnotation.param("comments", "EntryPoint to run webservice requests on behalf of a RunContext");
    // Add 'WebService' annotation
    if (!entryPointDefinition.containsAnnotation(WebService.class)) {
        final WebService _webServiceAnnotation = entryPointDefinition.getEndpointInterface().getAnnotation(WebService.class);
        final JAnnotationUse webServiceAnnotation = entryPoint.annotate(WebService.class);
        webServiceAnnotation.param("name", _webServiceAnnotation.name());
        webServiceAnnotation.param("targetNamespace", _webServiceAnnotation.targetNamespace());
        webServiceAnnotation.param("endpointInterface", entryPointDefinition.getEndpointInterfaceQualifiedName());
        if (StringUtility.hasText(entryPointDefinition.getServiceName())) {
            webServiceAnnotation.param("serviceName", entryPointDefinition.getServiceName());
        } else {
            m_logger.warn("No 'serviceName' specified, which is required if running in a EE container with 'webservice auto-discovery' enabled. [entryPoint={}, endpointInterface={}]", entryPointDefinition.getSimpleName(), entryPointDefinition.getEndpointInterfaceSimpleName());
        }
        if (StringUtility.hasText(entryPointDefinition.getPortName())) {
            webServiceAnnotation.param("portName", entryPointDefinition.getPortName());
        } else {
            m_logger.warn("No 'portName' specified, which is required if running in a EE container with 'webservice auto-discovery' enabled. [entryPoint={}, endpointInterface={}]", entryPointDefinition.getSimpleName(), entryPointDefinition.getEndpointInterfaceSimpleName());
        }
        if (entryPointDefinition.isWsdlLocationDerived()) {
            final WebServiceClient _webServiceClientAnnotation = findWebServiceClientAnnotation(roundEnv, entryPointDefinition.getServiceName());
            if (_webServiceClientAnnotation != null) {
                webServiceAnnotation.param("wsdlLocation", _webServiceClientAnnotation.wsdlLocation());
            } else if (!StringUtility.hasText(entryPointDefinition.getServiceName())) {
                m_logger.warn("Cannot derive 'wsdlLocation' because no 'serviceName'. [entryPoint={}, endpointInterface={}]", entryPointDefinition.getSimpleName(), entryPointDefinition.getEndpointInterfaceSimpleName());
            } else {
                m_logger.warn("Cannot derive 'wsdlLocation' because no Service annotated with '@WebServiceClient(name=\"{}\")' found. [entryPoint={}, endpointInterface={}]", entryPointDefinition.getServiceName(), entryPointDefinition.getSimpleName(), entryPointDefinition.getEndpointInterfaceSimpleName());
            }
        } else if (StringUtility.hasText(entryPointDefinition.getWsdlLocation())) {
            webServiceAnnotation.param("wsdlLocation", entryPointDefinition.getWsdlLocation());
        }
    }
    // Add custom annotations
    AnnotationUtil.addAnnotations(model, entryPoint, entryPointDefinition.getSiblingAnnotations());
}
Also used : WebService(javax.jws.WebService) JAnnotationUse(com.sun.codemodel.JAnnotationUse) WebServiceClient(javax.xml.ws.WebServiceClient) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 12 with JAnnotationUse

use of com.sun.codemodel.JAnnotationUse in project scout.rt by eclipse.

the class HandlerArtifactProcessor method createAndPersistHandlerDelegate.

/**
 * Generates the entry point for a handler.
 */
public String createAndPersistHandlerDelegate(final JClass portTypeEntryPoint, final EntryPointDefinition entryPointDefinition, final HandlerDefinition handler, final int idx, final ProcessingEnvironment env) throws IOException, JClassAlreadyExistsException {
    final JCodeModel model = new JCodeModel();
    final String fullName = entryPointDefinition.getEntryPointQualifiedName() + "_" + handler.getHandlerSimpleName() + HANDLER_SUFFIX;
    final JDefinedClass handlerDelegate = model._class(fullName);
    // Add 'Generated' annotation
    final JAnnotationUse generatedAnnotation = handlerDelegate.annotate(Generated.class);
    generatedAnnotation.param("value", JaxWsAnnotationProcessor.class.getName());
    generatedAnnotation.param("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:SSSZ").format(new Date()));
    generatedAnnotation.param("comments", "Handler delegate for " + handler.getHandlerQualifiedName());
    AptUtil.addJavaDoc(handlerDelegate, format("This class is auto-generated by APT triggered by Maven build and is based on the handler configuration declared in {@link %s}.", entryPointDefinition.getSimpleName()));
    switch(handler.getHandlerType()) {
        case SOAP:
            handlerDelegate._extends(model.ref(SOAPHandlerDelegate.class));
            break;
        case LOGICAL:
            handlerDelegate._extends(model.ref(HandlerDelegate.class).narrow(LogicalMessageContext.class));
            handlerDelegate._implements(model.ref(LogicalHandler.class).narrow(LogicalMessageContext.class));
            break;
        default:
            handlerDelegate._extends(model.ref(HandlerDelegate.class).narrow(MessageContext.class));
            break;
    }
    // Add default constructor with super call to provide handler annotation.
    final JClass entryPointDefinitionClass = model.ref(entryPointDefinition.getQualifiedName());
    final JMethod defaultConstructor = handlerDelegate.constructor(JMod.PUBLIC);
    defaultConstructor.body().invoke("super").arg(JExpr.dotclass(entryPointDefinitionClass).invoke("getAnnotation").arg(JExpr.dotclass(model.ref(WebServiceEntryPoint.class))).invoke("handlerChain").component(JExpr.lit(idx)));
    AptUtil.buildAndPersist(model, env.getFiler());
    return handlerDelegate.fullName();
}
Also used : JaxWsAnnotationProcessor(org.eclipse.scout.jaxws.apt.JaxWsAnnotationProcessor) LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) JDefinedClass(com.sun.codemodel.JDefinedClass) JClass(com.sun.codemodel.JClass) SOAPHandlerDelegate(org.eclipse.scout.rt.server.jaxws.provider.handler.SOAPHandlerDelegate) JCodeModel(com.sun.codemodel.JCodeModel) Date(java.util.Date) JAnnotationUse(com.sun.codemodel.JAnnotationUse) LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) MessageContext(javax.xml.ws.handler.MessageContext) JMethod(com.sun.codemodel.JMethod) WebServiceEntryPoint(org.eclipse.scout.rt.server.jaxws.provider.annotation.WebServiceEntryPoint) SimpleDateFormat(java.text.SimpleDateFormat)

Example 13 with JAnnotationUse

use of com.sun.codemodel.JAnnotationUse in project scout.rt by eclipse.

the class AnnotationUtil method addAnnotations.

/**
 * Annotates the given target class with a copy of the given annotations.
 */
public static void addAnnotations(final JCodeModel model, final JDefinedClass targetClazz, final List<AnnotationMirror> _annotations) {
    for (final AnnotationMirror _annotation : _annotations) {
        final JAnnotationUse targetAnnotation = targetClazz.annotate(model.ref(_annotation.getAnnotationType().toString()));
        // Add annotation attributes.
        for (final Entry<? extends ExecutableElement, ? extends AnnotationValue> _annotationParamEntry : _annotation.getElementValues().entrySet()) {
            final String paramName = _annotationParamEntry.getKey().getSimpleName().toString();
            final AnnotationValue _paramValue = _annotationParamEntry.getValue();
            targetAnnotation.param(paramName, AnnotationUtil.createExpression(model, _paramValue));
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) JAnnotationUse(com.sun.codemodel.JAnnotationUse) AnnotationValue(javax.lang.model.element.AnnotationValue)

Example 14 with JAnnotationUse

use of com.sun.codemodel.JAnnotationUse in project jsonschema2pojo by joelittlejohn.

the class Models method suppressWarnings.

public static void suppressWarnings(JMethod method, String... values) {
    JAnnotationUse annotation = method.annotate(SuppressWarnings.class);
    JAnnotationArrayMember member = annotation.paramArray("value");
    for (String value : values) {
        member.param(value);
    }
}
Also used : JAnnotationUse(com.sun.codemodel.JAnnotationUse) JAnnotationArrayMember(com.sun.codemodel.JAnnotationArrayMember)

Example 15 with JAnnotationUse

use of com.sun.codemodel.JAnnotationUse in project jsonschema2pojo by joelittlejohn.

the class PatternRule method apply.

@Override
public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) {
    if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && isApplicableType(field)) {
        final Class<? extends Annotation> patternClass = ruleFactory.getGenerationConfig().isUseJakartaValidation() ? Pattern.class : javax.validation.constraints.Pattern.class;
        JAnnotationUse annotation = field.annotate(patternClass);
        annotation.param("regexp", node.asText());
    }
    return field;
}
Also used : JAnnotationUse(com.sun.codemodel.JAnnotationUse)

Aggregations

JAnnotationUse (com.sun.codemodel.JAnnotationUse)16 JClass (com.sun.codemodel.JClass)4 JCodeModel (com.sun.codemodel.JCodeModel)3 JDefinedClass (com.sun.codemodel.JDefinedClass)3 JMethod (com.sun.codemodel.JMethod)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 JaxWsAnnotationProcessor (org.eclipse.scout.jaxws.apt.JaxWsAnnotationProcessor)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 JAnnotationArrayMember (com.sun.codemodel.JAnnotationArrayMember)1 JBlock (com.sun.codemodel.JBlock)1 JConditional (com.sun.codemodel.JConditional)1 JFieldVar (com.sun.codemodel.JFieldVar)1 JInvocation (com.sun.codemodel.JInvocation)1 WebService (javax.jws.WebService)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 AnnotationValue (javax.lang.model.element.AnnotationValue)1 WebServiceClient (javax.xml.ws.WebServiceClient)1 LogicalMessageContext (javax.xml.ws.handler.LogicalMessageContext)1