View Javadoc

1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  
20  package org.apache.jsieve;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.jsieve.comparators.Comparator;
24  import org.apache.jsieve.exception.LookupException;
25  import org.apache.jsieve.tests.ExecutableTest;
26  
27  /**
28   * Bean based implementation of context.
29   * 
30   */
31  public class BaseSieveContext extends SieveContext {
32  
33      private ScriptCoordinate coordinate;
34  
35      private ConditionManager conditionManager;
36  
37      private final CommandStateManager commandStateManager;
38  
39      private final CommandManager commandManager;
40  
41      private final ComparatorManager comparatorManager;
42  
43      private final TestManager testManager;
44  
45      private final Log log;
46  
47      public BaseSieveContext(final CommandManager commandManager,
48              final ComparatorManager comparatorManager,
49              final TestManager testManager, final Log log) {
50          this.commandStateManager = new CommandStateManager();
51          this.conditionManager = new ConditionManager();
52          this.testManager = testManager;
53          this.commandManager = commandManager;
54          this.comparatorManager = comparatorManager;
55          this.log = log;
56      }
57  
58      /**
59       * Gets the script position of the current operation.
60       * 
61       * @return <code>ScriptCoordinate</code>, not null
62       */
63      public ScriptCoordinate getCoordinate() {
64          return coordinate;
65      }
66  
67      /**
68       * Sets the script position of the current operation.
69       * 
70       * @param coordinate
71       *            <code>ScriptCoordinate</code>, not null
72       */
73      public void setCoordinate(ScriptCoordinate coordinate) {
74          this.coordinate = coordinate;
75          if (coordinate != null) {
76              coordinate.setLog(getLog());
77          }
78      }
79  
80      public CommandStateManager getCommandStateManager() {
81          return commandStateManager;
82      }
83  
84      public ConditionManager getConditionManager() {
85          return conditionManager;
86      }
87  
88      public void setConditionManager(ConditionManager conditionManager) {
89          this.conditionManager = conditionManager;
90      }
91  
92      public ExecutableCommand getCommand(String name) throws LookupException {
93          return commandManager.getCommand(name);
94      }
95  
96      public Comparator getComparator(String name) throws LookupException {
97          return comparatorManager.getComparator(name);
98      }
99  
100     public ExecutableTest getTest(String name) throws LookupException {
101         return testManager.getTest(name);
102     }
103 
104     public Log getLog() {
105         return log;
106     }
107 }