View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/event/eventtype/DbFormsEventTypeStrategy.java,v 1.5 2005/11/30 20:31:18 hkollmann Exp $
3    * $Revision: 1.5 $
4    * $Date: 2005/11/30 20:31:18 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   */
23  
24  package org.dbforms.event.eventtype;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  
30  
31  /***
32   * EventTypeStrategy implementation. Defines the strategy to identify an event
33   * group or type value from an input event string.
34   *
35   * @author Luca Fossato
36   *
37   */
38  public class DbFormsEventTypeStrategy extends AbstractCompositeEventTypeStrategy {
39     /*** logging category */
40     private static Log logCat = LogFactory.getLog(DbFormsEventTypeStrategy.class
41                                                   .getName());
42  
43     /***
44      * Default constructor. <br>
45      * Add the DatabaseEventTypeStrategy and the NavigationEventTypeStrategy
46      * objects to the composite strategy list
47      */
48     public DbFormsEventTypeStrategy() {
49        strategyList.add(new DatabaseEventTypeStrategy());
50        strategyList.add(new NavigationEventTypeStrategy());
51     }
52  
53     /***
54      * Gets the event group value.
55      *
56      * @param eventString the string that identifies an event type
57      *
58      * @return The event group value, or <code>EventType.EVENT_UNDEFINED</code>
59      */
60     public int getEventGroup(String eventString) {
61        int groupValue = EventType.EVENT_UNDEFINED;
62  
63        for (int i = 0; i < strategyList.size(); i++) {
64           logCat.info("::getEventGroup - using [" + getChild(i).getId()
65                       + "] strategy");
66           groupValue = getChild(i)
67                           .getEventGroup(eventString);
68  
69           if (groupValue != EventType.EVENT_UNDEFINED) {
70              break;
71           }
72        }
73  
74        return groupValue;
75     }
76  
77  
78     /***
79      * Gets the event type value.
80      *
81      * @param eventString the string that identifies an event type
82      *
83      * @return The event type value, or <code>EventType.EVENT_UNDEFINED</code>
84      */
85     public String getEventType(String eventString) {
86        String typeValue = String.valueOf(EventType.EVENT_UNDEFINED);
87  
88        for (int i = 0; i < strategyList.size(); i++) {
89           logCat.info("::getEventType - using [" + getChild(i).getId()
90                       + "] strategy");
91           typeValue = getChild(i)
92                          .getEventType(eventString);
93  
94           if (!typeValue.equals(String.valueOf(EventType.EVENT_UNDEFINED))) {
95              break;
96           }
97        }
98  
99        logCat.info("::getEventType - returned the event type [" + typeValue
100                   + "] from [" + eventString + "]");
101 
102       return typeValue;
103    }
104 
105 
106    /***
107     * Gets the EventTypeStrategy identifier.
108     *
109     * @return the EventTypeStrategy identifier
110     */
111    public String getId() {
112       return "DbFormsEventTypeStrategy";
113    }
114 }