From 71aebaa26c07cda648880cb62e48f69c497c0c4d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Fri, 31 Dec 2010 15:35:23 +0100 Subject: [PATCH] improve group api --- .../sonia/scm/group/AbstractGroupManager.java | 95 +++++++++++++++++++ .../src/main/java/sonia/scm/group/Group.java | 60 +++++++++++- .../scm/group/GroupAllreadyExistExeption.java | 2 + .../java/sonia/scm/group/GroupException.java | 2 + .../java/sonia/scm/group/GroupListener.java | 55 +++++++++++ .../java/sonia/scm/group/GroupManager.java | 7 +- 6 files changed, 216 insertions(+), 5 deletions(-) create mode 100644 scm-core/src/main/java/sonia/scm/group/AbstractGroupManager.java create mode 100644 scm-core/src/main/java/sonia/scm/group/GroupListener.java diff --git a/scm-core/src/main/java/sonia/scm/group/AbstractGroupManager.java b/scm-core/src/main/java/sonia/scm/group/AbstractGroupManager.java new file mode 100644 index 0000000000..719b5026af --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/group/AbstractGroupManager.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of SCM-Manager; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.group; + +//~--- non-JDK imports -------------------------------------------------------- + +import sonia.scm.HandlerEvent; + +//~--- JDK imports ------------------------------------------------------------ + +import java.util.HashSet; +import java.util.Set; + +/** + * + * @author Sebastian Sdorra + */ +public abstract class AbstractGroupManager implements GroupManager +{ + + /** + * Method description + * + * + * @param listener + */ + @Override + public void addListener(GroupListener listener) + { + listenerSet.add(listener); + } + + /** + * Method description + * + * + * @param listener + */ + @Override + public void removeListener(GroupListener listener) + { + listenerSet.remove(listener); + } + + /** + * Method description + * + * + * @param group + * @param event + */ + protected void fireEvent(Group group, HandlerEvent event) + { + for (GroupListener listener : listenerSet) + { + listener.onEvent(group, event); + } + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private Set listenerSet = new HashSet(); +} diff --git a/scm-core/src/main/java/sonia/scm/group/Group.java b/scm-core/src/main/java/sonia/scm/group/Group.java index 5fabfb0538..c39641396a 100644 --- a/scm-core/src/main/java/sonia/scm/group/Group.java +++ b/scm-core/src/main/java/sonia/scm/group/Group.java @@ -36,6 +36,7 @@ package sonia.scm.group; //~--- non-JDK imports -------------------------------------------------------- import sonia.scm.TypedObject; +import sonia.scm.Validateable; import sonia.scm.util.Util; //~--- JDK imports ------------------------------------------------------------ @@ -50,7 +51,6 @@ import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; /** * @@ -58,8 +58,9 @@ import javax.xml.bind.annotation.XmlType; */ @XmlRootElement(name = "groups") @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(propOrder = { "type", "name", "members" }) -public class Group implements TypedObject, Serializable +public class Group + implements TypedObject, Serializable, Cloneable, Validateable, + Iterable { /** Field description */ @@ -149,6 +150,42 @@ public class Group implements TypedObject, Serializable members.clear(); } + /** + * Method description + * + * + * @return + * + */ + @Override + public Group clone() + { + Group group = null; + + try + { + group = (Group) super.clone(); + } + catch (CloneNotSupportedException ex) + { + throw new RuntimeException(ex); + } + + return group; + } + + /** + * Method description + * + * + * @return + */ + @Override + public Iterator iterator() + { + return getMembers().iterator(); + } + /** * Method description * @@ -203,6 +240,11 @@ public class Group implements TypedObject, Serializable */ public List getMembers() { + if (members == null) + { + members = new ArrayList(); + } + return members; } @@ -229,6 +271,18 @@ public class Group implements TypedObject, Serializable return type; } + /** + * Method description + * + * + * @return + */ + @Override + public boolean isValid() + { + return Util.isNotEmpty(name) && Util.isNotEmpty(type); + } + //~--- set methods ---------------------------------------------------------- /** diff --git a/scm-core/src/main/java/sonia/scm/group/GroupAllreadyExistExeption.java b/scm-core/src/main/java/sonia/scm/group/GroupAllreadyExistExeption.java index 4389c32180..04ba93a41a 100644 --- a/scm-core/src/main/java/sonia/scm/group/GroupAllreadyExistExeption.java +++ b/scm-core/src/main/java/sonia/scm/group/GroupAllreadyExistExeption.java @@ -29,6 +29,8 @@ * */ + + package sonia.scm.group; /** diff --git a/scm-core/src/main/java/sonia/scm/group/GroupException.java b/scm-core/src/main/java/sonia/scm/group/GroupException.java index d8dd24932e..331a5256e5 100644 --- a/scm-core/src/main/java/sonia/scm/group/GroupException.java +++ b/scm-core/src/main/java/sonia/scm/group/GroupException.java @@ -29,6 +29,8 @@ * */ + + package sonia.scm.group; /** diff --git a/scm-core/src/main/java/sonia/scm/group/GroupListener.java b/scm-core/src/main/java/sonia/scm/group/GroupListener.java new file mode 100644 index 0000000000..8f392e91eb --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/group/GroupListener.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of SCM-Manager; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.group; + +//~--- non-JDK imports -------------------------------------------------------- + +import sonia.scm.HandlerEvent; + +/** + * + * @author Sebastian Sdorra + */ +public interface GroupListener +{ + + /** + * Method description + * + * + * @param group + * @param event + */ + public void onEvent(Group group, HandlerEvent event); +} diff --git a/scm-core/src/main/java/sonia/scm/group/GroupManager.java b/scm-core/src/main/java/sonia/scm/group/GroupManager.java index 7de7e1f5d9..aa2c86b548 100644 --- a/scm-core/src/main/java/sonia/scm/group/GroupManager.java +++ b/scm-core/src/main/java/sonia/scm/group/GroupManager.java @@ -35,10 +35,13 @@ package sonia.scm.group; //~--- non-JDK imports -------------------------------------------------------- -import sonia.scm.Handler; +import sonia.scm.ListenerSupport; +import sonia.scm.Manager; /** * * @author Sebastian Sdorra */ -public interface GroupManager extends Handler {} +public interface GroupManager + extends Manager, + ListenerSupport {}