improve handler and manager api

This commit is contained in:
Sebastian Sdorra
2010-11-05 18:19:43 +01:00
parent 137279c30a
commit fb20f3a26d
20 changed files with 326 additions and 191 deletions

View File

@@ -29,15 +29,10 @@
*
*/
package sonia.scm;
//~--- JDK imports ------------------------------------------------------------
import java.io.Closeable;
import java.io.IOException;
import java.util.Collection;
/**
*
* @author Sebastian Sdorra
@@ -45,65 +40,17 @@ import java.util.Collection;
* @param <T>
* @param <E>
*/
public interface Handler<T, E extends Exception> extends Initable, Closeable
public interface Handler<T extends TypedObject, E extends Exception>
extends HandlerBase<T, E>
{
/**
* Method description
*
*
* @param object
*
* @throws E
* @throws IOException
*/
public void create(T object) throws E, IOException;
/**
* Method description
*
*
* @param object
*
* @throws E
* @throws IOException
*/
public void delete(T object) throws E, IOException;
/**
* Method description
*
*
* @param object
*
* @throws E
* @throws IOException
*/
public void modify(T object) throws E, IOException;
/**
* Method description
*
*
* @param object
*
* @throws E
* @throws IOException
*/
public void refresh(T object) throws E, IOException;
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
*
* @param id
*
* @return
*/
public T get(String id);
public Type getType();
/**
* Method description
@@ -111,5 +58,5 @@ public interface Handler<T, E extends Exception> extends Initable, Closeable
*
* @return
*/
public Collection<T> getAll();
public boolean isConfigured();
}

View File

@@ -0,0 +1,110 @@
/**
* 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;
import java.io.Closeable;
import java.io.IOException;
import java.util.Collection;
/**
*
* @author Sebastian Sdorra
*/
public interface HandlerBase<T extends TypedObject, E extends Exception> extends Initable, Closeable
{
/**
* Method description
*
*
* @param object
*
* @throws E
* @throws IOException
*/
public void create(T object) throws E, IOException;
/**
* Method description
*
*
* @param object
*
* @throws E
* @throws IOException
*/
public void delete(T object) throws E, IOException;
/**
* Method description
*
*
* @param object
*
* @throws E
* @throws IOException
*/
public void modify(T object) throws E, IOException;
/**
* Method description
*
*
* @param object
*
* @throws E
* @throws IOException
*/
public void refresh(T object) throws E, IOException;
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
*
* @param id
*
* @return
*/
public T get(String id);
/**
* Method description
*
*
* @return
*/
public Collection<T> getAll();
}

View File

@@ -29,10 +29,10 @@
*
*/
package sonia.scm.repository;
package sonia.scm;
/**
*
* @author Sebastian Sdorra
*/
public enum RepositoryEvent { CREATE, MODIFY, DELETE }
public enum HandlerEvent { CREATE, MODIFY, DELETE }

View File

@@ -0,0 +1,58 @@
/**
* 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;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
/**
*
* @author Sebastian Sdorra
*
* @param <T>
* @param <E>
*/
public interface Manager<T extends TypedObject, E extends Exception>
extends HandlerBase<T, E>
{
/**
* Method description
*
*
* @return
*/
public Collection<Type> getTypes();
}

View File

