private Object wrapEnumeration(Object object, Class enumerationClass) {
   Class generatedClass = this.getClassToGeneratedClasses().get(enumerationClass.getName());
   if (generatedClass != null && WrappedValue.class.isAssignableFrom(generatedClass)) {
     ClassDescriptor desc =
         xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
     Object newObject = desc.getInstantiationPolicy().buildNewInstance();
     ((WrappedValue) newObject).setValue(object);
     object = newObject;
   }
   return object;
 }
  private Object wrapObject(
      Object object, JAXBElement wrapperElement, TypeMappingInfo typeMappingInfo) {
    if (jaxbContext.getTypeMappingInfoToGeneratedType().size() > 0) {
      Class generatedClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(typeMappingInfo);
      if (generatedClass != null && object == null && wrapperElement != null) {
        return wrapObjectInXMLRoot(wrapperElement, object, typeMappingInfo);
      }

      if (generatedClass != null && WrappedValue.class.isAssignableFrom(generatedClass)) {
        ClassDescriptor desc =
            xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
        Object newObject = desc.getInstantiationPolicy().buildNewInstance();
        ((WrappedValue) newObject).setValue(object);
        object = newObject;
      } else if (generatedClass != null) {
        // should be a many value
        ClassDescriptor desc =
            xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
        Object newObject = desc.getInstantiationPolicy().buildNewInstance();
        ((ManyValue) newObject).setItem(object);
        object = newObject;
      }
    }

    if (null == wrapperElement) {
      Root xmlRoot = new Root();
      QName xmlTagName = typeMappingInfo.getXmlTagName();
      if (null == xmlTagName) {
        return object;
      }
      xmlRoot.setNamespaceURI(typeMappingInfo.getXmlTagName().getNamespaceURI());
      xmlRoot.setLocalName(typeMappingInfo.getXmlTagName().getLocalPart());
      xmlRoot.setObject(object);
      return xmlRoot;
    }
    return wrapObjectInXMLRoot(wrapperElement, object, typeMappingInfo);
  }
  /**
   * Create an instance of XMLRoot populated from the contents of the provided JAXBElement. XMLRoot
   * will be used to hold the contents of the JAXBElement while the marshal operation is performed
   * by TopLink OXM. This will avoid adding any runtime dependencies to TopLink.
   *
   * @param elt
   * @return
   */
  private Root createXMLRootFromJAXBElement(JAXBElement elt) {
    // create an XMLRoot to hand into the marshaller
    Root xmlroot = new Root();
    Object objectValue = elt.getValue();
    xmlroot.setObject(objectValue);
    QName qname = elt.getName();
    xmlroot.setLocalName(qname.getLocalPart());
    xmlroot.setNamespaceURI(qname.getNamespaceURI());
    xmlroot.setDeclaredType(elt.getDeclaredType());
    xmlroot.setNil(elt.isNil());
    if (elt.getDeclaredType() == CoreClassConstants.ABYTE
        || elt.getDeclaredType() == CoreClassConstants.APBYTE
        || elt.getDeclaredType().getCanonicalName().equals("javax.activation.DataHandler")
        || elt.getDeclaredType().isEnum()) {
      // need a binary data mapping so need to wrap
      Class generatedClass =
          getClassToGeneratedClasses().get(elt.getDeclaredType().getCanonicalName());
      if (!elt.getDeclaredType().isEnum()) {
        xmlroot.setSchemaType(Constants.BASE_64_BINARY_QNAME);
      }
      if (generatedClass != null && WrappedValue.class.isAssignableFrom(generatedClass)) {
        ClassDescriptor desc =
            xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
        Object newObject = desc.getInstantiationPolicy().buildNewInstance();
        ((WrappedValue) newObject).setValue(objectValue);
        xmlroot.setObject(newObject);
        return xmlroot;
      }
    } else {
      xmlroot.setSchemaType(
          (QName)
              org.eclipse.persistence.internal.oxm.XMLConversionManager.getDefaultJavaTypes()
                  .get(elt.getDeclaredType()));
    }

    if (elt instanceof WrappedValue) {
      xmlroot.setObject(elt);
      return xmlroot;
    }
    Map<QName, Class> qNameToGeneratedClasses = jaxbContext.getQNameToGeneratedClasses();
    if (qNameToGeneratedClasses != null) {
      Class theClass = qNameToGeneratedClasses.get(qname);
      if (theClass != null && WrappedValue.class.isAssignableFrom(theClass)) {
        ClassDescriptor desc =
            xmlMarshaller.getXMLContext().getSession(theClass).getDescriptor(theClass);
        Object newObject = desc.getInstantiationPolicy().buildNewInstance();
        ((WrappedValue) newObject).setValue(objectValue);
        xmlroot.setObject(newObject);
        return xmlroot;
      }
    }

    Class generatedClass = null;
    if (jaxbContext.getTypeMappingInfoToGeneratedType() != null) {
      if (jaxbContext.getTypeToTypeMappingInfo() != null) {
        if (elt.getDeclaredType() != null && elt.getDeclaredType().isArray()) {
          TypeMappingInfo tmi = jaxbContext.getTypeToTypeMappingInfo().get(elt.getDeclaredType());
          generatedClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(tmi);
        } else if (elt instanceof JAXBTypeElement) {
          Type objectType = ((JAXBTypeElement) elt).getType();
          TypeMappingInfo tmi = jaxbContext.getTypeToTypeMappingInfo().get(objectType);
          generatedClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(tmi);
        }
      }
    } else {
      if (elt.getDeclaredType() != null && elt.getDeclaredType().isArray()) {
        if (jaxbContext.getArrayClassesToGeneratedClasses() != null) {
          generatedClass =
              jaxbContext
                  .getArrayClassesToGeneratedClasses()
                  .get(elt.getDeclaredType().getCanonicalName());
        }
      } else if (elt instanceof JAXBTypeElement) {
        Type objectType = ((JAXBTypeElement) elt).getType();
        generatedClass = jaxbContext.getCollectionClassesToGeneratedClasses().get(objectType);
      }
    }

    if (generatedClass != null) {
      ClassDescriptor desc =
          xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
      Object newObject = desc.getInstantiationPolicy().buildNewInstance();
      ((ManyValue) newObject).setItem(objectValue);
      xmlroot.setObject(newObject);
    }

    return xmlroot;
  }