Search in sources :

Example 1 with WebMethod

use of com.webcohesion.enunciate.modules.jaxws.model.WebMethod in project enunciate by stoicflame.

the class ResponseDocumentQNameMethod method exec.

/**
 * Gets the client-side package for the type, type declaration, package, or their string values.
 *
 * @param list The arguments.
 * @return The string value of the client-side package.
 */
public Object exec(List list) throws TemplateModelException {
    if (list.size() < 1) {
        throw new TemplateModelException("The responseDocumentQName method method must have a web method as a parameter.");
    }
    TemplateModel from = (TemplateModel) list.get(0);
    Object unwrapped = FreemarkerUtil.unwrap(from);
    if (!(unwrapped instanceof WebMethod)) {
        throw new TemplateModelException("A web method must be provided.");
    }
    WebMethod webMethod = (WebMethod) unwrapped;
    if (webMethod.getSoapBindingStyle() != SOAPBinding.Style.DOCUMENT || webMethod.getSoapUse() != SOAPBinding.Use.LITERAL) {
        throw new TemplateModelException("No response document qname available for a " + webMethod.getSoapBindingStyle() + "/" + webMethod.getSoapUse() + " web method.");
    }
    if (webMethod.getResponseWrapper() != null) {
        return new QName(webMethod.getResponseWrapper().getElementNamespace(), webMethod.getResponseWrapper().getElementName());
    } else if (webMethod.getSoapParameterStyle() == SOAPBinding.ParameterStyle.BARE) {
        WebResult wr = webMethod.getWebResult();
        if (!wr.isHeader()) {
            return new QName(wr.getTargetNamespace(), wr.getElementName());
        }
    }
    return null;
}
Also used : WebMethod(com.webcohesion.enunciate.modules.jaxws.model.WebMethod) TemplateModelException(freemarker.template.TemplateModelException) QName(javax.xml.namespace.QName) TemplateModel(freemarker.template.TemplateModel) WebResult(com.webcohesion.enunciate.modules.jaxws.model.WebResult)

Example 2 with WebMethod

use of com.webcohesion.enunciate.modules.jaxws.model.WebMethod in project enunciate by stoicflame.

the class WsdlInfo method getWebMessages.

public List<WebMessage> getWebMessages() {
    ArrayList<WebMessage> messages = new ArrayList<WebMessage>();
    HashSet<String> foundFaults = new HashSet<String>();
    for (EndpointInterface ei : getEndpointInterfaces()) {
        Collection<WebMethod> webMethods = ei.getWebMethods();
        for (WebMethod method : webMethods) {
            for (WebMessage webMessage : method.getMessages()) {
                if (webMessage.isFault() && !foundFaults.add(((WebFault) webMessage).getQualifiedName().toString())) {
                    continue;
                }
                messages.add(webMessage);
            }
        }
    }
    return messages;
}
Also used : EndpointInterface(com.webcohesion.enunciate.modules.jaxws.model.EndpointInterface) WebMethod(com.webcohesion.enunciate.modules.jaxws.model.WebMethod) WebFault(com.webcohesion.enunciate.modules.jaxws.model.WebFault) WebMessage(com.webcohesion.enunciate.modules.jaxws.model.WebMessage)

Example 3 with WebMethod

use of com.webcohesion.enunciate.modules.jaxws.model.WebMethod in project enunciate by stoicflame.

the class CSharpXMLClientModule method usesUnmappableElements.

