code: @Override
      public Document convert(XBELDocument source) {
          if (source == null) return null;
  
          List<XBELStatementGroup> xstmtGroups = source.getStatementGroup();
          List<StatementGroup> stmtGroups =
                  new ArrayList<StatementGroup>(xstmtGroups.size());
          StatementGroupConverter sgConverter = new StatementGroupConverter();
          for (final XBELStatementGroup xsg : xstmtGroups) {
              // Defer to StatementGroupConverter
              stmtGroups.add(sgConverter.convert(xsg));
          }
  
          XBELHeader header = source.getHeader();
          HeaderConverter hConverter = new HeaderConverter();
          // Defer to HeaderConverter
          Document dest = new Document(hConverter.convert(header), stmtGroups);
  
          if (source.isSetAnnotationDefinitionGroup()) {
              XBELAnnotationDefinitionGroup adGroup =
                      source.getAnnotationDefinitionGroup();
              List<XBELInternalAnnotationDefinition> internals =
                      adGroup.getInternalAnnotationDefinition();
              List<XBELExternalAnnotationDefinition> externals =
                      adGroup.getExternalAnnotationDefinition();
              int size = internals.size() + externals.size();
              List<AnnotationDefinition> l2 = sizedArrayList(size);
  
              // Defer to converters
              InternalAnnotationDefinitionConverter iConverter =
                      new InternalAnnotationDefinitionConverter();
              for (final XBELInternalAnnotationDefinition iad : internals) {
                  l2.add(iConverter.convert(iad));
              }
              ExternalAnnotationDefinitionConverter eConverter =
                      new ExternalAnnotationDefinitionConverter();
              for (final XBELExternalAnnotationDefinition ead : externals) {
                  l2.add(eConverter.convert(ead));
              }
              dest.setDefinitions(l2);
          }
  
          if (source.isSetNamespaceGroup()) {
              XBELNamespaceGroup namespaceGroup = source.getNamespaceGroup();
              NamespaceGroupConverter ngConverter = new NamespaceGroupConverter();
              // Defer to DocumentHeaderConverter
              dest.setNamespaceGroup(ngConverter.convert(namespaceGroup));
          }
  
          // Resolve any property references to instances
          dest.resolveReferences();
  
          return dest;
      }
docs: {@inheritDoc}