Search in sources :

Example 1 with PortType

use of com.sun.tools.ws.wsdl.document.PortType in project metro-jax-ws by eclipse-ee4j.

the class SeiGenerator method write.

private void write(Port port) {
    JavaInterface intf = port.getJavaInterface();
    String className = Names.customJavaTypeClassName(intf);
    if (donotOverride && GeneratorUtil.classExists(options, className)) {
        log("Class " + className + " exists. Not overriding.");
        return;
    }
    JDefinedClass cls;
    try {
        cls = getClass(className, ClassType.INTERFACE);
    } catch (JClassAlreadyExistsException e) {
        QName portTypeName = (QName) port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
        Locator loc = null;
        if (portTypeName != null) {
            PortType pt = port.portTypes.get(portTypeName);
            if (pt != null) {
                loc = pt.getLocator();
            }
        }
        receiver.error(loc, GeneratorMessages.GENERATOR_SEI_CLASS_ALREADY_EXIST(intf.getName(), portTypeName));
        return;
    }
    // so skip it.
    if (!cls.methods().isEmpty()) {
        return;
    }
    // write class comment - JAXWS warning
    JDocComment comment = cls.javadoc();
    String ptDoc = intf.getJavaDoc();
    if (ptDoc != null) {
        comment.add(ptDoc);
        comment.add("\n\n");
    }
    comment.addAll(getJAXWSClassComment());
    // @WebService
    JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class));
    writeWebServiceAnnotation(port, webServiceAnn);
    // @HandlerChain
    writeHandlerConfig(Names.customJavaTypeClassName(port.getJavaInterface()), cls, options);
    // @SOAPBinding
    writeSOAPBinding(port, cls);
    // @XmlSeeAlso
    if (options.target.isLaterThan(Options.Target.V2_1)) {
        writeXmlSeeAlso(cls);
    }
    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);
        }
        writeWebMethod(operation, m);
        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());
            }
            // annotate parameter with JAXB annotations
            paramType.annotate(var);
            methodDoc.addParam(var);
            JAnnotationUse paramAnn = var.annotate(cm.ref(WebParam.class));
            writeWebParam(operation, parameter, paramAnn);
        }
        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());
        }
        // It should be the last thing to invoke after JMethod is built completely
        extension.writeMethodAnnotations(wsdlOp, m);
    }
}
Also used : JavaInterface(com.sun.tools.ws.processor.model.java.JavaInterface) WebService(jakarta.jws.WebService) QName(javax.xml.namespace.QName) JAXBTypeAndAnnotation(com.sun.tools.ws.processor.model.jaxb.JAXBTypeAndAnnotation) Locator(org.xml.sax.Locator) WebParam(jakarta.jws.WebParam) JavaMethod(com.sun.tools.ws.processor.model.java.JavaMethod) JavaParameter(com.sun.tools.ws.processor.model.java.JavaParameter) PortType(com.sun.tools.ws.wsdl.document.PortType)

Example 2 with PortType

use of com.sun.tools.ws.wsdl.document.PortType in project metro-jax-ws by eclipse-ee4j.

the class ServiceGenerator method visit.