protected boolean usesUnmappableElements() {
    boolean usesUnmappableElements = false;
    if (this.jaxwsModule != null && this.jaxwsModule.getJaxwsContext() != null) {
        for (EndpointInterface ei : this.jaxwsModule.getJaxwsContext().getEndpointInterfaces()) {
            Map<String, javax.lang.model.element.Element> paramsByName = new HashMap<String, javax.lang.model.element.Element>();
            for (WebMethod webMethod : ei.getWebMethods()) {
                for (WebParam webParam : webMethod.getWebParameters()) {
                    // no out or in/out non-header parameters!
                    if (webParam.isHeader()) {
                        // unique parameter names for all header parameters of a given ei
                        javax.lang.model.element.Element conflict = paramsByName.put(webParam.getElementName(), webParam);
                        if (conflict != null) {
                            warn("%s: C# requires that all header parameters defined in the same endpoint interface have unique names. This parameter conflicts with the one at %s.", positionOf(webParam), positionOf(conflict));
                            usesUnmappableElements = true;
                        }
                        DecoratedTypeMirror paramType = (DecoratedTypeMirror) webParam.getType();
                        if (paramType.isCollection()) {
                            warn("%s: C# can't handle header parameters that are collections.", positionOf(webParam));
                            usesUnmappableElements = true;
                        }
                    } else if (webParam.getMode() != javax.jws.WebParam.Mode.IN) {
                        warn("%s: C# doesn't support non-header parameters of mode %s.", positionOf(webParam), webParam.getMode());
                        usesUnmappableElements = true;
                    }
                    // parameters/results can't be maps
                    if (webParam.getType() instanceof MapType) {
                        warn("%s: C# can't handle parameter types that are maps.", positionOf(webParam));
                        usesUnmappableElements = true;
                    }
                }
                // web result cannot be a header.
                if (webMethod.getWebResult().isHeader()) {
                    javax.lang.model.element.Element conflict = paramsByName.put(webMethod.getWebResult().getElementName(), webMethod);
                    if (conflict != null) {
                        warn("%s: C# requires that all header parameters defined in the same endpoint interface have unique names. This return parameter conflicts with the one at %s.", positionOf(webMethod), positionOf(conflict));
                        usesUnmappableElements = true;
                    }
                }
                if (webMethod.getWebResult().getType() instanceof MapType) {
                    warn("%s: C# can't handle return types that are maps.", positionOf(webMethod));
                    usesUnmappableElements = true;
                }
                if (ElementUtils.capitalize(webMethod.getClientSimpleName()).equals(ei.getClientSimpleName())) {
                    warn("%s: C# can't handle methods that are of the same name as their containing class. Either rename the method, or use the @org.codehaus.enunciate.ClientName annotation to rename the method (or type) on the client-side.", positionOf(webMethod));
                    usesUnmappableElements = true;
                }
            }
        }
    }
    if (this.jaxbModule != null && this.jaxbModule.getJaxbContext() != null && !this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
        for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
            for (TypeDefinition complexType : schemaInfo.getTypeDefinitions()) {
                for (Attribute attribute : complexType.getAttributes()) {
                    if (ElementUtils.capitalize(attribute.getClientSimpleName()).equals(complexType.getClientSimpleName())) {
                        warn("%s: C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename the property/field on the client-side.", positionOf(attribute));
                        usesUnmappableElements = true;
                    }
                }
                if (complexType.getValue() != null) {
                    if (ElementUtils.capitalize(complexType.getValue().getClientSimpleName()).equals(complexType.getClientSimpleName())) {
                        warn("%s: C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename the property/field on the client-side.", positionOf(complexType.getValue()));
                        usesUnmappableElements = true;
                    }
                }
                for (Element element : complexType.getElements()) {
                    if (ElementUtils.capitalize(element.getClientSimpleName()).equals(complexType.getClientSimpleName())) {
                        warn("%s: C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename the property/field on the client-side.", positionOf(element));
                        usesUnmappableElements = true;
                    }
                    if (element.getAccessorType() instanceof MapType && !element.isAdapted()) {
                        warn("%s: The C# client doesn't have a built-in way of serializing a Map. Use @XmlJavaTypeAdapter to supply your own adapter for the Map.", positionOf(element));
                        usesUnmappableElements = true;
                    }
                }
                if (complexType instanceof EnumTypeDefinition) {
                    List<VariableElement> enums = complexType.enumValues();
                    for (VariableElement enumItem : enums) {
                        if (isIgnored(enumItem)) {
                            continue;
                        }
                        String simpleName = enumItem.getSimpleName().toString();
                        ClientName clientNameInfo = enumItem.getAnnotation(ClientName.class);
                        if (clientNameInfo != null) {
                            simpleName = clientNameInfo.value();
                        }
                        if ("event".equals(simpleName)) {
                            warn("%s: C# can't handle an enum constant named 'Event'. Either rename the enum constant, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename it on the client-side.", positionOf(enumItem));
                            usesUnmappableElements = true;
                        } else if (simpleName.equals(complexType.getClientSimpleName())) {
                            warn("C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename the property/field on the client-side.", positionOf(enumItem));
                            usesUnmappableElements = true;
                        }
                    }
                }
                if (ElementUtils.isMap(complexType)) {
                    warn("%s: C# client doesn't handles types that implement java.util.Map. Use @XmlJavaTypeAdapter to supply your own adapter for the Map.", positionOf(complexType));
                    usesUnmappableElements = true;
                }
            }
        }
    }
    return usesUnmappableElements;
}
Also used : DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) VariableElement(javax.lang.model.element.VariableElement) VariableElement(javax.lang.model.element.VariableElement) MapType(com.webcohesion.enunciate.modules.jaxb.model.util.MapType) EndpointInterface(com.webcohesion.enunciate.modules.jaxws.model.EndpointInterface) WebMethod(com.webcohesion.enunciate.modules.jaxws.model.WebMethod) WebParam(com.webcohesion.enunciate.modules.jaxws.model.WebParam) ClientName(com.webcohesion.enunciate.metadata.ClientName) com.webcohesion.enunciate.modules.jaxb.model(com.webcohesion.enunciate.modules.jaxb.model)

