Search in sources :

Example 6 with WebService

use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.

the class WsgenOptions method validateEndpointClass.

/**
 * Get an implementation class annotated with @WebService annotation.
 */
private void validateEndpointClass() throws BadCommandLineException {
    Class clazz = null;
    for (String cls : endpoints) {
        clazz = getClass(cls);
        if (clazz == null)
            continue;
        if (clazz.isEnum() || clazz.isInterface() || clazz.isPrimitive()) {
            continue;
        }
        isImplClass = true;
        WebService webService = (WebService) clazz.getAnnotation(WebService.class);
        if (webService == null)
            continue;
        break;
    }
    if (clazz == null) {
        throw new BadCommandLineException(WscompileMessages.WSGEN_CLASS_NOT_FOUND(endpoints.get(0)));
    }
    if (!isImplClass) {
        throw new BadCommandLineException(WscompileMessages.WSGEN_CLASS_MUST_BE_IMPLEMENTATION_CLASS(clazz.getName()));
    }
    endpoint = clazz;
    validateBinding();
}
Also used : WebService(jakarta.jws.WebService)

Example 7 with WebService

use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.

the class WebServiceAp method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (context.getRound() != 1) {
        return true;
    }
    context.incrementRound();
    WebService webService;
    WebServiceProvider webServiceProvider;
    WebServiceVisitor webServiceVisitor = new WebServiceWrapperGenerator(this, context);
    boolean processedEndpoint = false;
    Collection<TypeElement> classes = new ArrayList<>();
    filterClasses(classes, roundEnv.getRootElements());
    for (TypeElement element : classes) {
        webServiceProvider = element.getAnnotation(WebServiceProvider.class);
        webService = element.getAnnotation(WebService.class);
        if (webServiceProvider != null) {
            if (webService != null) {
                processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_AND_WEBSERVICEPROVIDER(element.getQualifiedName()));
            }
            processedEndpoint = true;
        }
        if (webService == null) {
            continue;
        }
        element.accept(webServiceVisitor, null);
        processedEndpoint = true;
    }
    if (!processedEndpoint) {
        if (isCommandLineInvocation) {
            if (!ignoreNoWebServiceFoundWarning) {
                processWarning(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND());
            }
        } else {
            processError(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND());
        }
    }
    return true;
}
Also used : WebServiceProvider(jakarta.xml.ws.WebServiceProvider) WebService(jakarta.jws.WebService) TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList)

Example 8 with WebService

use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.

the class WebServiceVisitor method visitType.

@Override
public Void visitType(TypeElement e, Object o) {
    WebService webService = e.getAnnotation(WebService.class);
    if (!shouldProcessWebService(webService, e))
        return null;
    if (builder.checkAndSetProcessed(e))
        return null;
    typeElement = e;
    switch(e.getKind()) {
        case INTERFACE:
            {
                if (endpointInterfaceName != null && !endpointInterfaceName.equals(e.getQualifiedName())) {
                    builder.processError(WebserviceapMessages.WEBSERVICEAP_ENDPOINTINTERFACES_DO_NOT_MATCH(endpointInterfaceName, e.getQualifiedName()), e);
                }
                verifySeiAnnotations(webService, e);
                endpointInterfaceName = e.getQualifiedName();
                processingSei = true;
                preProcessWebService(webService, e);
                processWebService(webService, e);
                postProcessWebService(webService, e);
                break;
            }
        case CLASS:
            {
                typeElementSoapBinding = e.getAnnotation(SOAPBinding.class);
                if (serviceImplName == null)
                    serviceImplName = e.getQualifiedName();
                String endpointInterfaceName = webService != null ? webService.endpointInterface() : null;
                if (endpointInterfaceName != null && endpointInterfaceName.length() > 0) {
                    checkForInvalidImplAnnotation(e, SOAPBinding.class);
                    if (webService.name().length() > 0)
                        builder.processError(WebserviceapMessages.WEBSERVICEAP_ENDPOINTINTEFACE_PLUS_ELEMENT("name"), e);
                    endpointReferencesInterface = true;
                    verifyImplAnnotations(e);
                    inspectEndpointInterface(endpointInterfaceName, e);
                    serviceImplName = null;
                    return null;
                }
                processingSei = false;
                preProcessWebService(webService, e);
                processWebService(webService, e);
                serviceImplName = null;
                postProcessWebService(webService, e);
                serviceImplName = null;
                break;
            }
        default:
            break;
    }
    return null;
}
Also used : WebService(jakarta.jws.WebService) SOAPBinding(jakarta.jws.soap.SOAPBinding)

Example 9 with WebService

use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.

the class JwsImplGenerator method visit.

