UnmodifiableConfiguration.java

  1. package org.jbehave.core.configuration;

  2. import java.util.Comparator;
  3. import java.util.Set;

  4. import com.thoughtworks.paranamer.Paranamer;

  5. import org.apache.commons.lang3.builder.ToStringBuilder;
  6. import org.apache.commons.lang3.builder.ToStringStyle;
  7. import org.jbehave.core.condition.StepConditionMatcher;
  8. import org.jbehave.core.embedder.StoryControls;
  9. import org.jbehave.core.expressions.ExpressionResolver;
  10. import org.jbehave.core.failures.FailureStrategy;
  11. import org.jbehave.core.failures.PendingStepStrategy;
  12. import org.jbehave.core.io.StoryLoader;
  13. import org.jbehave.core.io.StoryPathResolver;
  14. import org.jbehave.core.model.ExamplesTableFactory;
  15. import org.jbehave.core.model.Story;
  16. import org.jbehave.core.model.TableTransformerMonitor;
  17. import org.jbehave.core.parsers.AliasParser;
  18. import org.jbehave.core.parsers.CompositeParser;
  19. import org.jbehave.core.parsers.StepPatternParser;
  20. import org.jbehave.core.parsers.StoryParser;
  21. import org.jbehave.core.reporters.StoryReporter;
  22. import org.jbehave.core.reporters.StoryReporterBuilder;
  23. import org.jbehave.core.reporters.ViewGenerator;
  24. import org.jbehave.core.steps.ParameterControls;
  25. import org.jbehave.core.steps.ParameterConverters;
  26. import org.jbehave.core.steps.StepCollector;
  27. import org.jbehave.core.steps.StepMonitor;

  28. /**
  29.  * Decorator of Configuration that disables modification of configuration
  30.  * elements.
  31.  */
  32. public class UnmodifiableConfiguration extends Configuration {

  33.     private final Configuration delegate;

  34.     public UnmodifiableConfiguration(Configuration delegate) {
  35.         this.delegate = delegate;
  36.     }

  37.     @Override
  38.     public StoryReporter defaultStoryReporter() {
  39.         return delegate.defaultStoryReporter();
  40.     }

  41.     @Override
  42.     public StoryParser storyParser() {
  43.         return delegate.storyParser();
  44.     }

  45.     @Override
  46.     public AliasParser aliasParser() {
  47.         return delegate.aliasParser();
  48.     }

  49.     @Override
  50.     public Set<String> aliasPaths() {
  51.         return delegate.aliasPaths();
  52.     }

  53.     @Override
  54.     public CompositeParser compositeParser() {
  55.         return delegate.compositeParser();
  56.     }

  57.     public PendingStepStrategy pendingStepStrategy() {
  58.         return delegate.pendingStepStrategy();
  59.     }

  60.     @Override
  61.     public StepCollector stepCollector() {
  62.         return delegate.stepCollector();
  63.     }

  64.     @Override
  65.     public FailureStrategy failureStrategy() {
  66.         return delegate.failureStrategy();
  67.     }

  68.     @Override
  69.     public Keywords keywords() {
  70.         return delegate.keywords();
  71.     }

  72.     @Override
  73.     public ParameterConverters parameterConverters() {
  74.         return delegate.parameterConverters();
  75.     }

  76.     @Override
  77.     public ExpressionResolver expressionResolver() {
  78.         return delegate.expressionResolver();
  79.     }

  80.     @Override
  81.     public ParameterControls parameterControls() {
  82.         return delegate.parameterControls();
  83.     }
  84.    
  85.     @Override
  86.     public Paranamer paranamer() {
  87.         return delegate.paranamer();
  88.     }

  89.     @Override
  90.     public ViewGenerator viewGenerator() {
  91.         return delegate.viewGenerator();
  92.     }

  93.     @Override
  94.     public ExamplesTableFactory examplesTableFactory() {
  95.         return delegate.examplesTableFactory();
  96.     }

  97.     @Override
  98.     public StepMonitor stepMonitor() {
  99.         return delegate.stepMonitor();
  100.     }

  101.     @Override
  102.     public StepPatternParser stepPatternParser() {
  103.         return delegate.stepPatternParser();
  104.     }

  105.     @Override
  106.     public boolean dryRun() {
  107.         return delegate.dryRun();
  108.     }

  109.     @Override
  110.     public StoryControls storyControls() {
  111.         return delegate.storyControls();
  112.     }

  113.     @Override
  114.     public StoryLoader storyLoader() {
  115.         return delegate.storyLoader();
  116.     }

  117.     @Override
  118.     public StoryPathResolver storyPathResolver() {
  119.         return delegate.storyPathResolver();
  120.     }

  121.     @Override
  122.     public StepConditionMatcher stepConditionMatcher() {
  123.         return delegate.stepConditionMatcher();
  124.     }

  125.     @Override
  126.     public TableTransformerMonitor tableTransformerMonitor() {
  127.         return delegate.tableTransformerMonitor();
  128.     }

  129.     @Override
  130.     public Configuration useStepConditionMatcher(StepConditionMatcher stepConditionMatcher) {
  131.         throw notAllowed();
  132.     }

  133.     @Override
  134.     public StoryReporter storyReporter(String storyPath) {
  135.         return delegate.storyReporter(storyPath);
  136.     }

  137.     @Override
  138.     public StoryReporterBuilder storyReporterBuilder() {
  139.         return delegate.storyReporterBuilder();
  140.     }

  141.     @Override
  142.     public Comparator<Story> storyExecutionComparator() {
  143.         return delegate.storyExecutionComparator();
  144.     }

  145.     @Override
  146.     public Configuration useKeywords(Keywords keywords) {
  147.         throw notAllowed();
  148.     }

  149.     @Override
  150.     public Configuration useStepCollector(StepCollector stepCollector) {
  151.         throw notAllowed();
  152.     }

  153.     @Override
  154.     public Configuration usePendingStepStrategy(PendingStepStrategy pendingStepStrategy) {
  155.         throw notAllowed();
  156.     }

  157.     @Override
  158.     public Configuration useFailureStrategy(FailureStrategy failureStrategy) {
  159.         throw notAllowed();
  160.     }

  161.     @Override
  162.     public Configuration doDryRun(Boolean dryRun) {
  163.         throw notAllowed();
  164.     }

  165.     @Override
  166.     public Configuration useStoryControls(StoryControls storyControls) {
  167.         throw notAllowed();
  168.     }

  169.     @Override
  170.     public Configuration useStoryParser(StoryParser storyParser) {
  171.         throw notAllowed();
  172.     }

  173.     @Override
  174.     public Configuration useAliasParser(AliasParser storyParser) {
  175.         throw notAllowed();
  176.     }

  177.     @Override
  178.     public Configuration useAliasPaths(Set<String> aliasPaths) {
  179.         throw notAllowed();
  180.     }

  181.     @Override
  182.     public Configuration useCompositeParser(CompositeParser compositeParser) {
  183.         throw notAllowed();
  184.     }

  185.     @Override
  186.     public Configuration useDefaultStoryReporter(StoryReporter storyReporter) {
  187.         throw notAllowed();
  188.     }

  189.     @Override
  190.     public Configuration useParameterConverters(ParameterConverters parameterConverters) {
  191.         throw notAllowed();
  192.     }

  193.     @Override
  194.     public Configuration useExpressionResolver(ExpressionResolver expressionResolver) {
  195.         throw notAllowed();
  196.     }

  197.     @Override
  198.     public Configuration useParameterControls(ParameterControls parameterControls) {
  199.         throw notAllowed();
  200.     }    

  201.     @Override
  202.     public Configuration useParanamer(Paranamer paranamer) {
  203.         throw notAllowed();
  204.     }

  205.     @Override
  206.     public Configuration useStepMonitor(StepMonitor stepMonitor) {
  207.         throw notAllowed();
  208.     }

  209.     @Override
  210.     public Configuration useStepPatternParser(StepPatternParser stepPatternParser) {
  211.         throw notAllowed();
  212.     }

  213.     @Override
  214.     public Configuration useViewGenerator(ViewGenerator viewGenerator) {
  215.         throw notAllowed();
  216.     }

  217.     @Override
  218.     public Configuration useStoryLoader(StoryLoader storyLoader) {
  219.         throw notAllowed();
  220.     }

  221.     @Override
  222.     public Configuration useExamplesTableFactory(ExamplesTableFactory examplesTableFactory) {
  223.         throw notAllowed();
  224.     }

  225.     @Override
  226.     public Configuration useStoryPathResolver(StoryPathResolver storyPathResolver) {
  227.         throw notAllowed();
  228.     }

  229.     @Override
  230.     public Configuration useStoryReporterBuilder(StoryReporterBuilder storyReporterBuilder) {
  231.         throw notAllowed();
  232.     }

  233.     @Override
  234.     public Configuration useStoryExecutionComparator(Comparator<Story> storyExecutionComparator) {
  235.         throw notAllowed();
  236.     }

  237.     @Override
  238.     public Configuration useTableTransformerMonitor(TableTransformerMonitor tableTransformerMonitor) {
  239.         throw notAllowed();
  240.     }

  241.     private RuntimeException notAllowed() {
  242.         return new ModificationNotAllowed();
  243.     }

  244.     @Override
  245.     public String toString() {
  246.         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append(delegate).toString();
  247.     }

  248.     @SuppressWarnings("serial")
  249.     public static class ModificationNotAllowed extends RuntimeException {
  250.         public ModificationNotAllowed() {
  251.             super("Configuration elements are unmodifiable");
  252.         }
  253.     }
  254. }