code: private void writeTextHandleTransformAs(String transformName, ExtensionMetadata metadata, Object source, String transformType)
      throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException {
      if (source == null) {
        throw new IllegalArgumentException("no source to write");
      }
  
      Class<?> as = source.getClass();
  
      TextWriteHandle sourceHandle = null;
      if (TextWriteHandle.class.isAssignableFrom(as)) {
        sourceHandle = (TextWriteHandle) source;
      } else {
        ContentHandle<?> handle = getHandleRegistry().makeHandle(as);
        if (!TextWriteHandle.class.isAssignableFrom(handle.getClass())) {
          throw new IllegalArgumentException(
            "Handle "+handle.getClass().getName()+
              " cannot be used to write transform source as "+as.getName()
          );
        }
        Utilities.setHandleContent(handle, source);
        sourceHandle = (TextWriteHandle) handle;
      }
  
      if (transformType.equals("javascript")) {
        writeJavascriptTransform(transformName, sourceHandle, metadata);
      }
      else if (transformType.equals("xquery")) {
        writeXQueryTransform(transformName, sourceHandle, metadata);
      }
    }
docs: This method used by writeJavascriptTransformAs and writeXQueryTransformAs