Commits

Sebastian Sdorra committed 162ba6d

added ListenerSupport for repositoryManagers

Comments (0)

Files changed (6)

plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryManager.java

  *
  * @author Sebastian Sdorra
  */
-public class HgRepositoryManager implements RepositoryManager
+public class HgRepositoryManager extends AbstractRepositoryManager
 {
 
   /** Field description */

scm-core/src/main/java/sonia/scm/ListenerSupport.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+
+
+package sonia.scm;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ *
+ * @param <T>
+ */
+public interface ListenerSupport<T>
+{
+
+  /**
+   * Method description
+   *
+   *
+   * @param listener
+   */
+  public void addListener(T listener);
+
+  /**
+   * Method description
+   *
+   *
+   * @param listener
+   */
+  public void removeListener(T listener);
+}

scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryManager.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+
+
+package sonia.scm.repository;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+public abstract class AbstractRepositoryManager implements RepositoryManager
+{
+
+  /**
+   * Method description
+   *
+   *
+   * @param listener
+   */
+  @Override
+  public void addListener(RepositoryListener listener)
+  {
+    listenerSet.add(listener);
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param listener
+   */
+  @Override
+  public void removeListener(RepositoryListener listener)
+  {
+    listenerSet.remove(listener);
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param repository
+   * @param event
+   */
+  protected void fireEvent(Repository repository, RepositoryEvent event)
+  {
+    for (RepositoryListener listener : listenerSet)
+    {
+      listener.onEvent(repository, event);
+    }
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  private Set<RepositoryListener> listenerSet =
+    new HashSet<RepositoryListener>();
+}

scm-core/src/main/java/sonia/scm/repository/RepositoryEvent.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+
+
+package sonia.scm.repository;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+public enum RepositoryEvent { CREATE, MODIFY, DELETE }

scm-core/src/main/java/sonia/scm/repository/RepositoryListener.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+
+
+package sonia.scm.repository;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+public interface RepositoryListener
+{
+
+  //~--- methods --------------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param repository
+   * @param event
+   */
+  public void onEvent(Repository repository, RepositoryEvent event);
+}

scm-core/src/main/java/sonia/scm/repository/RepositoryManager.java

 
 //~--- non-JDK imports --------------------------------------------------------
 
+import sonia.scm.ListenerSupport;
 import sonia.scm.Manager;
 
 /**
  * @author Sebastian Sdorra
  */
 public interface RepositoryManager
-        extends Manager<Repository, RepositoryException>
+        extends Manager<Repository, RepositoryException>, ListenerSupport<RepositoryListener>
 {
 
   /**