Search in sources :

Example 1 with EnumValue

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

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

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

the class EnumDataTypeImpl method getValues.

@Override
public List<? extends Value> getValues() {
    FacetFilter facetFilter = this.registrationContext.getFacetFilter();
    List<EnumValue> enumValues = this.typeDefinition.getEnumValues();
    ArrayList<Value> values = new ArrayList<Value>(enumValues.size());
    for (EnumValue enumValue : enumValues) {
        if (enumValue.getValue() != null) {
            if (!facetFilter.accept(enumValue)) {
                continue;
            }
            values.add(createValue(enumValue));
        }
    }
    return values;
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) EnumValue(com.webcohesion.enunciate.modules.jaxb.model.EnumValue) Value(com.webcohesion.enunciate.api.datatype.Value) EnumValue(com.webcohesion.enunciate.modules.jaxb.model.EnumValue) ArrayList(java.util.ArrayList)

Aggregations

EnumValue (com.webcohesion.enunciate.modules.jaxb.model.EnumValue)3 ClientName (com.webcohesion.enunciate.metadata.ClientName)2 EnumTypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition)2 TemplateModelException (freemarker.template.TemplateModelException)2 PackageElement (javax.lang.model.element.PackageElement)2 Value (com.webcohesion.enunciate.api.datatype.Value)1 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)1 ArrayList (java.util.ArrayList)1