View Javadoc

    1   package net.sourceforge.pmd.sourcetypehandlers;
    2
    3   import net.sourceforge.pmd.SourceType;
    4
    5   import java.util.HashMap;
    6   import java.util.Map;
    7
    8   /***
    9    * Broker for SourceTypeHandler instances for specific SourceTypes.
    10   *
    11   * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
    12   */
    13  public class SourceTypeHandlerBroker {
    14
    15      /***
    16       * Map of SourceType on SourceTypeHandler.
    17       */
    18      private Map mapSourceTypeOnSourceTypeHandler = new HashMap();
    19
    20      /***
    21       * Public constructor.
    22       */
    23      public SourceTypeHandlerBroker() {
    24          initialize();
    25      }
    26
    27      /***
    28       * Initialize the mapSourceTypeOnVisitorsFactory.
    29       */
    30      private void initialize() {
    31          mapSourceTypeOnSourceTypeHandler.put(SourceType.JAVA_13, new Java13Handler());
    32          mapSourceTypeOnSourceTypeHandler.put(SourceType.JAVA_14, new Java14Handler());
    33          mapSourceTypeOnSourceTypeHandler.put(SourceType.JAVA_15, new Java15Handler());
    34          mapSourceTypeOnSourceTypeHandler.put(SourceType.JSP, new JspTypeHandler());
    35      }
    36
    37      public SourceTypeHandler getVisitorsFactoryForSourceType(SourceType sourceType) {
    38          SourceTypeHandler handler = (SourceTypeHandler) mapSourceTypeOnSourceTypeHandler.get(sourceType);
    39
    40          if (handler == null) {
    41              throw new IllegalArgumentException("No VisitorsFactory is registered for SourceType [" + sourceType + "].");
    42          } else {
    43              return handler;
    44          }
    45      }
    46
    47  }