public Element( javax.lang.model.element.Element delegate, TypeDefinition typedef, EnunciateJaxbContext context) { super(delegate, typedef, context); XmlElement xmlElement = getAnnotation(XmlElement.class); XmlElements xmlElements = getAnnotation(XmlElements.class); if (xmlElements != null) { XmlElement[] elementChoices = xmlElements.value(); if (elementChoices.length == 0) { xmlElements = null; } else if ((xmlElement == null) && (elementChoices.length == 1)) { xmlElement = elementChoices[0]; xmlElements = null; } } this.xmlElement = xmlElement; this.choices = new ArrayList<Element>(); if (xmlElements != null) { for (final XmlElement element : xmlElements.value()) { DecoratedTypeMirror typeMirror = Annotations.mirrorOf( new Callable<Class<?>>() { @Override public Class<?> call() throws Exception { return element.type(); } }, this.env, XmlElement.DEFAULT.class); if ((typeMirror instanceof ArrayType && ((ArrayType) typeMirror).getComponentType().getKind() != TypeKind.BYTE) || (typeMirror.isCollection())) { throw new EnunciateException( "Member " + getName() + " of " + typedef.getQualifiedName() + ": an element choice must not be a collection or an array."); } this.choices.add(new Element(getDelegate(), getTypeDefinition(), element, context)); } } else { this.choices.add(this); } }
/** * The type of an element accessor can be specified by an annotation. * * @return The accessor type. */ @Override public DecoratedTypeMirror getAccessorType() { DecoratedTypeMirror specifiedType = null; if (xmlElement != null) { specifiedType = Annotations.mirrorOf( new Callable<Class<?>>() { @Override public Class<?> call() throws Exception { return xmlElement.type(); } }, this.env, XmlElement.DEFAULT.class); } if (specifiedType != null) { if (!isChoice) { DecoratedTypeMirror accessorType = super.getAccessorType(); if (accessorType.isCollection()) { TypeElement collectionElement = (TypeElement) (accessorType.isList() ? TypeMirrorUtils.listType(this.env).asElement() : TypeMirrorUtils.collectionType(this.env).asElement()); specifiedType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate( this.env.getTypeUtils().getDeclaredType(collectionElement, specifiedType), this.env); } else if (accessorType.isArray() && !(specifiedType.isArray())) { specifiedType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate( this.env.getTypeUtils().getArrayType(specifiedType), this.env); } } return specifiedType; } return super.getAccessorType(); }
/** * The base type of an element accessor can be specified by an annotation. * * @return The base type. */ @Override public com.webcohesion.enunciate.modules.jaxb.model.types.XmlType getBaseType() { if (xmlElement != null) { TypeMirror typeMirror = Annotations.mirrorOf( new Callable<Class<?>>() { @Override public Class<?> call() throws Exception { return xmlElement.type(); } }, this.env, XmlElement.DEFAULT.class); if (typeMirror != null) { return XmlTypeFactory.getXmlType(typeMirror, this.context); } } return super.getBaseType(); }