Search in sources :

Example 1 with ModelerException

use of com.sun.tools.ws.processor.modeler.ModelerException in project metro-jax-ws by eclipse-ee4j.

the class WebServiceApTest method testRemoteIfaceArg.

public void testRemoteIfaceArg() {
    options.add("-proc:only");
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
    WsgenOptions wsgenOptions = new WsgenOptions();
    wsgenOptions.verbose = true;
    JavaCompiler.CompilationTask task = getCompilationTask("com.sun.tools.ws.test.processor.modeler.annotation.RemoteArgTestWS", options, wsgenOptions, diagnostics);
    try {
        task.call();
    } catch (RuntimeException re) {
        if (!(re.getCause() instanceof ModelerException)) {
            fail(ModelerException.class.getName() + " should have been thrown - spec requirement");
        }
    }
}
Also used : ModelerException(com.sun.tools.ws.processor.modeler.ModelerException) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) JavaFileObject(javax.tools.JavaFileObject) WsgenOptions(com.sun.tools.ws.wscompile.WsgenOptions) JavaCompiler(javax.tools.JavaCompiler) DiagnosticCollector(javax.tools.DiagnosticCollector)

Example 2 with ModelerException

use of com.sun.tools.ws.processor.modeler.ModelerException in project metro-jax-ws by eclipse-ee4j.

the class WebServiceApTest method testRemoteIfaceReturn.

public void testRemoteIfaceReturn() {
    options.add("-proc:only");
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
    WsgenOptions wsgenOptions = new WsgenOptions();
    wsgenOptions.verbose = true;
    JavaCompiler.CompilationTask task = getCompilationTask("com.sun.tools.ws.test.processor.modeler.annotation.RemoteReturnTestWs", options, wsgenOptions, diagnostics);
    try {
        task.call();
    } catch (RuntimeException re) {
        if (!(re.getCause() instanceof ModelerException)) {
            fail(ModelerException.class.getName() + " should have been thrown - spec requirement");
        }
    }
}
Also used : ModelerException(com.sun.tools.ws.processor.modeler.ModelerException) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) JavaFileObject(javax.tools.JavaFileObject) WsgenOptions(com.sun.tools.ws.wscompile.WsgenOptions) JavaCompiler(javax.tools.JavaCompiler) DiagnosticCollector(javax.tools.DiagnosticCollector)

Example 3 with ModelerException

use of com.sun.tools.ws.processor.modeler.ModelerException in project metro-jax-ws by eclipse-ee4j.

the class ModelerExceptionTest method testLocalizability.

public void testLocalizability() {
    String msg = "Try localizing me";
    ModelerException pe = new ModelerException(msg);
    Localizer localizer = new Localizer();
    assertEquals(msg, localizer.localize(pe));
}
Also used : ModelerException(com.sun.tools.ws.processor.modeler.ModelerException) Localizer(com.sun.istack.localization.Localizer)

Example 4 with ModelerException

use of com.sun.tools.ws.processor.modeler.ModelerException in project metro-jax-ws by eclipse-ee4j.

the class WebServiceWrapperGenerator method generateWrappers.