@@ -29,20 +29,27 @@
*
*/
package sonia.scm.repository;
package sonia.scm;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.AssertUtil;
import sonia.scm.util.Util;
/**
*
* @author Sebastian Sdorra
*/
public class RepositoryType
public class Type
{
/**
* Constructs ...
* Constructor is required for JAXB
*
*/
public RepositoryType() {}
public Type() {}
/**
* Constructs ...
@@ -51,14 +58,84 @@ public class RepositoryType
* @param name
* @param displayName
*/
public RepositoryType(String name, String displayName)
public Type(String name, String displayName)
{
AssertUtil.assertIsNotEmpty(name);
this.name = name;
this.displayName = displayName;
if (Util.isNotEmpty(displayName))
{
this.displayName = displayName;
}
else
{
this.displayName = name;
}
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param obj
*
* @return
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final Type other = (Type) obj;
if ((this.name == null)
? (other.name != null)
: !this.name.equals(other.name))
{
return false;
}
if ((this.displayName == null)
? (other.displayName != null)
: !this.displayName.equals(other.displayName))
{
return false;
}
return true;
}
/**
* Method description
*
*
* @return
*/
@Override
public int hashCode()
{
int hash = 5;
hash = 37 * hash + ((this.name != null)
? this.name.hashCode()
: 0);
hash = 37 * hash + ((this.displayName != null)
? this.displayName.hashCode()
: 0);
return hash;
}
/**
* Method description
*
@@ -68,11 +145,11 @@ public class RepositoryType
@Override
public String toString()
{
StringBuilder msg = new StringBuilder(name);
StringBuilder out = new StringBuilder("Type{name=");
msg.append(" (").append(displayName).append(")");
out.append(name).append(", displayName=").append(displayName).append("}");
return msg.toString();
return out.toString();
}
//~--- get methods ----------------------------------------------------------

View File

@@ -29,10 +29,13 @@
*
*/
package sonia.scm.group;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.TypedObject;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
@@ -56,7 +59,7 @@ import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name = "groups")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "type", "name", "members" })
public class Group implements Serializable
public class Group implements TypedObject, Serializable
{
/** Field description */
@@ -220,6 +223,7 @@ public class Group implements Serializable
*
* @return
*/
@Override
public String getType()
{
return type;

View File

@@ -29,6 +29,8 @@
*
*/
package sonia.scm.group;
//~--- non-JDK imports --------------------------------------------------------
@@ -39,14 +41,4 @@ import sonia.scm.Handler;
*
* @author Sebastian Sdorra
*/
public interface GroupManager extends Handler<Group, GroupException>
{
/**
* Method description
*
*
* @return
*/
public String getType();
}
public interface GroupManager extends Handler<Group, GroupException> {}

View File

@@ -33,6 +33,7 @@ package sonia.scm.repository;
//~--- JDK imports ------------------------------------------------------------
import sonia.scm.HandlerEvent;
import java.util.HashSet;
import java.util.Set;
@@ -74,7 +75,7 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
* @param repository
* @param event
*/
protected void fireEvent(Repository repository, RepositoryEvent event)
protected void fireEvent(Repository repository, HandlerEvent event)
{
for (RepositoryListener listener : listenerSet)
{

View File

@@ -40,6 +40,7 @@ import sonia.scm.SCMContextProvider;
import java.io.IOException;
import java.util.Collection;
import sonia.scm.Type;
/**
*
@@ -60,20 +61,6 @@ public abstract class AbstractRepositoryManagerDecorator
this.orginal = orginal;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param handler
*/
@Override
public void addHandler(RepositoryHandler handler)
{
orginal.addHandler(handler);
}
/**
* Method description
*
@@ -145,7 +132,7 @@ public abstract class AbstractRepositoryManagerDecorator
* @return
*/
@Override
public Collection<RepositoryType> getTypes()
public Collection<Type> getTypes()
{
return orginal.getTypes();
}

View File

@@ -33,6 +33,7 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.HandlerEvent;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -56,6 +57,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import sonia.scm.Type;
/**
*
@@ -81,7 +83,7 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
public BasicRepositoryManager(Set<RepositoryHandler> handlerSet)
{
handlerMap = new HashMap<String, RepositoryHandler>();
types = new ArrayList<RepositoryType>();
types = new ArrayList<Type>();
for (RepositoryHandler handler : handlerSet)
{
@@ -91,18 +93,11 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param handler
*/
@Override
public void addHandler(RepositoryHandler handler)
private void addHandler(RepositoryHandler handler)
{
AssertUtil.assertIsNotNull(handler);
RepositoryType type = handler.getType();
Type type = handler.getType();
AssertUtil.assertIsNotNull(type);
@@ -158,7 +153,7 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
}
getHandler(repository).create(repository);
fireEvent(repository, RepositoryEvent.CREATE);
fireEvent(repository, HandlerEvent.CREATE);
}
/**
@@ -181,7 +176,7 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
}
getHandler(repository).delete(repository);
fireEvent(repository, RepositoryEvent.DELETE);
fireEvent(repository, HandlerEvent.DELETE);
}
/**
@@ -213,7 +208,7 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
}
getHandler(repository).modify(repository);
fireEvent(repository, RepositoryEvent.MODIFY);
fireEvent(repository, HandlerEvent.MODIFY);
}
/**
@@ -322,7 +317,7 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
* @return
*/
@Override
public Collection<RepositoryType> getTypes()
public Collection<Type> getTypes()
{
return types;
}
@@ -363,5 +358,5 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
private Map<String, RepositoryHandler> handlerMap;
/** Field description */
private List<RepositoryType> types;
private List<Type> types;
}

View File

@@ -29,6 +29,8 @@
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
@@ -44,22 +46,4 @@ import sonia.scm.ListenerSupport;
*/
public interface RepositoryHandler
extends Handler<Repository, RepositoryException>,
ListenerSupport<ConfigChangedListener>
{
/**
* Method description
*
*
* @return
*/
public RepositoryType getType();
/**
* Method description
*
*
* @return
*/
public boolean isConfigured();
}
ListenerSupport<ConfigChangedListener> {}

View File

@@ -31,6 +31,8 @@
package sonia.scm.repository;
import sonia.scm.HandlerEvent;
/**
*
* @author Sebastian Sdorra
@@ -45,5 +47,5 @@ public interface RepositoryListener
* @param repository
* @param event
*/
public void onEvent(Repository repository, RepositoryEvent event);
public void onEvent(Repository repository, HandlerEvent event);
}

View File

@@ -29,36 +29,24 @@
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.Handler;
import sonia.scm.ListenerSupport;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import sonia.scm.Manager;
/**
*
* @author Sebastian Sdorra
*/
public interface RepositoryManager
extends Handler<Repository, RepositoryException>,
extends Manager<Repository, RepositoryException>,
ListenerSupport<RepositoryListener>
{
/**
* Method description
*
*
* @param handler
*/
public void addHandler(RepositoryHandler handler);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
@@ -68,12 +56,4 @@ public interface RepositoryManager
* @return
*/
public RepositoryHandler getHandler(String type);
/**
* Method description
*
*
* @return
*/
public Collection<RepositoryType> getTypes();
}