Example 4 with WebMethod

use of com.webcohesion.enunciate.modules.jaxws.model.WebMethod in project enunciate by stoicflame.

the class RequestDocumentQNameMethod method exec.

/**
 * Gets the client-side package for the type, type declaration, package, or their string values.
 *
 * @param list The arguments.
 * @return The string value of the client-side package.
 */
public Object exec(List list) throws TemplateModelException {
    if (list.size() < 1) {
        throw new TemplateModelException("The requestQName method method must have a web method as a parameter.");
    }
    TemplateModel from = (TemplateModel) list.get(0);
    Object unwrapped = FreemarkerUtil.unwrap(from);
    if (!(unwrapped instanceof WebMethod)) {
        throw new TemplateModelException("A web method must be provided.");
    }
    WebMethod webMethod = (WebMethod) unwrapped;
    if (webMethod.getSoapBindingStyle() != SOAPBinding.Style.DOCUMENT || webMethod.getSoapUse() != SOAPBinding.Use.LITERAL) {
        throw new TemplateModelException("No request document qname available for a " + webMethod.getSoapBindingStyle() + "/" + webMethod.getSoapUse() + " web method.");
    }
    if (webMethod.getRequestWrapper() != null) {
        return new QName(webMethod.getRequestWrapper().getElementNamespace(), webMethod.getRequestWrapper().getElementName());
    } else if (webMethod.getSoapParameterStyle() == SOAPBinding.ParameterStyle.BARE) {
        Collection<WebParam> params = webMethod.getWebParameters();
        for (WebParam param : params) {
            if (!param.isHeader()) {
                return new QName(webMethod.getDeclaringEndpointInterface().getTargetNamespace(), param.getElementName());
            }
        }
    }
    return null;
}
Also used : WebMethod(com.webcohesion.enunciate.modules.jaxws.model.WebMethod) TemplateModelException(freemarker.template.TemplateModelException) WebParam(com.webcohesion.enunciate.modules.jaxws.model.WebParam) QName(javax.xml.namespace.QName) Collection(java.util.Collection) TemplateModel(freemarker.template.TemplateModel)

Example 5 with WebMethod

use of com.webcohesion.enunciate.modules.jaxws.model.WebMethod in project enunciate by stoicflame.

the class EnunciateJaxwsContext method add.

