View Javadoc
1   /*
2    * scriptable-dataset (https://github.com/hazendaz/scriptable-dataset)
3    *
4    * Copyright 2011-2024 Hazendaz.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of The Apache Software License,
8    * Version 2.0 which accompanies this distribution, and is available at
9    * https://www.apache.org/licenses/LICENSE-2.0.txt
10   *
11   * Contributors:
12   *     Gunnar Morling
13   *     Hazendaz (Jeremy Landis).
14   */
15  package de.gmorling.scriptabledataset;
16  
17  import de.gmorling.scriptabledataset.handlers.ScriptInvocationHandler;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  import java.util.Objects;
22  
23  import lombok.ToString;
24  
25  /**
26   * Configures the usage of one scripting language with a prefix and a list of invocation handlers.
27   */
28  @ToString
29  public class ScriptableDataSetConfig {
30  
31      /** The prefix. */
32      private final String prefix;
33  
34      /** The language name. */
35      private final String languageName;
36  
37      /** The handlers. */
38      private final List<ScriptInvocationHandler> handlers = new ArrayList<>();
39  
40      /**
41       * Creates a new ScriptableDataSetConfig.
42       *
43       * @param languageName
44       *            The name of the language as expected by the JSR 223 scripting engine manager, e.g. "jruby". May not be
45       *            null.
46       * @param prefix
47       *            A prefix, which shall precede fields in a ScriptableDataSet in that language, e.g. "jruby:". May not
48       *            be null.
49       */
50      public ScriptableDataSetConfig(String languageName, String prefix) {
51          this(languageName, prefix, null);
52      }
53  
54      /**
55       * Creates a new ScriptableDataSetConfig.
56       *
57       * @param languageName
58       *            The name of the language as expected by the JSR 223 scripting engine manager, e.g. "jruby". May not be
59       *            null.
60       * @param prefix
61       *            A prefix, which shall precede fields in a ScriptableDataSet in that language, e.g. "jruby:". May not
62       *            be null.
63       * @param handlers
64       *            An optional list with handlers to be applied for fields with the given prefix.
65       */
66      public ScriptableDataSetConfig(String languageName, String prefix, List<ScriptInvocationHandler> handlers) {
67  
68          Objects.requireNonNull(languageName);
69          Objects.requireNonNull(prefix);
70  
71          this.prefix = prefix;
72          this.languageName = languageName;
73  
74          if (handlers != null) {
75              this.handlers.addAll(handlers);
76          }
77      }
78  
79      /**
80       * Gets the prefix.
81       *
82       * @return the prefix
83       */
84      public String getPrefix() {
85          return prefix;
86      }
87  
88      /**
89       * Gets the language name.
90       *
91       * @return the language name
92       */
93      public String getLanguageName() {
94          return languageName;
95      }
96  
97      /**
98       * Gets the handlers.
99       *
100      * @return the handlers
101      */
102     public List<ScriptInvocationHandler> getHandlers() {
103         return handlers;
104     }
105 
106 }