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);
  }
 private Root wrapObjectInXMLRoot(
     JAXBElement wrapperElement, Object value, TypeMappingInfo typeMappingInfo) {
   Root xmlroot = new Root();
   Object objectValue = value;
   xmlroot.setObject(objectValue);
   QName qname = wrapperElement.getName();
   xmlroot.setLocalName(qname.getLocalPart());
   xmlroot.setNamespaceURI(qname.getNamespaceURI());
   xmlroot.setDeclaredType(wrapperElement.getDeclaredType());
   if (typeMappingInfo != null) {
     xmlroot.setSchemaType(typeMappingInfo.getSchemaType());
   } else if (value != null) {
     if (value.getClass() == CoreClassConstants.ABYTE
         || value.getClass() == CoreClassConstants.APBYTE
         || value.getClass().getCanonicalName().equals("javax.activation.DataHandler")) {
       xmlroot.setSchemaType(Constants.BASE_64_BINARY_QNAME);
     }
   }
   return xmlroot;
 }