added basic structure

This commit is contained in:
Sebastian Sdorra
2010-09-08 15:16:42 +02:00
parent 90588d188f
commit 6250565bf3
20 changed files with 562 additions and 7 deletions

View File

@@ -0,0 +1,29 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm;
import sonia.scm.group.GroupManager;
import sonia.scm.repository.RepositoryManager;
/**
*
* @author Sebastian Sdorra
*/
public class BasicContextProvider implements SCMContextProvider {
@Override
public GroupManager getGroupManager()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public RepositoryManager getRepositoryManager()
{
throw new UnsupportedOperationException("Not supported yet.");
}
}

View File

@@ -0,0 +1,24 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm;
/**
*
* @author Sebastian Sdorra
*/
public interface Initable
{
/**
* Method description
*
*
* @param context
*/
public void init(SCMContextProvider context);
}

View File

@@ -0,0 +1,90 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm;
//~--- JDK imports ------------------------------------------------------------
import java.io.Closeable;
import java.io.IOException;
import java.util.Collection;
/**
*
* @author Sebastian Sdorra
*
* @param <T>
* @param <E>
*/
public interface Manager<T, 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 name
*
* @return
*/
public T get(String name);
/**
* Method description
*
*
* @return
*/
public Collection<T> getAll();
}

View File

@@ -0,0 +1,52 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.ServiceUtil;
/**
*
* @author Sebastian Sdorra
*/
public class SCMContext
{
/** Field description */
private static volatile SCMContextProvider provider;
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public static SCMContextProvider getContext()
{
if (provider == null)
{
synchronized (SCMContext.class)
{
if (provider == null)
{
provider = ServiceUtil.getService(SCMContextProvider.class);
if (provider == null)
{
provider = new BasicContextProvider();
}
}
}
}
return provider;
}
}

View File

@@ -0,0 +1,37 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.group.GroupManager;
import sonia.scm.repository.RepositoryManager;
/**
*
* @author Sebastian Sdorra
*/
public interface SCMContextProvider
{
/**
* Method description
*
*
* @return
*/
public GroupManager getGroupManager();
/**
* Method description
*
*
* @return
*/
public RepositoryManager getRepositoryManager();
}

View File

@@ -5,7 +5,7 @@
package sonia.scm;
package sonia.scm.group;
//~--- non-JDK imports --------------------------------------------------------

View File

@@ -0,0 +1,19 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.group;
/**
*
* @author Sebastian Sdorra
*/
public class GroupAllreadyExistExeption extends GroupException
{
/** Field description */
private static final long serialVersionUID = 4042878550219750430L;
}

View File

@@ -0,0 +1,64 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.group;
/**
*
* @author Sebastian Sdorra
*/
public class GroupException extends Exception
{
/** Field description */
private static final long serialVersionUID = 5191341492098994225L;
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
public GroupException()
{
super();
}
/**
* Constructs ...
*
*
* @param message
*/
public GroupException(String message)
{
super(message);
}
/**
* Constructs ...
*
*
* @param cause
*/
public GroupException(Throwable cause)
{
super(cause);
}
/**
* Constructs ...
*
*
* @param message
* @param cause
*/
public GroupException(String message, Throwable cause)
{
super(message, cause);
}
}

View File

@@ -0,0 +1,18 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.group;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.Manager;
/**
*
* @author Sebastian Sdorra
*/
public interface GroupManager extends Manager<Group, GroupException> {}

View File

@@ -5,7 +5,7 @@
package sonia.scm;
package sonia.scm.repository;
//~--- JDK imports ------------------------------------------------------------

View File

@@ -0,0 +1,19 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.repository;
/**
*
* @author Sebastian Sdorra
*/
public class RepositoryAllreadyExistExeption extends RepositoryException
{
/** Field description */
private static final long serialVersionUID = -774929917214137675L;
}

View File

@@ -0,0 +1,64 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.repository;
/**
*
* @author Sebastian Sdorra
*/
public class RepositoryException extends Exception
{
/** Field description */
private static final long serialVersionUID = -4939196278070910058L;
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
public RepositoryException()
{
super();
}
/**
* Constructs ...
*
*
* @param message
*/
public RepositoryException(String message)
{
super(message);
}
/**
* Constructs ...
*
*
* @param cause
*/
public RepositoryException(Throwable cause)
{
super(cause);
}
/**
* Constructs ...
*
*
* @param message
* @param cause
*/
public RepositoryException(String message, Throwable cause)
{
super(message, cause);
}
}

View File

@@ -0,0 +1,19 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.Manager;
/**
*
* @author Sebastian Sdorra
*/
public interface RepositoryManager
extends Manager<Repository, RepositoryException> {}

View File

@@ -5,7 +5,7 @@
package sonia.scm;
package sonia.scm.repository;
/**
*

View File

@@ -0,0 +1,119 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.util;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.ServiceLoader;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Sebastian Sdorra
*/
public class ServiceUtil
{
/** Field description */
private static final Logger logger =
Logger.getLogger(ServiceUtil.class.getName());
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param type
* @param def
* @param <T>
*
* @return
*/
public static <T> T getService(Class<T> type, T def)
{
T result = getService(type);
if (result == null)
{
result = def;
}
return result;
}
/**
* Method description
*
*
* @param type
* @param <T>
*
* @return
*/
public static <T> T getService(Class<T> type)
{
T result = null;
try
{
ServiceLoader<T> loader = ServiceLoader.load(type);
if (loader != null)
{
result = loader.iterator().next();
}
}
catch (NoSuchElementException ex)
{
if (logger.isLoggable(Level.FINEST))
{
logger.log(Level.FINEST, null, ex);
}
}
return result;
}
/**
* Method description
*
*
* @param type
* @param <T>
*
* @return
*/
public static <T> List<T> getServices(Class<T> type)
{
List<T> result = new ArrayList<T>();
try
{
ServiceLoader<T> loader = ServiceLoader.load(type);
if (loader != null)
{
for (T service : loader)
{
result.add(service);
}
}
}
catch (NoSuchElementException ex)
{
if (logger.isLoggable(Level.FINEST))
{
logger.log(Level.FINEST, null, ex);
}
}
return result;
}
}