james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r691061 - in /james/jsieve/trunk/src: main/java/org/apache/jsieve/ test/java/org/apache/jsieve/ test/java/org/apache/jsieve/junit/ test/java/org/apache/jsieve/junit/utils/ test/java/org/apache/jsieve/util/check/
Date Mon, 01 Sep 2008 21:03:13 GMT
Author: rdonkin
Date: Mon Sep  1 14:03:12 2008
New Revision: 691061

URL: http://svn.apache.org/viewvc?rev=691061&view=rev
Log:
SieveFactory is no longer a singleton. JSIEVE-31

Modified:
    james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveFactory.java
    james/jsieve/trunk/src/test/java/org/apache/jsieve/SieveParserVisitorImplQuoteTest.java
    james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/AddressParseTest.java
    james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/ConfigurationManagerTest.java
    james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/utils/JUnitUtils.java
    james/jsieve/trunk/src/test/java/org/apache/jsieve/util/check/ScriptChecker.java

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java?rev=691061&r1=691060&r2=691061&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java Mon Sep 
1 14:03:12 2008
@@ -53,11 +53,6 @@
     private static final String COMPARATORSMAP_PROPERTIES = "org/apache/jsieve/comparatorsmap.properties";
 
     /**
-     * The sole instance of the receiver.
-     */
-    static private ConfigurationManager fieldInstance;
-
-    /**
      * A Map of the Command names and their associated class names.
      */
     private Map fieldCommandMap;
@@ -72,16 +67,14 @@
      */
     private Map fieldComparatorMap;
 
-    //TODO: Temporary fix to allow Logger to be deleted
-    //TODO: inject
-    public static final Log log = LogFactory.getLog(ConditionManager.class);
+    private static final Log log = LogFactory.getLog("org.apache.jsieve");
     
     /**
      * Constructor for ConfigurationManager.
      * 
      * @throws SieveConfigurationException
      */
