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