Search in sources :

Example 1 with WebParam

use of com.webcohesion.enunciate.modules.jaxws.model.WebParam 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 2 with WebParam

use of com.webcohesion.enunciate.modules.jaxws.model.WebParam 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)

Aggregations

WebMethod (com.webcohesion.enunciate.modules.jaxws.model.WebMethod)2 WebParam (com.webcohesion.enunciate.modules.jaxws.model.WebParam)2 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 MapType (com.webcohesion.enunciate.modules.jaxb.model.util.MapType)1 EndpointInterface (com.webcohesion.enunciate.modules.jaxws.model.EndpointInterface)1 TemplateModel (freemarker.template.TemplateModel)1 TemplateModelException (freemarker.template.TemplateModelException)1 Collection (java.util.Collection)1 VariableElement (javax.lang.model.element.VariableElement)1 QName (javax.xml.namespace.QName)1