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);
}
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;
}
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);
}
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;
}
Aggregations