Search in sources :

Example 1 with Accessor

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);
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) TemplateModel(freemarker.template.TemplateModel) Accessor(com.webcohesion.enunciate.modules.jaxb.model.Accessor)

Example 2 with Accessor

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;
}
Also used : XmlClassType(com.webcohesion.enunciate.modules.jaxb.model.types.XmlClassType) ArrayList(java.util.ArrayList) Accessor(com.webcohesion.enunciate.modules.jaxb.model.Accessor) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition) XmlType(com.webcohesion.enunciate.modules.jaxb.model.types.XmlType)

Example 3 with Accessor

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;
}
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 4 with Accessor

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;
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) Accessor(com.webcohesion.enunciate.modules.jaxb.model.Accessor) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)

Example 5 with Accessor

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;
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) AnyElement(com.webcohesion.enunciate.modules.jaxb.model.AnyElement) TemplateModel(freemarker.template.TemplateModel) Accessor(com.webcohesion.enunciate.modules.jaxb.model.Accessor)

Aggregations

Accessor (com.webcohesion.enunciate.modules.jaxb.model.Accessor)6 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)4 TemplateModel (freemarker.template.TemplateModel)4 TemplateModelException (freemarker.template.TemplateModelException)4 ArrayList (java.util.ArrayList)2 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)1 AnyElement (com.webcohesion.enunciate.modules.jaxb.model.AnyElement)1 Element (com.webcohesion.enunciate.modules.jaxb.model.Element)1 ElementDeclaration (com.webcohesion.enunciate.modules.jaxb.model.ElementDeclaration)1 EnumTypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.EnumTypeDefinition)1 SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)1 XmlClassType (com.webcohesion.enunciate.modules.jaxb.model.types.XmlClassType)1 XmlType (com.webcohesion.enunciate.modules.jaxb.model.types.XmlType)1 HashMap (java.util.HashMap)1 List (java.util.List)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 JAXBElement (javax.xml.bind.JAXBElement)1