-    private ConfigurationManager() throws SieveConfigurationException {
+    public ConfigurationManager() throws SieveConfigurationException {
         super();
         try {
             parse();
@@ -95,59 +88,7 @@
             throw new SieveConfigurationException(e);
         }
     }
-
-    /**
-     * Returns the sole instance of the receiver, lazily initialised if
-     * required.
-     * 
-     * @return ConfigurationManager
-     */
-    static public synchronized ConfigurationManager getInstance()
-            throws SieveConfigurationException {
-        ConfigurationManager instance = null;
-        if (null == (instance = getInstanceBasic())) {
-            updateInstance();
-            return getInstance();
-        }
-        return instance;
-    }
-
-    /**
-     * Returns the sole instance of the receiver.
-     * 
-     * @return ConfigurationManager
-     */
-    static private ConfigurationManager getInstanceBasic() {
-        return fieldInstance;
-    }
-
-    /**
-     * Returns a new instance of the receiver.
-     * 
-     * @return ConfigurationManager
-     */
-    static protected ConfigurationManager computeInstance()
-            throws SieveConfigurationException {
-        return new ConfigurationManager();
-    }
-
-    /**
-     * Sets the instance.
-     * 
-     * @param instance
-     *                The instance to set
-     */
-    static protected void setInstance(ConfigurationManager instance) {
-        fieldInstance = instance;
-    }
-
-    /**
-     * Updates the instance.
-     */
-    static protected void updateInstance() throws SieveConfigurationException {
-        setInstance(computeInstance());
-    }
-
+    
     /**
      * <p>
      * Method getConfigStream answers an InputStream over the Sieve
@@ -163,7 +104,7 @@
      * @return InputStream
      * @throws IOException
      */
-    static protected InputStream getConfigStream(String configName) throws IOException {
+    private InputStream getConfigStream(String configName) throws IOException {
         InputStream stream = null;
         // Context classloader is usually right in a JEE evironment
         final ClassLoader contextClassLoader = Thread.currentThread()
@@ -190,7 +131,7 @@
      * 
      * @return Map
      */
-    public synchronized Map getCommandMap() {
+    public Map getCommandMap() {
         if (null == fieldCommandMap) {
             fieldCommandMap = new HashMap();
         }
@@ -203,7 +144,7 @@
      * 
      * @return Map
      */
-    public synchronized Map getTestMap() {
+    public Map getTestMap() {
         if (null == fieldTestMap) {
             fieldTestMap = new HashMap();
         }
@@ -216,7 +157,7 @@
      * 
      * @return Map
      */
-    public synchronized Map getComparatorMap() {
+    public Map getComparatorMap() {
         if (null == fieldComparatorMap) {
             fieldComparatorMap = new HashMap();
         }
@@ -230,7 +171,7 @@
      * @throws SAXException
      * @throws IOException
      */
-    protected void parse() throws SAXException, IOException {
+    private void parse() throws SAXException, IOException {
         InputStream is;
         Properties p;
         is = getConfigStream(COMMANDSMAP_PROPERTIES);
@@ -253,7 +194,7 @@
      * @param commandMap
      *                The commandMap to set
      */
-    protected synchronized void setCommandMap(Map commandMap) {
+    private void setCommandMap(Map commandMap) {
         fieldCommandMap = commandMap;
     }
 
@@ -263,7 +204,7 @@
      * @param testMap
      *                The testMap to set
      */
-    protected synchronized void setTestMap(Map testMap) {
+    private void setTestMap(Map testMap) {
         fieldTestMap = testMap;
     }
 
@@ -273,7 +214,7 @@
      * @param comparatorMap
      *                The comparatorMap to set
      */
-    protected synchronized void setComparatorMap(Map comparatorMap) {
+    private void setComparatorMap(Map comparatorMap) {
         fieldComparatorMap = comparatorMap;
     }
     
@@ -288,4 +229,8 @@
     public TestManager getTestManager() {
         return new TestManagerImpl(fieldTestMap);
     }
+    
+    public Log getLog() {
+        return log;
+    }
 }

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveFactory.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveFactory.java?rev=691061&r1=691060&r2=691061&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveFactory.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveFactory.java Mon Sep  1 14:03:12
2008
@@ -59,11 +59,21 @@
  */
 public class SieveFactory {
 
+    private final CommandManager commandManager;
+    private final ComparatorManager comparatorManager;
+    private final TestManager testManager;
+    private final Log log;
+    
     /**
      * Constructor for SieveFactory.
      */
-    public SieveFactory() {
+    public SieveFactory(final CommandManager commandManager, final ComparatorManager comparatorManager,
+            final TestManager testManager, final Log log) {
         super();
+        this.commandManager = commandManager;
+        this.comparatorManager = comparatorManager;
+        this.testManager = testManager;
+        this.log = log;
     }
 
     /**
@@ -80,20 +90,16 @@
     public Node parse(InputStream inputStream) throws ParseException {
         try {
             final SimpleNode node = new SieveParser(inputStream, "UTF-8").start();
-            final CommandManager commandManager = ConfigurationManager.getInstance().getCommandManager();
-            final TestManager testManager = ConfigurationManager.getInstance().getTestManager();
             SieveValidationVisitor visitor = new SieveValidationVisitor(commandManager, testManager);
             node.jjtAccept(visitor, null);
             return node;
         } catch (ParseException ex) {
-            Log log = ConfigurationManager.log;
             if (log.isErrorEnabled())
                 log.error("Parse failed. Reason: " + ex.getMessage());
             if (log.isDebugEnabled())
                 log.debug("Parse failed.", ex);
             throw ex;
         } catch (SieveException ex) {
-            Log log = ConfigurationManager.log;
             if (log.isErrorEnabled())
                 log.error("Parse failed. Reason: " + ex.getMessage());
             if (log.isDebugEnabled())
@@ -124,10 +130,6 @@
      */
     public void evaluate(MailAdapter mail, Node startNode)
             throws SieveException {
-        final CommandManager commandManager = ConfigurationManager.getInstance().getCommandManager();
-        final ComparatorManager comparatorManager = ConfigurationManager.getInstance().getComparatorManager();
-        final TestManager testManager = ConfigurationManager.getInstance().getTestManager();
-        final Log log = ConfigurationManager.log;
         SieveContext context = new BaseSieveContext(commandManager, comparatorManager, testManager,
log);
         SieveParserVisitor visitor = new SieveParserVisitorImpl(context);
         try {

Modified: james/jsieve/trunk/src/test/java/org/apache/jsieve/SieveParserVisitorImplQuoteTest.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/test/java/org/apache/jsieve/SieveParserVisitorImplQuoteTest.java?rev=691061&r1=691060&r2=691061&view=diff
==============================================================================
--- james/jsieve/trunk/src/test/java/org/apache/jsieve/SieveParserVisitorImplQuoteTest.java
(original)
+++ james/jsieve/trunk/src/test/java/org/apache/jsieve/SieveParserVisitorImplQuoteTest.java
Mon Sep  1 14:03:12 2008
@@ -35,8 +35,9 @@
     
     protected void setUp() throws Exception {
         super.setUp();
-        visitor = new SieveParserVisitorImpl(new BaseSieveContext(ConfigurationManager.getInstance().getCommandManager(),
ConfigurationManager.getInstance().getComparatorManager(),
-                ConfigurationManager.getInstance().getTestManager(), LogFactory.getLog(SieveParserVisitorImplQuoteTest.class)));
+        final ConfigurationManager configurationManager = new ConfigurationManager();
+        visitor = new SieveParserVisitorImpl(new BaseSieveContext(configurationManager.getCommandManager(),
configurationManager.getComparatorManager(),
+                configurationManager.getTestManager(), LogFactory.getLog(SieveParserVisitorImplQuoteTest.class)));
         data = new ArrayList();
         node = new ASTstring(100);
     }

Modified: james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/AddressParseTest.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/AddressParseTest.java?rev=691061&r1=691060&r2=691061&view=diff
==============================================================================
--- james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/AddressParseTest.java (original)
+++ james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/AddressParseTest.java Mon Sep
 1 14:03:12 2008
@@ -40,8 +40,9 @@
 
     protected void setUp() throws Exception {
         super.setUp();
-        context = new BaseSieveContext(ConfigurationManager.getInstance().getCommandManager(),
ConfigurationManager.getInstance().getComparatorManager(), 
-                ConfigurationManager.getInstance().getTestManager(),
+        ConfigurationManager configurationManager = new ConfigurationManager();
+        context = new BaseSieveContext(configurationManager.getCommandManager(), configurationManager.getComparatorManager(),

+                configurationManager.getTestManager(),
                 LogFactory.getLog(AddressParseTest.class));
         mail = (SieveMailAdapter) JUnitUtils.createMail();
         address = new OpenedAddress();

Modified: james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/ConfigurationManagerTest.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/ConfigurationManagerTest.java?rev=691061&r1=691060&r2=691061&view=diff
==============================================================================
--- james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/ConfigurationManagerTest.java
(original)
+++ james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/ConfigurationManagerTest.java
Mon Sep  1 14:03:12 2008
@@ -85,7 +85,7 @@
 
         boolean isTestPassed = false;
         try {
-            Map commandMap = ConfigurationManager.getInstance().getCommandMap();
+            Map commandMap = new ConfigurationManager().getCommandMap();
 
             Iterator mapIter = map.entrySet().iterator();
             while (mapIter.hasNext()) {
@@ -124,7 +124,7 @@
 
         boolean isTestPassed = false;
         try {
-            Map testMap = ConfigurationManager.getInstance().getTestMap();
+            Map testMap = new ConfigurationManager().getTestMap();
 
             Iterator mapIter = map.entrySet().iterator();
             while (mapIter.hasNext()) {
@@ -155,8 +155,7 @@
 
         boolean isTestPassed = false;
         try {
-            Map comparatorMap = ConfigurationManager.getInstance()
-                    .getComparatorMap();
+            Map comparatorMap = new ConfigurationManager().getComparatorMap();
 
             Iterator mapIter = map.entrySet().iterator();
             while (mapIter.hasNext()) {

Modified: james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/utils/JUnitUtils.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/utils/JUnitUtils.java?rev=691061&r1=691060&r2=691061&view=diff
==============================================================================
--- james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/utils/JUnitUtils.java (original)
+++ james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/utils/JUnitUtils.java Mon Sep
 1 14:03:12 2008
@@ -26,6 +26,7 @@
 import javax.mail.Session;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.jsieve.ConfigurationManager;
 import org.apache.jsieve.SieveFactory;
 import org.apache.jsieve.exception.SieveException;
 import org.apache.jsieve.mail.MailAdapter;
@@ -46,7 +47,9 @@
     static public void interpret(MailAdapter mail, String script)
         throws SieveException, ParseException
     {
-        new SieveFactory().interpret(
+        ConfigurationManager configuration = new ConfigurationManager();
+        new SieveFactory(configuration.getCommandManager(), configuration.getComparatorManager(),
+                configuration.getTestManager(), configuration.getLog()).interpret(
             mail,
             new ByteArrayInputStream(script.getBytes()));
     }
@@ -61,7 +64,9 @@
     static public void parse(String script)
         throws SieveException, ParseException
     {
-        new SieveFactory().parse(
+        ConfigurationManager configuration = new ConfigurationManager();
+        new SieveFactory(configuration.getCommandManager(), configuration.getComparatorManager(),
+                configuration.getTestManager(), configuration.getLog()).parse(
             new ByteArrayInputStream(script.getBytes()));
     }
     

Modified: james/jsieve/trunk/src/test/java/org/apache/jsieve/util/check/ScriptChecker.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/test/java/org/apache/jsieve/util/check/ScriptChecker.java?rev=691061&r1=691060&r2=691061&view=diff
==============================================================================
--- james/jsieve/trunk/src/test/java/org/apache/jsieve/util/check/ScriptChecker.java (original)
+++ james/jsieve/trunk/src/test/java/org/apache/jsieve/util/check/ScriptChecker.java Mon Sep
 1 14:03:12 2008
@@ -28,6 +28,7 @@
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.jsieve.ConfigurationManager;
 import org.apache.jsieve.SieveFactory;
 import org.apache.jsieve.exception.SieveException;
 import org.apache.jsieve.mail.ActionFileInto;
@@ -85,7 +86,9 @@
         adapter.setMail(mimeMessage);
         Results results;
         try {
-            new SieveFactory().interpret(adapter, script);
+            ConfigurationManager configuration = new ConfigurationManager();
+            new SieveFactory(configuration.getCommandManager(), configuration.getComparatorManager(),
+                    configuration.getTestManager(), configuration.getLog()).interpret(adapter,
script);
             final List executedActions = adapter.getExecutedActions();
             results = new Results(executedActions);
         } catch (ParseException e) {



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message