use of com.webcohesion.enunciate.modules.jaxb.model.Accessor in project enunciate by stoicflame.
the class AccessorOverridesAnotherMethod method exec.
public Object exec(List list) throws TemplateModelException {
if (list.size() < 1) {
throw new TemplateModelException("The accessorOverridesAnother method must have the accessor as a parameter.");
}
TemplateModel from = (TemplateModel) list.get(0);
Object unwrapped = FreemarkerUtil.unwrap(from);
if (!(unwrapped instanceof Accessor)) {
throw new TemplateModelException("The accessorOverridesAnother method must have the accessor as a parameter.");
}
return overridesAnother((Accessor) unwrapped);
}
use of com.webcohesion.enunciate.modules.jaxb.model.Accessor in project enunciate by stoicflame.
the class AccessorOverridesAnotherMethod method overridesAnother.
public Boolean overridesAnother(Accessor a) {
TypeDefinition typeDefinition = a.getTypeDefinition();
XmlType baseType = typeDefinition.getBaseType();
if (baseType instanceof XmlClassType) {
typeDefinition = ((XmlClassType) baseType).getTypeDefinition();
while (typeDefinition != null) {
ArrayList<Accessor> accessors = new ArrayList<Accessor>();
accessors.addAll(typeDefinition.getAttributes());
accessors.add(typeDefinition.getValue());
accessors.addAll(typeDefinition.getElements());
for (Accessor accessor : accessors) {
if (a.overrides(accessor)) {
return true;
}
}
baseType = typeDefinition.getBaseType();
typeDefinition = baseType instanceof XmlClassType ? ((XmlClassType) baseType).getTypeDefinition() : null;
}
}
return Boolean.FALSE;
}
use of com.webcohesion.enunciate.modules.jaxb.model.Accessor 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.Accessor in project enunciate by stoicflame.
the class JAXBCodeErrors method findConflictingAccessorNamingErrors.
public static List<String> findConflictingAccessorNamingErrors(EnunciateJaxbContext context) {
List<String> errors = (List<String>) context.getContext().getProperty(CONFLICTING_JAXB_ACCESSOR_NAMING_ERRORS_PROPERTY);
if (errors == null) {
errors = new ArrayList<String>();
context.getContext().setProperty(CONFLICTING_JAXB_ACCESSOR_NAMING_ERRORS_PROPERTY, errors);
for (SchemaInfo schemaInfo : context.getSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
Map<String, Accessor> accessorsBySimpleName = new HashMap<String, Accessor>();
for (Accessor accessor : typeDefinition.getAllAccessors()) {
String name = accessor.getClientSimpleName();
Accessor conflict = accessorsBySimpleName.get(name);
if (conflict != null) {
errors.add(String.format("%s: accessor \"%s\" conflicts with accessor \"%s\" of %s: both are named \"%s\".", typeDefinition.getQualifiedName(), accessor, conflict, conflict.getTypeDefinition().getQualifiedName(), name));
} else {
accessorsBySimpleName.put(name, accessor);
}
}
}
}
}
return errors;
}
use of com.webcohesion.enunciate.modules.jaxb.model.Accessor in project enunciate by stoicflame.
the class ClientSimpleNameMethod 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 = BeansWrapper.getDefaultInstance().unwrap(from);
String name;
if (unwrapped instanceof Accessor) {
Accessor accessor = (Accessor) unwrapped;
name = accessor.getClientSimpleName();
if (this.clientNames.containsKey(name)) {
name = this.clientNames.get(name);
}
} else if (unwrapped instanceof AnyElement) {
AnyElement accessor = (AnyElement) unwrapped;
name = accessor.getClientSimpleName();
if (this.clientNames.containsKey(name)) {
name = this.clientNames.get(name);
}
} else {
throw new TemplateModelException("The clientSimpleName method must have an accessor as a parameter.");
}
return name;
}
Aggregations