// GENERATED CODE: ... fieldName = new C<T>();
originalImplField.init(JExpr._new(collectionImplClass));
}
// Annotate the field with the @XmlElementWrapper annotation using the original field name.
JAnnotationUse xmlElementWrapperAnnotation = originalImplField.annotate(xmlElementWrapperModelClass);
JAnnotationUse xmlElementOriginalAnnotation = getAnnotation(originalImplField, xmlElementModelClass);
// xmlElementOriginalAnnotation can be null:
JExpression wrapperXmlName = getAnnotationMemberExpression(xmlElementOriginalAnnotation, "name");
if (wrapperXmlName != null) {
xmlElementWrapperAnnotation.param("name", wrapperXmlName);
}
else if (fieldConfiguration.isApplyPluralForm()) {
xmlElementWrapperAnnotation.param("name", getXsdDeclaration(fieldPropertyInfo).getName());
}
JExpression wrapperXmlRequired = getAnnotationMemberExpression(xmlElementOriginalAnnotation, "required");
if (wrapperXmlRequired != null) {
xmlElementWrapperAnnotation.param("required", wrapperXmlRequired);
}
JExpression wrapperXmlNillable = getAnnotationMemberExpression(xmlElementOriginalAnnotation, "nillable");
if (wrapperXmlNillable != null) {
xmlElementWrapperAnnotation.param("nillable", wrapperXmlNillable);
}
// Namespace of the wrapper element
JExpression wrapperXmlNamespace = getAnnotationMemberExpression(xmlElementOriginalAnnotation,
"namespace");
if (wrapperXmlNamespace != null) {
xmlElementWrapperAnnotation.param("namespace", wrapperXmlNamespace);
}
if (xmlElementOriginalAnnotation != null) {
removeAnnotation(originalImplField, xmlElementOriginalAnnotation);
}
boolean xmlElementInfoWasTransferred = false;
// Transfer @XmlAnyElement, @XmlElementRefs, @XmlElements:
for (JClass annotationModelClass : new JClass[] { xmlAnyElementModelClass, xmlMixedModelClass,
xmlElementRefModelClass, xmlElementRefsModelClass, xmlElementsModelClass }) {
JAnnotationUse annotation = getAnnotation(candidate.getField(), annotationModelClass);
if (annotation != null) {
if (candidate.getFieldTargetNamespace() != null) {
JAnnotationArrayMember annotationArrayMember = (JAnnotationArrayMember) getAnnotationMember(
annotation, "value");
if (annotationArrayMember != null) {
for (JAnnotationUse subAnnotation : annotationArrayMember.annotations()) {
if (getAnnotationMemberExpression(subAnnotation, "namespace") == null) {
subAnnotation.param("namespace", candidate.getFieldTargetNamespace());
}
}
}
}
xmlElementInfoWasTransferred = true;
addAnnotation(originalImplField, annotation);
}
}
if (!xmlElementInfoWasTransferred) {
// Annotate the field with the @XmlElement annotation using the field name from the wrapped type as name.
// We cannot just re-use the same annotation object instance, as for example, we need to set XML name and this
// will impact the candidate field annotation in case candidate is unmarked from removal.
JAnnotationUse xmlElementAnnotation = originalImplField.annotate(xmlElementModelClass);
xmlElementOriginalAnnotation = getAnnotation(candidate.getField(), xmlElementModelClass);
// xmlElementOriginalAnnotation can be null:
JExpression xmlName = getAnnotationMemberExpression(xmlElementOriginalAnnotation, "name");
if (xmlName != null) {
xmlElementAnnotation.param("name", xmlName);
}
else {
xmlElementAnnotation.param("name", candidate.getFieldName());
}
JExpression xmlNamespace = getAnnotationMemberExpression(xmlElementOriginalAnnotation, "namespace");
if (xmlNamespace != null) {
xmlElementAnnotation.param("namespace", xmlNamespace);
}
else if (candidate.getFieldTargetNamespace() != null) {
xmlElementAnnotation.param("namespace", candidate.getFieldTargetNamespace());
}
JExpression type = getAnnotationMemberExpression(xmlElementOriginalAnnotation, "type");
if (type != null) {
xmlElementAnnotation.param("type", type);
}
}
JAnnotationUse adapterAnnotation = getAnnotation(candidate.getField(), xmlJavaTypeAdapterModelClass);
if (adapterAnnotation != null) {
addAnnotation(originalImplField, adapterAnnotation);
}