Search in sources :

Example 1 with EnumTypeDefinition

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

use of com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition in project enunciate by stoicflame.

the class FunctionIdentifierForMethod method exec.

public Object exec(List list) throws TemplateModelException {
    if (list.size() < 1) {
        throw new TemplateModelException("The functionIdentifierFor method must have an accessor or type mirror as a parameter.");
    }
    TemplateModel from = (TemplateModel) list.get(0);
    Object unwrapped = FreemarkerUtil.unwrap(from);
    TypeMirror typeMirror;
    if (unwrapped instanceof Accessor) {
        Accessor accessor = (Accessor) unwrapped;
        if (accessor.isAdapted()) {
            typeMirror = accessor.getAdapterType().getAdaptingType(accessor.getAccessorType(), this.context.getContext());
        } else {
            typeMirror = accessor.getAccessorType();
        }
    } else if (unwrapped instanceof TypeMirror) {
        typeMirror = (TypeMirror) unwrapped;
    } else {
        throw new TemplateModelException("The functionIdentifierFor method must have an accessor or type mirror as a parameter.");
    }
    if (typeMirror instanceof PrimitiveType) {
        switch(typeMirror.getKind()) {
            case BOOLEAN:
                return "Boolean";
            case BYTE:
                return "Byte";
            case CHAR:
                return "Character";
            case DOUBLE:
                return "Double";
            case FLOAT:
                return "Float";
            case INT:
                return "Int";
            case LONG:
                return "Long";
            case SHORT:
                return "Short";
            default:
                return (typeMirror.getKind()).toString();
        }
    } else if (typeMirror instanceof DeclaredType) {
        TypeElement declaration = (TypeElement) ((DeclaredType) typeMirror).asElement();
        TypeDefinition typeDefinition = this.context.findTypeDefinition(declaration);
        if (typeDefinition != null) {
            if (typeDefinition instanceof EnumTypeDefinition) {
                return typeDefName.calculateName(typeDefinition);
            }
        } else {
            String classname = declaration.getQualifiedName().toString();
            if (Boolean.class.getName().equals(classname)) {
                return "Boolean";
            } else if (Byte.class.getName().equals(classname)) {
                return "Byte";
            } else if (Character.class.getName().equals(classname)) {
                return "UnsignedShort";
            } else if (Double.class.getName().equals(classname)) {
                return "Double";
            } else if (Float.class.getName().equals(classname)) {
                return "Float";
            } else if (Integer.class.getName().equals(classname)) {
                return "Int";
            } else if (Long.class.getName().equals(classname)) {
                return "Long";
            } else if (Short.class.getName().equals(classname)) {
                return "Short";
            }
        }
    }
    return null;
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) TypeElement(javax.lang.model.element.TypeElement) EnumTypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition) TemplateModel(freemarker.template.TemplateModel) Accessor(com.webcohesion.enunciate.modules.jaxb.model.Accessor) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition) EnumTypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition) TypeMirror(javax.lang.model.type.TypeMirror) PrimitiveType(javax.lang.model.type.PrimitiveType) DeclaredType(javax.lang.model.type.DeclaredType)

Example 3 with EnumTypeDefinition

use of com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition 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 = ObjCXMLClientModule.scrubIdentifier(typeDefinition.getName());
    String simpleName = ObjCXMLClientModule.scrubIdentifier(typeDefinition.getSimpleName().toString());
    String clientName = ObjCXMLClientModule.scrubIdentifier(typeDefinition.getClientSimpleName());
    String simpleNameDecap = ObjCXMLClientModule.scrubIdentifier(Introspector.decapitalize(simpleName));
    String clientNameDecap = ObjCXMLClientModule.scrubIdentifier(Introspector.decapitalize(clientName));
    if (name == null) {
        name = "anonymous_" + clientNameDecap;
    }
    PackageElement pckg = typeDefinition.getPackage().getDelegate();
    String packageName = pckg == null ? "" : pckg.getQualifiedName().toString();
    String packageIdentifier = this.packages2ids.containsKey(packageName) ? ObjCXMLClientModule.scrubIdentifier(this.packages2ids.get(packageName)) : ObjCXMLClientModule.scrubIdentifier(packageName);
    String nsid = ObjCXMLClientModule.scrubIdentifier(namespaces2ids.get(typeDefinition.getNamespace()));
    String constantName = ObjCXMLClientModule.scrubIdentifier(enumValue.getSimpleName().toString());
    String constantClientName = ObjCXMLClientModule.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, packageIdentifier, 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 4 with EnumTypeDefinition

use of com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition in project enunciate by stoicflame.

the class NamespaceImpl method getTypes.

@Override
public List<? extends DataType> getTypes() {
    FacetFilter facetFilter = this.registrationContext.getFacetFilter();
    ArrayList<DataType> dataTypes = new ArrayList<DataType>();
    for (TypeDefinition typeDefinition : this.schema.getTypeDefinitions()) {
        if (!facetFilter.accept(typeDefinition)) {
            continue;
        }
        if (typeDefinition instanceof ComplexTypeDefinition) {
            dataTypes.add(new ComplexDataTypeImpl((ComplexTypeDefinition) typeDefinition, registrationContext));
        } else if (typeDefinition instanceof EnumTypeDefinition) {
            dataTypes.add(new EnumDataTypeImpl((EnumTypeDefinition) typeDefinition, registrationContext));
        }
    }
    return dataTypes;
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) EnumTypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition) ArrayList(java.util.ArrayList) DataType(com.webcohesion.enunciate.api.datatype.DataType) ComplexTypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.ComplexTypeDefinition) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition) EnumTypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition) ComplexTypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.ComplexTypeDefinition)

Aggregations

EnumTypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition)4 TemplateModelException (freemarker.template.TemplateModelException)3 ClientName (com.webcohesion.enunciate.metadata.ClientName)2 EnumValue (com.webcohesion.enunciate.modules.jaxb.model.EnumValue)2 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)2 PackageElement (javax.lang.model.element.PackageElement)2 DataType (com.webcohesion.enunciate.api.datatype.DataType)1 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)1 Accessor (com.webcohesion.enunciate.modules.jaxb.model.Accessor)1 ComplexTypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.ComplexTypeDefinition)1 TemplateModel (freemarker.template.TemplateModel)1 ArrayList (java.util.ArrayList)1 TypeElement (javax.lang.model.element.TypeElement)1 DeclaredType (javax.lang.model.type.DeclaredType)1 PrimitiveType (javax.lang.model.type.PrimitiveType)1 TypeMirror (javax.lang.model.type.TypeMirror)1