Search in sources :

Example 11 with ClientName

use of com.webcohesion.enunciate.metadata.ClientName in project enunciate by stoicflame.

the class TypeNameForMethod method convert.

@Override
public String convert(TypeElement declaration) throws TemplateModelException {
    String fqn = declaration.getQualifiedName().toString();
    if (classConversions.containsKey(fqn)) {
        return classConversions.get(fqn);
    } else if (declaration.getKind() == ElementKind.ENUM) {
        return "string";
    } else if (isCollection(declaration) || isMap(declaration)) {
        return "array";
    }
    AdapterType adapterType = JAXBUtil.findAdapterType(declaration, this.jaxbContext);
    if (adapterType != null) {
        return convert(adapterType.getAdaptingType());
    }
    String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
    ClientName specifiedName = declaration.getAnnotation(ClientName.class);
    String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
    return "\\" + convertedPackage + getPackageSeparator() + simpleName;
}
Also used : ClientName(com.webcohesion.enunciate.metadata.ClientName) AdapterType(com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType)

Example 12 with ClientName

use of com.webcohesion.enunciate.metadata.ClientName 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 13 with ClientName

use of com.webcohesion.enunciate.metadata.ClientName in project enunciate by stoicflame.

the class ClientClassnameForMethod method convert.

@Override
public String convert(TypeElement declaration) throws TemplateModelException {
    String fqn = declaration.getQualifiedName().toString();
    if (classConversions.containsKey(fqn)) {
        return classConversions.get(fqn);
    } else if (isCollection(declaration)) {
        return "global::System.Collections.ArrayList";
    }
    AdapterType adapterType = JAXBUtil.findAdapterType(declaration, this.jaxbContext);
    if (adapterType != null) {
        return convert(adapterType.getAdaptingType());
    }
    if (declaration.getKind() == ElementKind.CLASS) {
        DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment());
        if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) {
            // for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement
            return convert(superType);
        }
    }
    String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
    ClientName specifiedName = declaration.getAnnotation(ClientName.class);
    String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
    return convertedPackage + getPackageSeparator() + simpleName;
}
Also used : ClientName(com.webcohesion.enunciate.metadata.ClientName) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) AdapterType(com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType)

Example 14 with ClientName

use of com.webcohesion.enunciate.metadata.ClientName in project enunciate by stoicflame.

the class EndpointImplementation method getClientSimpleName.

/**
 * The simple name for client-side code generation.
 *
 * @return The simple name for client-side code generation.
 */
public String getClientSimpleName() {
    String clientSimpleName = getSimpleName().toString();
    ClientName clientName = getAnnotation(ClientName.class);
    if (clientName != null) {
        clientSimpleName = clientName.value();
    }
    return clientSimpleName;
}
Also used : ClientName(com.webcohesion.enunciate.metadata.ClientName)

Example 15 with ClientName

use of com.webcohesion.enunciate.metadata.ClientName in project enunciate by stoicflame.

the class ClientClassnameForMethod method convert.

@Override
public String convert(TypeElement declaration) throws TemplateModelException {
    if (classConversions.containsKey(declaration.getQualifiedName().toString())) {
        return classConversions.get(declaration.getQualifiedName().toString());
    } else if (isCollection(declaration)) {
        return "com.google.gwt.core.client.JsArray";
    }
    TypeMirror adaptingType = jsonContext.findAdaptingType(declaration);
    if (adaptingType != null) {
        return convert(adaptingType);
    }
    if (declaration.getKind() == ElementKind.CLASS) {
        DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment());
        if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) {
            // for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement
            return convert(superType);
        }
    }
    String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
    ClientName specifiedName = declaration.getAnnotation(ClientName.class);
    String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
    return convertedPackage + getPackageSeparator() + simpleName;
}
Also used : ClientName(com.webcohesion.enunciate.metadata.ClientName) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)

Aggregations

ClientName (com.webcohesion.enunciate.metadata.ClientName)31 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)7 AdapterType (com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType)6 AdapterType (com.webcohesion.enunciate.modules.jackson.model.adapters.AdapterType)5 EnumTypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition)2 EnumValue (com.webcohesion.enunciate.modules.jaxb.model.EnumValue)2 TemplateModelException (freemarker.template.TemplateModelException)2 PackageElement (javax.lang.model.element.PackageElement)2 TypeMirror (javax.lang.model.type.TypeMirror)2 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 WebMethod (com.webcohesion.enunciate.modules.jaxws.model.WebMethod)1 WebParam (com.webcohesion.enunciate.modules.jaxws.model.WebParam)1 VariableElement (javax.lang.model.element.VariableElement)1