Search in sources :

Example 1 with ClientName

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

the class EndpointInterface 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 2 with ClientName

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

the class NameForEnumConstantMethod method exec.

public Object exec(List list) throws TemplateModelException {
    if (list.size() < 1) {
        throw new TemplateModelException("The nameForEnumConstant method must have an enum type definition and an enum constant declaration as parameters.");
    }
    Object unwrapped = FreemarkerUtil.unwrap((TemplateModel) list.get(0));
    if (!(unwrapped instanceof EnumValue)) {
        throw new TemplateModelException("The nameForEnumConstant method must have an enum value as a parameter.");
    }
    EnumValue enumValue = (EnumValue) unwrapped;
    EnumTypeDefinition typeDefinition = enumValue.getTypeDefinition();
    String name = CXMLClientModule.scrubIdentifier(typeDefinition.getName());
    String simpleName = CXMLClientModule.scrubIdentifier(typeDefinition.getSimpleName().toString());
    String clientName = CXMLClientModule.scrubIdentifier(typeDefinition.getClientSimpleName());
    String simpleNameDecap = CXMLClientModule.scrubIdentifier(Introspector.decapitalize(simpleName));
    String clientNameDecap = CXMLClientModule.scrubIdentifier(Introspector.decapitalize(clientName));
    if (name == null) {
        name = "anonymous_" + clientNameDecap;
    }
    PackageElement pckg = typeDefinition.getPackage().getDelegate();
    String packageUnderscored = CXMLClientModule.scrubIdentifier(pckg != null ? pckg.getQualifiedName().toString().replace('.', '_') : "");
    String nsid = CXMLClientModule.scrubIdentifier(namespaces2ids.get(typeDefinition.getNamespace()));
    String constantName = CXMLClientModule.scrubIdentifier(enumValue.getSimpleName().toString());
    String constantClientName = CXMLClientModule.scrubIdentifier(enumValue.getAnnotation(ClientName.class) != null ? enumValue.getAnnotation(ClientName.class).value() : constantName);
    return String.format(this.pattern, this.projectLabel, nsid, name, clientName, clientNameDecap, simpleName, simpleNameDecap, packageUnderscored, constantClientName, constantName);
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) ClientName(com.webcohesion.enunciate.metadata.ClientName) EnumValue(com.webcohesion.enunciate.modules.jaxb.model.EnumValue) EnumTypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition) PackageElement(javax.lang.model.element.PackageElement)

Example 3 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 {
    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);
        }
    }
    if (declaration.getKind() == ElementKind.INTERFACE && eraseInterfaces) {
        return "java.lang.Object";
    }
    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 4 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 {
    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);
        }
    }
    if (declaration.getKind() == ElementKind.INTERFACE && eraseInterfaces) {
        return "java.lang.Object";
    }
    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) TypeMirror(javax.lang.model.type.TypeMirror) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)

Example 5 with ClientName

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

the class TypeDefinition 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)

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