View Javadoc

1   /*
2    * Copyright 2010 Fraunhofer Gesellschaft, Munich, Germany,
3    * for its Fraunhofer Institute for Computer Architecture and Software
4    * Technology (FIRST), Berlin, Germany. All rights reserved.
5    * http://www.first.fraunhofer.de/
6    */
7   
8   package net.kwfgrid.gwes;
9   
10  import net.kwfgrid.gwes.exception.NoSuchWorkflowException;
11  
12  import java.util.Hashtable;
13  
14  import org.apache.log4j.Logger;
15  
16  /**
17   * A workflow handler table is an extended Hashtable with GenericWorkflowHandlers as values and their corresponding
18   * workflow instance identifiers as keys.
19   * @author Andreas Hoheisel
20   *         (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
21   * @version $Id: GenericWorkflowHandlerTable.java 1447 2010-12-10 11:27:08Z hoheisel $
22   */
23  public class GenericWorkflowHandlerTable extends Hashtable<String, GenericWorkflowHandler> {
24  
25      /**
26       * log4j logger
27       */
28      static final Logger logger = Logger.getLogger(GenericWorkflowHandlerTable.class);
29  
30      /**
31       * Maps the specified <code>workflowID</code> to the specified
32       * <code>handler</code> in this table. Neither the workflowID nor the
33       * handler can be <code>null</code>. <p>
34       *
35       * @param workflowID The workflow identifier
36       * @param handler The workflow handler
37       * @return     the previous workflow handler of the specified workflowID in this hashtable,
38       *             or <code>null</code> if it did not have one.
39       */
40      public final GenericWorkflowHandler put(String workflowID, GenericWorkflowHandler handler) {
41          return super.put(workflowID, handler);
42      }
43  
44      /**
45       * Returns the handler to which the specified workflowID is mapped in this hashtable. This method
46       * will never return <code>null</code>.
47       *
48       * @param   workflowID   a workflowID in the hashtable.
49       * @return  the handler to which the workflowID is mapped in this hashtable;
50       * @throws  NullPointerException  if the workflowID is <code>null</code>.
51       * @throws  NoSuchWorkflowException if the workflowID is not mapped to any handler in
52       *          this hashtable.
53       * @see     #put(String, GenericWorkflowHandler)
54       */
55      public final GenericWorkflowHandler get(String workflowID) throws NoSuchWorkflowException {
56          GenericWorkflowHandler handler = super.get(workflowID);
57          if (handler == null) {
58              throw new NoSuchWorkflowException("Workflow with ID '" + workflowID + "' is not available in memory!");
59          }
60          return handler;
61      }
62  
63      /**
64       * Removes the workflowID (and its corresponding handler) from this
65       * hashtable. This method does nothing if the workflowID is not in the hashtable.
66       *
67       * @param   workflowID   the workflowID that needs to be removed.
68       * @return  the handler to which the workflowID had been mapped in this hashtable,
69       *          or <code>null</code> if the workflowID did not have a mapping.
70       * @throws  NullPointerException  if the workflowID is <code>null</code>.
71       */
72      public final GenericWorkflowHandler remove(String workflowID) {
73          return super.remove(workflowID);
74      }
75  
76  }