public void updateEntry(String name, EntryConfig entryConfig) throws Exception {

    log.debug(TextUtil.repeat("-", 70));

    Directory directory = getDirectory();
    List<Entry> children = null;

    if (directory != null) {
      try {
        Entry oldEntry = directory.removeEntry(entryConfig.getName());
        if (oldEntry != null) {
          children = oldEntry.getChildren();
          oldEntry.destroy();
        }
      } catch (Exception e) {
        log.error(e.getMessage(), e);
      }
    }

    removeEntryService(entryConfig.getName());

    DirectoryConfig directoryConfig = getDirectoryConfig();
    directoryConfig.updateEntryConfig(name, entryConfig);

    if (directory != null) {
      try {
        Entry newEntry = directory.createEntry(entryConfig);
        if (children != null) newEntry.addChildren(children);
      } catch (Exception e) {
        log.error(e.getMessage(), e);
      }
    }

    createEntryService(entryConfig.getName());
  }
  public void init() throws Exception {
    jmxService.register(getObjectName(), this);

    DirectoryConfig directoryConfig = getDirectoryConfig();

    for (String entryName : directoryConfig.getEntryNames()) {
      createEntryService(entryName);
    }
  }
  public void destroy() throws Exception {

    DirectoryConfig directoryConfig = getDirectoryConfig();

    for (String entryName : directoryConfig.getEntryNames()) {
      removeEntryService(entryName);
    }

    jmxService.unregister(getObjectName());
  }
  /**
   * Ensures that the Directory Server is running.
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @BeforeClass()
  public void startServer() throws Exception {
    TestCaseUtils.startServer();

    entryDNType = DirectoryConfig.getAttributeType("entrydn", false);
    assertNotNull(entryDNType);
  }
 /**
  * Tests the {@code appliesToEntry} method.
  *
  * @param rule The rule for which to perform the test.
  * @param appliesToEntry Indicates whether the provided rule applies to a minimal "o=test" entry.
  * @throws Exception If an unexpected problem occurs.
  */
 @Test(dataProvider = "testRules")
 public void testAppliesToEntry(VirtualAttributeRule rule, boolean appliesToEntry)
     throws Exception {
   TestCaseUtils.initializeTestBackend(true);
   addGroups();
   assertEquals(
       rule.appliesToEntry(DirectoryConfig.getEntry(DN.decode("o=test"))), appliesToEntry);
   removeGroups();
 }
  public void removeEntry(String entryName) throws Exception {

    log.debug(TextUtil.repeat("-", 70));

    Directory directory = getDirectory();
    if (directory != null) {
      try {
        directory.destroy(entryName);
      } catch (Exception e) {
        log.error(e.getMessage(), e);
      }
    }

    DirectoryConfig directoryConfig = getDirectoryConfig();
    directoryConfig.removeEntryConfig(entryName);

    removeEntryService(entryName);
  }
  public String createEntry(EntryConfig entryConfig) throws Exception {

    log.debug(TextUtil.repeat("-", 70));

    DirectoryConfig directoryConfig = getDirectoryConfig();
    directoryConfig.addEntryConfig(entryConfig);

    Directory directory = getDirectory();
    if (directory != null) {
      try {
        directory.createEntry(entryConfig);
      } catch (Exception e) {
        log.error(e.getMessage(), e);
      }
    }

    createEntryService(entryConfig.getName());

    return entryConfig.getName();
  }
 public void setChildNames(String entryName, List<String> childNames) throws Exception {
   DirectoryConfig directoryConfig = getDirectoryConfig();
   directoryConfig.setChildNames(entryName, childNames);
 }
 public List<String> getChildNames(String entryName) throws Exception {
   DirectoryConfig directoryConfig = getDirectoryConfig();
   return directoryConfig.getChildNames(entryName);
 }
 public String getParentName(String entryName) throws Exception {
   DirectoryConfig directoryConfig = getDirectoryConfig();
   return directoryConfig.getParentName(entryName);
 }
 public Collection<String> getEntryNames() throws Exception {
   Collection<String> list = new ArrayList<String>();
   DirectoryConfig directoryConfig = getDirectoryConfig();
   list.addAll(directoryConfig.getEntryNames());
   return list;
 }
 public Collection<DN> getSuffixes() throws Exception {
   Collection<DN> list = new ArrayList<DN>();
   DirectoryConfig directoryConfig = getDirectoryConfig();
   list.addAll(directoryConfig.getSuffixes());
   return list;
 }
 public DN getSuffix() throws Exception {
   DirectoryConfig directoryConfig = getDirectoryConfig();
   return directoryConfig.getSuffix();
 }
 public EntryConfig getEntryConfig(String entryName) throws Exception {
   DirectoryConfig directoryConfig = getDirectoryConfig();
   return directoryConfig.getEntryConfig(entryName);
 }
 public DN getEntryDn(String entryName) throws Exception {
   DirectoryConfig directoryConfig = getDirectoryConfig();
   EntryConfig entryConfig = directoryConfig.getEntryConfig(entryName);
   if (entryConfig == null) return null;
   return entryConfig.getDn();
 }
 public String getEntryName(DN dn) throws Exception {
   DirectoryConfig directoryConfig = getDirectoryConfig();
   return directoryConfig.getEntryNameByDn(dn);
 }