@Override
public void visit(Service service) {
    QName serviceName = service.getName();
    // process the ordered service only if it is defined
    if (options.implServiceName != null && !equalsNSOptional(options.implServiceName, serviceName))
        return;
    for (Port port : service.getPorts()) {
        if (port.isProvider()) {
            // Not generating for Provider based endpoint
            continue;
        }
        // Generate the impl class name according to
        // Xpath(/definitions/service/port[@name]);
        QName portName = port.getName();
        // process the ordered port only if it is defined
        if (options.implPortName != null && !equalsNSOptional(options.implPortName, portName))
            continue;
        String simpleClassName = serviceName.getLocalPart() + "_" + portName.getLocalPart() + "Impl";
        String className = makePackageQualified(simpleClassName);
        implFiles.add(className);
        if (donotOverride && GeneratorUtil.classExists(options, className)) {
            log("Class " + className + " exists. Not overriding.");
            return;
        }
        JDefinedClass cls = null;
        try {
            cls = getClass(className, ClassType.CLASS);
        } catch (JClassAlreadyExistsException e) {
            log("Class " + className + " generates failed. JClassAlreadyExistsException[" + className + "].");
            return;
        }
        // Each serviceImpl will implements one port interface
        JavaInterface portIntf = port.getJavaInterface();
        String portClassName = Names.customJavaTypeClassName(portIntf);
        JDefinedClass portCls = null;
        try {
            portCls = getClass(portClassName, ClassType.INTERFACE);
        } catch (JClassAlreadyExistsException e) {
            log("Class " + className + " generates failed. JClassAlreadyExistsException[" + portClassName + "].");
            return;
        }
        cls._implements(portCls);
        // create a default constructor
        cls.constructor(JMod.PUBLIC);
        // write class comment - JAXWS warning
        JDocComment comment = cls.javadoc();
        if (service.getJavaDoc() != null) {
            comment.add(service.getJavaDoc());
            comment.add("\n\n");
        }
        comment.addAll(getJAXWSClassComment());
        // @WebService
        JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class));
        writeWebServiceAnnotation(service, port, webServiceAnn);
        // @BindingType
        JAnnotationUse bindingTypeAnn = cls.annotate(cm.ref(BindingType.class));
        writeBindingTypeAnnotation(port, bindingTypeAnn);
        // extra annotation
        for (GeneratorExtension f : findService(GeneratorExtension.class)) {
            f.writeWebServiceAnnotation(model, cm, cls, port);
        }
        // WebMethods
        for (Operation operation : port.getOperations()) {
            JavaMethod method = operation.getJavaMethod();
            // @WebMethod
            JMethod m;
            JDocComment methodDoc;
            String methodJavaDoc = operation.getJavaDoc();
            if (method.getReturnType().getName().equals("void")) {
                m = cls.method(JMod.PUBLIC, void.class, method.getName());
                methodDoc = m.javadoc();
            } else {
                JAXBTypeAndAnnotation retType = method.getReturnType().getType();
                m = cls.method(JMod.PUBLIC, retType.getType(), method.getName());
                retType.annotate(m);
                methodDoc = m.javadoc();
                JCommentPart ret = methodDoc.addReturn();
                ret.add("returns " + retType.getName());
            }
            if (methodJavaDoc != null)
                methodDoc.add(methodJavaDoc);
            JClass holder = cm.ref(Holder.class);
            for (JavaParameter parameter : method.getParametersList()) {
                JVar var;
                JAXBTypeAndAnnotation paramType = parameter.getType().getType();
                if (parameter.isHolder()) {
                    var = m.param(holder.narrow(paramType.getType().boxify()), parameter.getName());
                } else {
                    var = m.param(paramType.getType(), parameter.getName());
                }
                methodDoc.addParam(var);
            }
            com.sun.tools.ws.wsdl.document.Operation wsdlOp = operation.getWSDLPortTypeOperation();
            for (Fault fault : operation.getFaultsSet()) {
                m._throws(fault.getExceptionClass());
                methodDoc.addThrows(fault.getExceptionClass());
                wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass());
            }
            m.body().block().directStatement("//replace with your impl here");
            m.body().block().directStatement(getReturnString(method.getReturnType().getName()));
        }
    }
}
Also used : JavaInterface(com.sun.tools.ws.processor.model.java.JavaInterface) JDefinedClass(com.sun.codemodel.JDefinedClass) WebService(jakarta.jws.WebService) QName(javax.xml.namespace.QName) Port(com.sun.tools.ws.processor.model.Port) JClass(com.sun.codemodel.JClass) JCommentPart(com.sun.codemodel.JCommentPart) Fault(com.sun.tools.ws.processor.model.Fault) Operation(com.sun.tools.ws.processor.model.Operation) JDocComment(com.sun.codemodel.JDocComment) JClassAlreadyExistsException(com.sun.codemodel.JClassAlreadyExistsException) JAXBTypeAndAnnotation(com.sun.tools.ws.processor.model.jaxb.JAXBTypeAndAnnotation) BindingType(jakarta.xml.ws.BindingType) JAnnotationUse(com.sun.codemodel.JAnnotationUse) JavaMethod(com.sun.tools.ws.processor.model.java.JavaMethod) JavaParameter(com.sun.tools.ws.processor.model.java.JavaParameter) JMethod(com.sun.codemodel.JMethod) JVar(com.sun.codemodel.JVar)

Aggregations

WebService (jakarta.jws.WebService)9 JavaInterface (com.sun.tools.ws.processor.model.java.JavaInterface)2 JavaMethod (com.sun.tools.ws.processor.model.java.JavaMethod)2 JavaParameter (com.sun.tools.ws.processor.model.java.JavaParameter)2 JAXBTypeAndAnnotation (com.sun.tools.ws.processor.model.jaxb.JAXBTypeAndAnnotation)2 AsyncProvider (com.sun.xml.ws.api.server.AsyncProvider)2 ReflectAnnotationReader (com.sun.xml.ws.model.ReflectAnnotationReader)2 Provider (jakarta.xml.ws.Provider)2 WebServiceProvider (jakarta.xml.ws.WebServiceProvider)2 QName (javax.xml.namespace.QName)2 DatabindingModeFeature (com.oracle.webservices.api.databinding.DatabindingModeFeature)1 ExternalMetadataFeature (com.oracle.webservices.api.databinding.ExternalMetadataFeature)1 JAnnotationUse (com.sun.codemodel.JAnnotationUse)1 JClass (com.sun.codemodel.JClass)1 JClassAlreadyExistsException (com.sun.codemodel.JClassAlreadyExistsException)1 JCommentPart (com.sun.codemodel.JCommentPart)1 JDefinedClass (com.sun.codemodel.JDefinedClass)1 JDocComment (com.sun.codemodel.JDocComment)1 JMethod (com.sun.codemodel.JMethod)1 JVar (com.sun.codemodel.JVar)1