/**
   * XmlElement override will completely replace the existing values.
   *
   * @param xmlElement
   * @param oldProperty
   * @param typeInfo
   * @param nsInfo
   * @return
   */
  private Property processXmlElement(
      XmlElement xmlElement, Property oldProperty, TypeInfo typeInfo, NamespaceInfo nsInfo) {
    // reset any existing values
    resetProperty(oldProperty, typeInfo);

    if (xmlElement.getXmlMap() != null) {
      processXmlMap(xmlElement.getXmlMap(), oldProperty);
    }

    // handle xml-id
    if (xmlElement.isXmlId()) {
      typeInfo.setIDProperty(oldProperty);
    } else if (oldProperty.isXmlId()) {
      // account for XmlID un-set via XML
      if (typeInfo.getIDProperty() != null
          && typeInfo.getIDProperty().getPropertyName().equals(oldProperty.getPropertyName())) {
        typeInfo.setIDProperty(null);
      }
    }
    oldProperty.setIsXmlId(xmlElement.isXmlId());

    // handle xml-idref
    oldProperty.setIsXmlIdRef(xmlElement.isXmlIdref());

    // set required
    oldProperty.setIsRequired(xmlElement.isRequired());

    // set xml-inline-binary-data
    oldProperty.setisInlineBinaryData(xmlElement.isXmlInlineBinaryData());

    // set nillable
    oldProperty.setNillable(xmlElement.isNillable());

    // set defaultValue
    if (xmlElement.getDefaultValue().equals("\u0000")) {
      oldProperty.setDefaultValue(null);
    } else {
      oldProperty.setDefaultValue(xmlElement.getDefaultValue());
    }

    // set schema name
    QName qName;
    String name = xmlElement.getName();
    if (name.equals("##default")) {
      name = oldProperty.getPropertyName();
    }
    if (xmlElement.getNamespace().equals("##default")) {
      if (nsInfo.isElementFormQualified()) {
        qName = new QName(nsInfo.getNamespace(), name);
      } else {
        qName = new QName(name);
      }
    } else {
      qName = new QName(xmlElement.getNamespace(), name);
    }
    oldProperty.setSchemaName(qName);

    // set type
    if (xmlElement.getType().equals("javax.xml.bind.annotation.XmlElement.DEFAULT")) {
      // if xmlElement has no type, and the property type was set via
      // @XmlElement, reset it to the original value
      if (oldProperty.isXmlElementType()) {
        oldProperty.setType(oldProperty.getOriginalType());
      }
    } else {
      if (xmlElement.getXmlMap() != null) {
        getLogger()
            .logWarning(
                JAXBMetadataLogger.INVALID_TYPE_ON_MAP, new Object[] {xmlElement.getName()});
      } else {
        oldProperty.setType(jModelInput.getJavaModel().getClass(xmlElement.getType()));
      }
    }

    // handle XmlJavaTypeAdapter
    if (xmlElement.getXmlJavaTypeAdapter() != null) {
      oldProperty.setXmlJavaTypeAdapter(xmlElement.getXmlJavaTypeAdapter());
    }

    // handle XmlElementWrapper
    if (xmlElement.getXmlElementWrapper() != null) {
      oldProperty.setXmlElementWrapper(xmlElement.getXmlElementWrapper());
    }

    // for primitives we always set required, a.k.a. minOccurs="1"
    if (!oldProperty.isRequired()) {
      JavaClass ptype = oldProperty.getActualType();
      oldProperty.setIsRequired(
          ptype.isPrimitive() || ptype.isArray() && ptype.getComponentType().isPrimitive());
    }

    // handle xml-list
    if (xmlElement.isSetXmlList()) {
      // Make sure XmlList annotation is on a collection or array
      if (!aProcessor.isCollectionType(oldProperty) && !oldProperty.getType().isArray()) {
        throw JAXBException.invalidList(oldProperty.getPropertyName());
      }
      oldProperty.setIsXmlList(xmlElement.isXmlList());
    }

    // handle xml-mime-type
    if (xmlElement.getXmlMimeType() != null) {
      oldProperty.setMimeType(xmlElement.getXmlMimeType());
    }

    // handle xml-attachment-ref
    if (xmlElement.isXmlAttachmentRef()) {
      oldProperty.setIsSwaAttachmentRef(true);
      oldProperty.setSchemaType(XMLConstants.SWA_REF_QNAME);
    }

    // handle xml-schema-type
    if (xmlElement.getXmlSchemaType() != null) {
      oldProperty.setSchemaType(
          new QName(
              xmlElement.getXmlSchemaType().getNamespace(),
              xmlElement.getXmlSchemaType().getName()));
    }

    return oldProperty;
  }
  /**
   * Return all of the declared <code>JavaFields</code> for this <code>JavaClass</code>.
   *
   * @return A <code>Collection</code> containing this <code>JavaClass'</code> <code>JavaFields
   *     </code>.
   */
  public Collection<JavaField> getDeclaredFields() {
    List<JavaField> fieldsToReturn = new ArrayList<JavaField>();

    if (this.enumValues != null) {
      for (Iterator<String> iterator = this.enumValues.iterator(); iterator.hasNext(); ) {
        fieldsToReturn.add(new OXMJavaFieldImpl(iterator.next(), JAVA_LANG_OBJECT, this));
      }
    } else {
      JavaAttributes javaAttributes = this.javaType.getJavaAttributes();
      if (null != javaAttributes) {
        List<JAXBElement<? extends JavaAttribute>> fields = javaAttributes.getJavaAttribute();

        for (Iterator<JAXBElement<? extends JavaAttribute>> iterator = fields.iterator();
            iterator.hasNext(); ) {
          JAXBElement<? extends JavaAttribute> jaxbElement = iterator.next();

          JavaAttribute att = (JavaAttribute) jaxbElement.getValue();

          if (att instanceof XmlElement) {
            XmlElement xme = (XmlElement) att;
            String fieldName = xme.getJavaAttribute();
            String fieldType = xme.getType();
            fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
          } else if (att instanceof XmlElements) {
            XmlElements xmes = (XmlElements) att;
            String fieldName = xmes.getJavaAttribute();
            String fieldType = JAVA_LANG_OBJECT;
            fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
          } else if (att instanceof XmlElementRef) {
            XmlElementRef xmer = (XmlElementRef) att;
            String fieldName = xmer.getJavaAttribute();
            String fieldType = xmer.getType();
            fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
          } else if (att instanceof XmlAttribute) {
            XmlAttribute xma = (XmlAttribute) att;
            String fieldName = xma.getJavaAttribute();
            String fieldType = xma.getType();
            fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
          } else if (att instanceof XmlValue) {
            XmlValue xmv = (XmlValue) att;
            String fieldName = xmv.getJavaAttribute();
            String fieldType = xmv.getType();
            fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
          } else if (att instanceof XmlAnyElement) {
            XmlAnyElement xmae = (XmlAnyElement) att;
            String fieldName = xmae.getJavaAttribute();
            String fieldType = JAVA_LANG_OBJECT;
            fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
          } else if (att instanceof XmlAnyAttribute) {
            XmlAnyAttribute xmaa = (XmlAnyAttribute) att;
            String fieldName = xmaa.getJavaAttribute();
            String fieldType = JAVA_UTIL_MAP;
            fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
          } else if (att instanceof XmlJoinNodes) {
            XmlJoinNodes xmjn = (XmlJoinNodes) att;
            String fieldName = xmjn.getJavaAttribute();
            String fieldType = xmjn.getType();
            fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
          } else if (att instanceof XmlInverseReference) {
            XmlInverseReference xmir = (XmlInverseReference) att;
            String fieldName = xmir.getJavaAttribute();
            String fieldType = xmir.getType();
            fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
          }
        }
      }
    }

    return fieldsToReturn;
  }