code: public void addAttachment(CmsDocumentDependency dep) {
  
          // don't add attachment if this is a language version of an already existing attachment
          boolean exist = false;
          for (CmsDocumentDependency att : m_attachments) {
              if (att.getAttachmentNumber() == dep.getAttachmentNumber()) {
  
                  if (m_locale.equals(dep.getLocale())) {
                      // if dependency has same locale as main document it is added as attachment
                      // and gets the old attachment as a language-version with all previous language-versions
                      for (CmsDocumentDependency langAtt : att.getVariants()) {
                          dep.addVariant(langAtt);
                      }
                      dep.addVariant(att);
                      m_attachments.remove(att);
                  } else {
                      exist = true;
                      att.addVariant(dep);
                  }
                  break;
              }
          }
  
          if (!exist) {
              dep.setType(DependencyType.attachment);
              m_attachments.add(dep);
          } else {
              dep.setType(DependencyType.variant);
          }
          addDependency(dep);
      }
docs: Adds another document attachment dependency to this document.<p>
  
  @param dep the document attachment dependency to add