@Override
public void visit(Service service) {
    JavaInterface intf = service.getJavaInterface();
    String className = Names.customJavaTypeClassName(intf);
    if (donotOverride && GeneratorUtil.classExists(options, className)) {
        log("Class " + className + " exists. Not overriding.");
        return;
    }
    JDefinedClass cls;
    try {
        cls = getClass(className, ClassType.CLASS);
    } catch (JClassAlreadyExistsException e) {
        receiver.error(service.getLocator(), GeneratorMessages.GENERATOR_SERVICE_CLASS_ALREADY_EXIST(className, service.getName()));
        return;
    }
    cls._extends(jakarta.xml.ws.Service.class);
    String serviceFieldName = BindingHelper.mangleNameToClassName(service.getName().getLocalPart()).toUpperCase(Locale.ENGLISH);
    String wsdlLocationName = serviceFieldName + "_WSDL_LOCATION";
    JFieldVar urlField = cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, URL.class, wsdlLocationName);
    JFieldVar exField = cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, WebServiceException.class, serviceFieldName + "_EXCEPTION");
    String serviceName = serviceFieldName + "_QNAME";
    cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, QName.class, serviceName, JExpr._new(cm.ref(QName.class)).arg(service.getName().getNamespaceURI()).arg(service.getName().getLocalPart()));
    JClass qNameCls = cm.ref(QName.class);
    JInvocation inv;
    inv = JExpr._new(qNameCls);
    inv.arg("namespace");
    inv.arg("localpart");
    if (options.useBaseResourceAndURLToLoadWSDL) {
        writeClassLoaderBaseResourceWSDLLocation(className, cls, urlField, exField);
    } else if (wsdlLocation.startsWith("http://") || wsdlLocation.startsWith("https://") || wsdlLocation.startsWith("file:/")) {
        writeAbsWSDLLocation(cls, urlField, exField);
    } else if (wsdlLocation.startsWith("META-INF/")) {
        writeClassLoaderResourceWSDLLocation(className, cls, urlField, exField);
    } else {
        writeResourceWSDLLocation(className, cls, urlField, exField);
    }
    // write class comment - JAXWS warning
    JDocComment comment = cls.javadoc();
    if (service.getJavaDoc() != null) {
        comment.add(service.getJavaDoc());
        comment.add("\n\n");
    }
    comment.addAll(getJAXWSClassComment());
    // Generating constructor
    // for e.g:  public ExampleService()
    JMethod constructor1 = cls.constructor(JMod.PUBLIC);
    String constructor1Str = String.format("super(__getWsdlLocation(), %s);", serviceName);
    constructor1.body().directStatement(constructor1Str);
    // for e.g:  public ExampleService(WebServiceFeature ... features)
    if (options.target.isLaterThan(Options.Target.V2_2)) {
        JMethod constructor2 = cls.constructor(JMod.PUBLIC);
        constructor2.varParam(WebServiceFeature.class, "features");
        String constructor2Str = String.format("super(__getWsdlLocation(), %s, features);", serviceName);
        constructor2.body().directStatement(constructor2Str);
    }
    // for e.g:  public ExampleService(URL wsdlLocation)
    if (options.target.isLaterThan(Options.Target.V2_2)) {
        JMethod constructor3 = cls.constructor(JMod.PUBLIC);
        constructor3.param(URL.class, "wsdlLocation");
        String constructor3Str = String.format("super(wsdlLocation, %s);", serviceName);
        constructor3.body().directStatement(constructor3Str);
    }
    // for e.g:  public ExampleService(URL wsdlLocation, WebServiceFeature ... features)
    if (options.target.isLaterThan(Options.Target.V2_2)) {
        JMethod constructor4 = cls.constructor(JMod.PUBLIC);
        constructor4.param(URL.class, "wsdlLocation");
        constructor4.varParam(WebServiceFeature.class, "features");
        String constructor4Str = String.format("super(wsdlLocation, %s, features);", serviceName);
        constructor4.body().directStatement(constructor4Str);
    }
    // Generating constructor
    // for e.g:  public ExampleService(URL wsdlLocation, QName serviceName)
    JMethod constructor5 = cls.constructor(JMod.PUBLIC);
    constructor5.param(URL.class, "wsdlLocation");
    constructor5.param(QName.class, "serviceName");
    constructor5.body().directStatement("super(wsdlLocation, serviceName);");
    // for e.g:  public ExampleService(URL, QName, WebServiceFeature ...)
    if (options.target.isLaterThan(Options.Target.V2_2)) {
        JMethod constructor6 = cls.constructor(JMod.PUBLIC);
        constructor6.param(URL.class, "wsdlLocation");
        constructor6.param(QName.class, "serviceName");
        constructor6.varParam(WebServiceFeature.class, "features");
        constructor6.body().directStatement("super(wsdlLocation, serviceName, features);");
    }
    // @WebService
    JAnnotationUse webServiceClientAnn = cls.annotate(cm.ref(WebServiceClient.class));
    writeWebServiceClientAnnotation(service, webServiceClientAnn);
    // additional annotations
    for (GeneratorExtension f : ServiceFinder.find(GeneratorExtension.class, ServiceLoader.load(GeneratorExtension.class))) {
        f.writeWebServiceClientAnnotation(options, cm, cls);
    }
    // @HandlerChain
    writeHandlerConfig(Names.customJavaTypeClassName(service.getJavaInterface()), cls, options);
    for (Port port : service.getPorts()) {
        if (port.isProvider()) {
            // No getXYZPort() for porvider based endpoint
            continue;
        }
        // Get the SEI class
        JType retType;
        try {
            retType = getClass(port.getJavaInterface().getName(), ClassType.INTERFACE);
        } catch (JClassAlreadyExistsException e) {
            QName portTypeName = (QName) port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
            Locator loc = null;
            if (portTypeName != null) {
                PortType pt = port.portTypes.get(portTypeName);
                if (pt != null) {
                    loc = pt.getLocator();
                }
            }
            receiver.error(loc, GeneratorMessages.GENERATOR_SEI_CLASS_ALREADY_EXIST(port.getJavaInterface().getName(), portTypeName));
            return;
        }
        // write getXyzPort()
        writeDefaultGetPort(port, retType, cls);
        // write getXyzPort(WebServicesFeature...)
        if (options.target.isLaterThan(Options.Target.V2_1)) {
            writeGetPort(port, retType, cls);
        }
    }
    writeGetWsdlLocation(cm.ref(URL.class), cls, urlField, exField);
}
Also used : JavaInterface(com.sun.tools.ws.processor.model.java.JavaInterface) JDefinedClass(com.sun.codemodel.JDefinedClass) QName(javax.xml.namespace.QName) JClass(com.sun.codemodel.JClass) Port(com.sun.tools.ws.processor.model.Port) JInvocation(com.sun.codemodel.JInvocation) WebServiceClient(jakarta.xml.ws.WebServiceClient) JDocComment(com.sun.codemodel.JDocComment) URL(java.net.URL) JClassAlreadyExistsException(com.sun.codemodel.JClassAlreadyExistsException) Locator(org.xml.sax.Locator) JFieldVar(com.sun.codemodel.JFieldVar) JAnnotationUse(com.sun.codemodel.JAnnotationUse) JMethod(com.sun.codemodel.JMethod) JType(com.sun.codemodel.JType) PortType(com.sun.tools.ws.wsdl.document.PortType)