/**
 * Add an endpoint interface to the model.
 *
 * @param ei The endpoint interface to add to the model.
 */
public void add(EndpointInterface ei) {
    String namespace = ei.getTargetNamespace();
    String prefix = this.jaxbContext.addNamespace(namespace);
    WsdlInfo wsdlInfo = wsdls.get(namespace);
    if (wsdlInfo == null) {
        wsdlInfo = new WsdlInfo(jaxbContext);
        wsdlInfo.setId(prefix);
        wsdls.put(namespace, wsdlInfo);
        wsdlInfo.setTargetNamespace(namespace);
    }
    for (WebMethod webMethod : ei.getWebMethods()) {
        for (WebMessage webMessage : webMethod.getMessages()) {
            for (WebMessagePart messagePart : webMessage.getParts()) {
                if (messagePart.isImplicitSchemaElement()) {
                    ImplicitSchemaElement implicitElement = (ImplicitSchemaElement) messagePart;
                    String particleNamespace = messagePart.getParticleQName().getNamespaceURI();
                    SchemaInfo schemaInfo = this.jaxbContext.getSchemas().get(particleNamespace);
                    if (schemaInfo == null) {
                        schemaInfo = new SchemaInfo(this.jaxbContext);
                        schemaInfo.setId(this.jaxbContext.addNamespace(particleNamespace));
                        schemaInfo.setNamespace(particleNamespace);
                        this.jaxbContext.getSchemas().put(particleNamespace, schemaInfo);
                    }
                    schemaInfo.getImplicitSchemaElements().add(implicitElement);
                }
            }
        }
    }
    wsdlInfo.getEndpointInterfaces().add(ei);
    this.endpointInterfaces.add(ei);
    debug("Added %s as a JAX-WS endpoint interface.", ei.getQualifiedName());
    if (getContext().getProcessingEnvironment().findSourcePosition(ei) == null) {
        OneTimeLogMessage.SOURCE_FILES_NOT_FOUND.log(getContext());
        if (OneTimeLogMessage.SOURCE_FILES_NOT_FOUND.getLogged() <= 3) {
            info("Unable to find source file for %s.", ei.getQualifiedName());
        } else {
            debug("Unable to find source file for %s.", ei.getQualifiedName());
        }
    }
}
Also used : WebMethod(com.webcohesion.enunciate.modules.jaxws.model.WebMethod) ImplicitSchemaElement(com.webcohesion.enunciate.modules.jaxb.model.ImplicitSchemaElement) WebMessagePart(com.webcohesion.enunciate.modules.jaxws.model.WebMessagePart) WebMessage(com.webcohesion.enunciate.modules.jaxws.model.WebMessage) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)

Aggregations

WebMethod (com.webcohesion.enunciate.modules.jaxws.model.WebMethod)6 EndpointInterface (com.webcohesion.enunciate.modules.jaxws.model.EndpointInterface)2 WebMessage (com.webcohesion.enunciate.modules.jaxws.model.WebMessage)2 WebParam (com.webcohesion.enunciate.modules.jaxws.model.WebParam)2 TemplateModel (freemarker.template.TemplateModel)2 TemplateModelException (freemarker.template.TemplateModelException)2 QName (javax.xml.namespace.QName)2 Operation (com.webcohesion.enunciate.api.services.Operation)1 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)1 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)1 ClientName (com.webcohesion.enunciate.metadata.ClientName)1 com.webcohesion.enunciate.modules.jaxb.model (com.webcohesion.enunciate.modules.jaxb.model)1 ImplicitSchemaElement (com.webcohesion.enunciate.modules.jaxb.model.ImplicitSchemaElement)1 SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)1 MapType (com.webcohesion.enunciate.modules.jaxb.model.util.MapType)1 WebFault (com.webcohesion.enunciate.modules.jaxws.model.WebFault)1 WebMessagePart (com.webcohesion.enunciate.modules.jaxws.model.WebMessagePart)1 WebResult (com.webcohesion.enunciate.modules.jaxws.model.WebResult)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1