jdk/src/share/classes/javax/script/Invocable.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 18567 35b36d452864
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18567
35b36d452864 8019320: Fix doclint issues in javax.script
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.script;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * The optional interface implemented by ScriptEngines whose methods allow the invocation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * procedures in scripts that have previously been executed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @author  Mike Grogan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author  A. Sundararajan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public interface Invocable  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     * Calls a method on a script object compiled during a previous script execution,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * which is retained in the state of the <code>ScriptEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * @param name The name of the procedure to be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * @param thiz If the procedure is a member  of a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * defined in the script and thiz is an instance of that class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * returned by a previous execution or invocation, the named method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * called through that instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * @param args Arguments to pass to the procedure.  The rules for converting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * the arguments to scripting variables are implementation-specific.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @return The value returned by the procedure.  The rules for converting the scripting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * variable returned by the script method to a Java Object are implementation-specific.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18567
diff changeset
    54
     * @throws ScriptException if an error occurs during invocation of the method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @throws NoSuchMethodException if method with given name or matching argument types cannot be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @throws NullPointerException if the method name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @throws IllegalArgumentException if the specified thiz is null or the specified Object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * does not represent a scripting object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public Object invokeMethod(Object thiz, String name, Object... args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        throws ScriptException, NoSuchMethodException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Used to call top-level procedures and functions defined in scripts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
18567
35b36d452864 8019320: Fix doclint issues in javax.script
darcy
parents: 5506
diff changeset
    66
     * @param name of the procedure or function to call
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param args Arguments to pass to the procedure or function
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @return The value returned by the procedure or function
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18567
diff changeset
    70
     * @throws ScriptException if an error occurs during invocation of the method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @throws NoSuchMethodException if method with given name or matching argument types cannot be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @throws NullPointerException if method name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     public Object invokeFunction(String name, Object... args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        throws ScriptException, NoSuchMethodException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Returns an implementation of an interface using functions compiled in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * the interpreter. The methods of the interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * may be implemented using the <code>invokeFunction</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
18567
35b36d452864 8019320: Fix doclint issues in javax.script
darcy
parents: 5506
diff changeset
    83
     * @param <T> the type of the interface to return
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param clasz The <code>Class</code> object of the interface to return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @return An instance of requested interface - null if the requested interface is unavailable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * i. e. if compiled functions in the <code>ScriptEngine</code> cannot be found matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * the ones in the requested interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @throws IllegalArgumentException if the specified <code>Class</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * is null or is not an interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public <T> T getInterface(Class<T> clasz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Returns an implementation of an interface using member functions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * a scripting object compiled in the interpreter. The methods of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * interface may be implemented using the <code>invokeMethod</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
18567
35b36d452864 8019320: Fix doclint issues in javax.script
darcy
parents: 5506
diff changeset
   100
     * @param <T> the type of the interface to return
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param thiz The scripting object whose member functions are used to implement the methods of the interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param clasz The <code>Class</code> object of the interface to return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @return An instance of requested interface - null if the requested interface is unavailable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * i. e. if compiled methods in the <code>ScriptEngine</code> cannot be found matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * the ones in the requested interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @throws IllegalArgumentException if the specified <code>Class</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * is null or is not an interface, or if the specified Object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * null or does not represent a scripting object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     public <T> T getInterface(Object thiz, Class<T> clasz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
}