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());
}
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();
}
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));
}
}
}
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);
}
}
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;
}
Aggregations