Example 3 with PortType

use of com.sun.tools.ws.wsdl.document.PortType in project metro-jax-ws by eclipse-ee4j.

the class WSDLParser method parsePortType.

private PortType parsePortType(TWSDLParserContextImpl context, Definitions definitions, Element e) {
    context.push();
    context.registerNamespaces(e);
    PortType portType = new PortType(definitions, forest.locatorTable.getStartLocation(e), errReceiver);
    String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
    portType.setName(name);
    boolean gotDocumentation = false;
    for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext(); ) {
        Element e2 = Util.nextElement(iter);
        if (e2 == null)
            break;
        if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
            if (gotDocumentation) {
                errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
            }
            gotDocumentation = true;
            if (portType.getDocumentation() == null)
                portType.setDocumentation(getDocumentationFor(e2));
        } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_OPERATION)) {
            Operation op = parsePortTypeOperation(context, e2);
            op.setParent(portType);
            portType.add(op);
        } else {
            // possible extensibility element -- must live outside the WSDL namespace
            checkNotWsdlElement(e2);
            if (!handleExtension(context, portType, e2)) {
                checkNotWsdlRequired(e2);
            }
        }
    /*else {
                Util.fail(
                    "parsing.invalidElement",
                    e2.getTagName(),
                    e2.getNamespaceURI());
            }*/
    }
    context.pop();
    context.fireDoneParsingEntity(WSDLConstants.QNAME_PORT_TYPE, portType);
    return portType;
}
Also used : Element(org.w3c.dom.Element) Iterator(java.util.Iterator) BindingOperation(com.sun.tools.ws.wsdl.document.BindingOperation) Operation(com.sun.tools.ws.wsdl.document.Operation) PortType(com.sun.tools.ws.wsdl.document.PortType)

Example 4 with PortType

use of com.sun.tools.ws.wsdl.document.PortType in project metro-jax-ws by eclipse-ee4j.

the class WSDLParser method parseDefinitionsNoImport.