private boolean generateWrappers(ExecutableElement method, WebMethod webMethod) {
    boolean isOneway = method.getAnnotation(Oneway.class) != null;
    String beanPackage = packageName + WebServiceConstants.PD_JAXWS_PACKAGE_PD.getValue();
    if (packageName.length() == 0)
        beanPackage = WebServiceConstants.JAXWS_PACKAGE_PD.getValue();
    Name methodName = method.getSimpleName();
    String operationName = builder.getOperationName(methodName);
    operationName = webMethod != null && webMethod.operationName().length() > 0 ? webMethod.operationName() : operationName;
    String reqName = operationName;
    String resName = operationName + WebServiceConstants.RESPONSE.getValue();
    String reqNamespace = typeNamespace;
    String resNamespace = typeNamespace;
    String requestClassName = beanPackage + StringUtils.capitalize(method.getSimpleName().toString());
    RequestWrapper reqWrapper = method.getAnnotation(RequestWrapper.class);
    if (reqWrapper != null) {
        if (reqWrapper.className().length() > 0)
            requestClassName = reqWrapper.className();
        if (reqWrapper.localName().length() > 0)
            reqName = reqWrapper.localName();
        if (reqWrapper.targetNamespace().length() > 0)
            reqNamespace = reqWrapper.targetNamespace();
    }
    builder.log("requestWrapper: " + requestClassName);
    boolean canOverwriteRequest = builder.canOverWriteClass(requestClassName);
    if (!canOverwriteRequest) {
        builder.log("Class " + requestClassName + " exists. Not overwriting.");
    }
    if (duplicateName(requestClassName) && canOverwriteRequest) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_REQUEST_WRAPPER_BEAN_NAME_NOT_UNIQUE(typeElement.getQualifiedName(), method.toString()));
    }
    String responseClassName = null;
    boolean canOverwriteResponse = canOverwriteRequest;
    if (!isOneway) {
        responseClassName = beanPackage + StringUtils.capitalize(method.getSimpleName().toString()) + WebServiceConstants.RESPONSE.getValue();
        ResponseWrapper resWrapper = method.getAnnotation(ResponseWrapper.class);
        if (resWrapper != null) {
            if (resWrapper.className().length() > 0)
                responseClassName = resWrapper.className();
            if (resWrapper.localName().length() > 0)
                resName = resWrapper.localName();
            if (resWrapper.targetNamespace().length() > 0)
                resNamespace = resWrapper.targetNamespace();
        }
        canOverwriteResponse = builder.canOverWriteClass(responseClassName);
        builder.log("responseWrapper: " + responseClassName);
        if (!canOverwriteResponse) {
            builder.log("Class " + responseClassName + " exists. Not overwriting.");
        }
        if (duplicateName(responseClassName) && canOverwriteResponse) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_RESPONSE_WRAPPER_BEAN_NAME_NOT_UNIQUE(typeElement.getQualifiedName(), method.toString()));
        }
    }
    // ArrayList<MemberInfo> reqMembers = new ArrayList<MemberInfo>();
    // ArrayList<MemberInfo> resMembers = new ArrayList<MemberInfo>();
    WrapperInfo reqWrapperInfo = new WrapperInfo(requestClassName);
    // reqWrapperInfo.setMembers(reqMembers);
    WrapperInfo resWrapperInfo = null;
    if (!isOneway) {
        resWrapperInfo = new WrapperInfo(responseClassName);
    // resWrapperInfo.setMembers(resMembers);
    }
    seiContext.setReqWrapperOperation(method, reqWrapperInfo);
    if (!isOneway)
        seiContext.setResWrapperOperation(method, resWrapperInfo);
    try {
        if (!canOverwriteRequest && !canOverwriteResponse) {
            return false;
        }
        JDefinedClass reqCls = null;
        if (canOverwriteRequest) {
            reqCls = getCMClass(requestClassName, ClassType.CLASS);
        }
        JDefinedClass resCls = null;
        if (!isOneway && canOverwriteResponse) {
            resCls = getCMClass(responseClassName, ClassType.CLASS);
        }
        // XMLElement Declarations
        writeXmlElementDeclaration(reqCls, reqName, reqNamespace);
        writeXmlElementDeclaration(resCls, resName, resNamespace);
        List<MemberInfo> reqMembers = ap_generator.collectRequestBeanMembers(method);
        List<MemberInfo> resMembers = ap_generator.collectResponseBeanMembers(method);
        // XmlType
        writeXmlTypeDeclaration(reqCls, reqName, reqNamespace, reqMembers);
        writeXmlTypeDeclaration(resCls, resName, resNamespace, resMembers);
        // class members
        writeMembers(reqCls, reqMembers);
        writeMembers(resCls, resMembers);
    } catch (Exception e) {
        throw new ModelerException("modeler.nestedGeneratorError", e);
    }
    return true;
}
Also used : ModelerException(com.sun.tools.ws.processor.modeler.ModelerException) Oneway(jakarta.jws.Oneway) JDefinedClass(com.sun.codemodel.JDefinedClass) RequestWrapper(jakarta.xml.ws.RequestWrapper) ResponseWrapper(jakarta.xml.ws.ResponseWrapper) MirroredTypeException(javax.lang.model.type.MirroredTypeException) WebServiceException(jakarta.xml.ws.WebServiceException) ModelerException(com.sun.tools.ws.processor.modeler.ModelerException) IOException(java.io.IOException) QName(javax.xml.namespace.QName) Name(javax.lang.model.element.Name)

Aggregations

ModelerException (com.sun.tools.ws.processor.modeler.ModelerException)4 WsgenOptions (com.sun.tools.ws.wscompile.WsgenOptions)2 DiagnosticCollector (javax.tools.DiagnosticCollector)2 JavaCompiler (javax.tools.JavaCompiler)2 JavaFileObject (javax.tools.JavaFileObject)2 SimpleJavaFileObject (javax.tools.SimpleJavaFileObject)2 JDefinedClass (com.sun.codemodel.JDefinedClass)1 Localizer (com.sun.istack.localization.Localizer)1 Oneway (jakarta.jws.Oneway)1 RequestWrapper (jakarta.xml.ws.RequestWrapper)1 ResponseWrapper (jakarta.xml.ws.ResponseWrapper)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 IOException (java.io.IOException)1 Name (javax.lang.model.element.Name)1 MirroredTypeException (javax.lang.model.type.MirroredTypeException)1 QName (javax.xml.namespace.QName)1