code: public List<String> getAncestorDNs(String DN, int level) throws WIMException {
          if (DN == null || DN.trim().length() == 0) {
              return null;
          }
          try {
              NameParser nameParser = getNameParser();
              Name name = nameParser.parse(DN);
              int size = name.size();
  
              List<String> ancestorDNs = new ArrayList<String>();
              if (level == 0) {
                  level = size;
              }
  
              for (int i = size - 1; i >= (size - level); i--) {
                  name.remove(i);
                  ancestorDNs.add(name.toString());
              }
              return ancestorDNs;
          } catch (NamingException e) {
              String msg = Tr.formatMessage(tc, WIMMessageKey.NAMING_EXCEPTION, WIMMessageHelper.generateMsgParms(e.toString(true)));
              throw new WIMSystemException(WIMMessageKey.NAMING_EXCEPTION, msg, e);
          }
      }
docs: Get a list of all ancestor distinguished names for the input distinguished name. For example;
  if the input distinguished name was "uid=user,o=ibm,c=us" the results would be ["o=ibm,c=us", "c=us"].
  
  @param DN The distinguished name to get the ancestor distinguished names for.
  @param level the number of levels to return. If not set, all will be returned.
  @return The list of ancestor DNs.
  @throws WIMException If there was an error parsing the input DN.