View Javadoc

1   package com.explosion.expfmodules.wizard.standard;
2   
3   import java.util.Iterator;
4   import java.util.Map;
5   
6   import com.explosion.expfmodules.wizard.Condition;
7   import com.explosion.expfmodules.wizard.StepDefinition;
8   import com.explosion.expfmodules.wizard.Wizard;
9   import com.explosion.utilities.preferences.Preference;
10  
11  
12  /* =============================================================================
13   *       
14   *     Copyright 2004 Stephen Cowx
15   *
16   *     Licensed under the Apache License, Version 2.0 (the "License");
17   *     you may not use this file except in compliance with the License.
18   *     You may obtain a copy of the License at
19   *
20   *     http://www.apache.org/licenses/LICENSE-2.0
21   *
22   *     Unless required by applicable law or agreed to in writing, software
23   *     distributed under the License is distributed on an "AS IS" BASIS,
24   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25   *     See the License for the specific language governing permissions and
26   *     limitations under the License.
27   * 
28   * =============================================================================
29   */
30  
31  /***
32   * @author Stephen Cowx
33   * Created on 16-Feb-2005
34   */
35  public class StandardCondition implements Condition
36  {
37      private Map dataItems;
38      private static org.apache.log4j.Logger log = org.apache.log4j.LogManager.getLogger(StandardCondition.class);
39      
40      /***
41       * Returns a boolean whether or not this condition has been met
42       * This implementation compares the values of the dataitems in the condition
43       * with the correpsonding values in the current step of the wizard, if they are all
44       * present and they match then true is returned otherwise false is returned. 
45       * @see com.explosion.expfmodules.wizard.Condition#conditionMet()
46       * @return
47       */
48      public boolean conditionMet(Wizard wizard)
49      {
50          StepDefinition currentStep = wizard.getCurrentStep().getStepDefinition();
51          for (Iterator it = dataItems.keySet().iterator(); it.hasNext();)
52          {
53              Object key = it.next();
54              Object requiredValue = dataItems.get(key);
55              PreferenceDataItem item = (PreferenceDataItem) currentStep.getDataItems().get(key);
56              Preference currentValue = item.getPreference();
57              log.debug("Comparing " + key + " Required:"+ requiredValue + " Current:" + currentValue);
58              if (currentValue == null || !requiredValue.equals(currentValue.getValue()))
59              {
60                  return false;
61              }
62          }
63          
64          return true;
65      }
66      
67      /***
68       * @return Returns the dataItems.
69       */
70      public Map getDataItems()
71      {
72          return dataItems;
73      }
74      /***
75       * @param dataItems The dataItems to set.
76       */
77      public void setDataItems(Map dataItems)
78      {
79          this.dataItems = dataItems;
80      }
81  }