code: @Override
      public Document convert(BELDocument bd) {
          if (bd == null) {
              return null;
          }
  
          final Header header = dhc.convert(bd.getDocumentHeader());
  
          // handle annotation definitions
          Set<BELAnnotationDefinition> badlist = bd.getAnnotationDefinitions();
          List<AnnotationDefinition> adlist = null;
          if (badlist != null) {
              adlist = sizedArrayList(badlist.size());
              if (hasItems(badlist)) {
                  for (BELAnnotationDefinition bad : badlist) {
                      adlist.add(badc.convert(bad));
                  }
              }
          }
  
          // handle namespace definitions
          Set<BELNamespaceDefinition> bndlist = bd.getNamespaceDefinitions();
          NamespaceGroup nsgroup = null;
          if (bndlist != null) {
              nsgroup = new NamespaceGroup();
              if (hasItems(bndlist)) {
                  List<Namespace> nslist = new ArrayList<Namespace>();
                  for (BELNamespaceDefinition bnd : bndlist) {
                      // handle namespace default on the namespace group
                      if (bnd.isNsDefault()) {
                          nsgroup.setDefaultResourceLocation(bnd
                                  .getResourceLocation());
                      } else {
                          nslist.add(bndc.convert(bnd));
                      }
                  }
                  nsgroup.setNamespaces(nslist);
              }
          }
  
          // handle statements
          final BELStatementGroupConverter sgc = new BELStatementGroupConverter(
                  getNamespaceMap(nsgroup), getDefinitionMap(adlist));
          List<StatementGroup> statementGroups = new ArrayList<StatementGroup>();
          for (BELStatementGroup bsg : bd.getBelStatementGroups()) {
              statementGroups.add(sgc.convert(bsg));
          }
  
          return new Document(header, statementGroups, nsgroup, adlist);
      }
docs: {@inheritDoc}