You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2008/12/23 22:04:14 UTC
svn commit: r729112 - in
/james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet:
ActionDispatcher.java SieveMailAdapter.java
Author: rdonkin
Date: Tue Dec 23 13:04:14 2008
New Revision: 729112
URL: http://svn.apache.org/viewvc?rev=729112&view=rev
Log:
Replace singleton.
Modified:
james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/ActionDispatcher.java
james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java
Modified: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/ActionDispatcher.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/ActionDispatcher.java?rev=729112&r1=729111&r2=729112&view=diff
==============================================================================
--- james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/ActionDispatcher.java (original)
+++ james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/ActionDispatcher.java Tue Dec 23 13:04:14 2008
@@ -26,6 +26,7 @@
import javax.mail.MessagingException;
+import org.apache.jsieve.exception.SieveException;
import org.apache.jsieve.mail.Action;
import org.apache.jsieve.mail.ActionFileInto;
import org.apache.jsieve.mail.ActionKeep;
@@ -39,12 +40,7 @@
* an Action depending on the type of Action received at runtime.
*/
public class ActionDispatcher
-{
- /**
- * The sole instance of the receiver.
- */
- static private ActionDispatcher fieldInstance;
-
+{
/**
* A Map keyed by the type of Action. The values are the methods to invoke to
* handle the Action.
@@ -53,71 +49,14 @@
/**
* Constructor for ActionDispatcher.
+ * @throws NoSuchMethodException
*/
- private ActionDispatcher()
+ public ActionDispatcher() throws SieveException
{
super();
+ setMethodMap(defaultMethodMap());
}
-
- /**
- * Returns the sole instance of the receiver, lazily initialised.
- * @return ActionDispatcher
- */
- public static synchronized ActionDispatcher getInstance()
- {
- ActionDispatcher instance = null;
- if (null == (instance = getInstanceBasic()))
- {
- updateInstance();
- return getInstance();
- }
- return instance;
- }
-
- /**
- * Returns the sole instance of the receiver.
- * @return ActionDispatcher
- */
- private static ActionDispatcher getInstanceBasic()
- {
- return fieldInstance;
- }
-
- /**
- * Returns a new instance of the receiver.
- * @return ActionDispatcher
- */
- protected static ActionDispatcher computeInstance()
- {
- return new ActionDispatcher();
- }
-
- /**
- * Sets the instance.
- * @param instance The instance to set
- */
- protected static void setInstance(ActionDispatcher instance)
- {
- fieldInstance = instance;
- }
-
-
- /**
- * Resets the instance.
- */
- public static void resetInstance()
- {
- setInstance(null);
- }
-
- /**
- * Updates the instance.
- */
- protected static void updateInstance()
- {
- setInstance(computeInstance());
- }
-
+
/**
* Method execute executes the passed Action by invoking the method mapped by the
* receiver with a parameter of the EXACT type of Action.
@@ -155,26 +94,10 @@
}
/**
- * Returns the methodMap, lazily initialised.
- * @return Map
- * @throws NoSuchMethodException
- */
- protected synchronized Map getMethodMap() throws NoSuchMethodException
- {
- Map methodMap = null;
- if (null == (methodMap = getMethodMapBasic()))
- {
- updateMethodMap();
- return getMethodMap();
- }
- return methodMap;
- }
-
- /**
* Returns the methodMap.
* @return Map
*/
- private Map getMethodMapBasic()
+ public Map getMethodMap()
{
return fieldMethodMap;
}
@@ -183,8 +106,9 @@
* Returns a new methodMap.
* @return Map
*/
- protected Map computeMethodMap() throws NoSuchMethodException
+ private Map defaultMethodMap() throws SieveException
{
+ try {
Map methodNameMap = new HashMap();
methodNameMap.put(
ActionFileInto.class,
@@ -219,6 +143,9 @@
Mail.class,
MailetContext.class }));
return methodNameMap;
+ } catch (NoSuchMethodException e) {
+ throw new SieveException(e);
+ }
}
/**
@@ -229,14 +156,4 @@
{
fieldMethodMap = methodMap;
}
-
- /**
- * Updates the methodMap.
- * @throws NoSuchMethodException
- */
- protected void updateMethodMap() throws NoSuchMethodException
- {
- setMethodMap(computeMethodMap());
- }
-
}
Modified: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java?rev=729112&r1=729111&r2=729112&view=diff
==============================================================================
--- james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java (original)
+++ james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java Tue Dec 23 13:04:14 2008
@@ -68,22 +68,18 @@
* List of Actions to perform.
*/
private List fieldActions;
- /**
- * Constructor for SieveMailAdapter.
- */
- private SieveMailAdapter()
- {
- super();
- }
+
+ private final ActionDispatcher dispatcher;
+
/**
* Constructor for SieveMailAdapter.
*
* @param aMail
* @param aMailetContext
*/
- public SieveMailAdapter(Mail aMail, MailetContext aMailetContext)
+ public SieveMailAdapter(final Mail aMail, final MailetContext aMailetContext, final ActionDispatcher dispatcher)
{
- this();
+ this.dispatcher = dispatcher;
setMail(aMail);
setMailetContext(aMailetContext);
}
@@ -143,8 +139,6 @@
*/
public void executeActions() throws SieveException
{
- // Log log = Logger.getLog();
- // boolean isDebugEnabled = log.isDebugEnabled();
ListIterator actionsIter = getActionsIterator();
while (actionsIter.hasNext())
{
@@ -152,8 +146,7 @@
getMailetContext().log("Executing action: " + action.toString());
try
{
- ActionDispatcher.getInstance().execute(action, getMail(),
- getMailetContext());
+ dispatcher.execute(action, getMail(), getMailetContext());
}
catch (NoSuchMethodException e)
{
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org