View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.jxpath;
19  
20  import java.io.Serializable;
21  
22  /**
23   * Variables provide access to a global set of values accessible via XPath. XPath can reference variables using the {@code "$varname"} syntax. To use a custom
24   * implementation of this interface, pass it to {@link JXPathContext#setVariables JXPathContext.setVariables()}
25   */
26  public interface Variables extends Serializable {
27  
28      /**
29       * Defines a new variable with the specified value or modifies the value of an existing variable. May throw UnsupportedOperationException.
30       *
31       * @param name variable name
32       * @param value   to declare
33       */
34      void declareVariable(String name, Object value);
35  
36      /**
37       * Returns the value of the specified variable.
38       *
39       * @param name variable name
40       * @return Object value
41       * @throws IllegalArgumentException if there is no such variable.
42       */
43      Object getVariable(String name);
44  
45      /**
46       * Returns true if the specified variable is declared.
47       *
48       * @param name variable name
49       * @return boolean
50       */
51      boolean isDeclaredVariable(String name);
52  
53      /**
54       * Removes an existing variable. May throw UnsupportedOperationException.
55       *
56       * @param name is a variable name without the "$" sign
57       */
58      void undeclareVariable(String name);
59  }