private Definitions parseDefinitionsNoImport(TWSDLParserContextImpl context, Document doc) {
    Element e = doc.getDocumentElement();
    // at this poinjt we expect a wsdl or schema document to be fully qualified
    if (e.getNamespaceURI() == null || (!e.getNamespaceURI().equals(WSDLConstants.NS_WSDL) || !e.getLocalName().equals("definitions"))) {
        return null;
    }
    context.push();
    context.registerNamespaces(e);
    Definitions definitions = new Definitions(context.getDocument(), forest.locatorTable.getStartLocation(e));
    String name = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAME);
    definitions.setName(name);
    String targetNamespaceURI = XmlUtil.getAttributeOrNull(e, Constants.ATTR_TARGET_NAMESPACE);
    definitions.setTargetNamespaceURI(targetNamespaceURI);
    boolean gotDocumentation = false;
    boolean gotTypes = false;
    for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext(); ) {
        Element e2 = Util.nextElement(iter);
        if (e2 == null)
            break;
        if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
            if (gotDocumentation) {
                errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
                return null;
            }
            gotDocumentation = true;
            if (definitions.getDocumentation() == null)
                definitions.setDocumentation(getDocumentationFor(e2));
        } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_TYPES)) {
            if (gotTypes && !options.isExtensionMode()) {
                errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_TYPES_ALLOWED(Constants.TAG_DEFINITIONS));
                return null;
            }
            gotTypes = true;
            // that will be needed to create jaxb model
            if (!options.isExtensionMode())
                validateSchemaImports(e2);
        } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_MESSAGE)) {
            Message message = parseMessage(context, definitions, e2);
            definitions.add(message);
        } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_PORT_TYPE)) {
            PortType portType = parsePortType(context, definitions, e2);
            definitions.add(portType);
        } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_BINDING)) {
            Binding binding = parseBinding(context, definitions, e2);
            definitions.add(binding);
        } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_SERVICE)) {
            Service service = parseService(context, definitions, e2);
            definitions.add(service);
        } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_IMPORT)) {
            definitions.add(parseImport(context, definitions, e2));
        } else if (XmlUtil.matchesTagNS(e2, SchemaConstants.QNAME_IMPORT)) {
            errReceiver.warning(forest.locatorTable.getStartLocation(e2), WsdlMessages.WARNING_WSI_R_2003());
        } else {
            // possible extensibility element -- must live outside the WSDL namespace
            checkNotWsdlElement(e2);
            if (!handleExtension(context, definitions, e2)) {
                checkNotWsdlRequired(e2);
            }
        }
    }
    context.pop();
    context.fireDoneParsingEntity(WSDLConstants.QNAME_DEFINITIONS, definitions);
    return definitions;
}
Also used : Binding(com.sun.tools.ws.wsdl.document.Binding) Message(com.sun.tools.ws.wsdl.document.Message) Element(org.w3c.dom.Element) Definitions(com.sun.tools.ws.wsdl.document.Definitions) Iterator(java.util.Iterator) Service(com.sun.tools.ws.wsdl.document.Service) PortType(com.sun.tools.ws.wsdl.document.PortType)

Aggregations

PortType (com.sun.tools.ws.wsdl.document.PortType)4 JavaInterface (com.sun.tools.ws.processor.model.java.JavaInterface)2 Iterator (java.util.Iterator)2 QName (javax.xml.namespace.QName)2 Element (org.w3c.dom.Element)2 Locator (org.xml.sax.Locator)2 JAnnotationUse (com.sun.codemodel.JAnnotationUse)1 JClass (com.sun.codemodel.JClass)1 JClassAlreadyExistsException (com.sun.codemodel.JClassAlreadyExistsException)1 JDefinedClass (com.sun.codemodel.JDefinedClass)1 JDocComment (com.sun.codemodel.JDocComment)1 JFieldVar (com.sun.codemodel.JFieldVar)1 JInvocation (com.sun.codemodel.JInvocation)1 JMethod (com.sun.codemodel.JMethod)1 JType (com.sun.codemodel.JType)1 Port (com.sun.tools.ws.processor.model.Port)1 JavaMethod (com.sun.tools.ws.processor.model.java.JavaMethod)1 JavaParameter (com.sun.tools.ws.processor.model.java.JavaParameter)1 JAXBTypeAndAnnotation (com.sun.tools.ws.processor.model.jaxb.JAXBTypeAndAnnotation)1 Binding (com.sun.tools.ws.wsdl.document.Binding)1