ScriptObject.java revision 9883:903a2e023ffb
1/*
2 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24package sun.jvm.hotspot.utilities.soql;
25
26/**
27 * Any Java object supporting this interface can be
28 * accessed from scripts with "simpler" access pattern.
29 * For example, a script engine may support natural
30 * property/field access syntax for the properties exposed
31 * via this interface. We use this interface so that we
32 * can dynamically add/delete/modify fields exposed to
33 * scripts. If we stick to JavaBean pattern, then property
34 * set is fixed.
35 */
36public interface ScriptObject {
37  // special sentinel to denote no-result -- so that
38  // null could be used as proper value
39  public static final Object UNDEFINED = new Object();
40  // empty object array
41  public static final Object[] EMPTY_ARRAY = new Object[0];
42
43  /*
44   * Returns all property names supported by this object.
45   * Property "name" is either a String or an Integer".
46   */
47  public Object[] getIds();
48
49  /**
50   * Get the value of the named property.
51   */
52  public Object get(String name);
53
54  /**
55   * Get the value of the "indexed" property.
56   * Returns UNDEFINED if the property does not exist.
57   */
58  public Object get(int index);
59
60  /**
61   * Set the value of the named property.
62   */
63  public void put(String name, Object value);
64
65  /**
66   * Set the value of the indexed property.
67   */
68  public void put(int index, Object value);
69
70  /**
71   * Returns whether the named property exists or not.
72   */
73  public boolean has(String name);
74
75  /**
76   * Returns whether the indexed property exists or not.
77   */
78  public boolean has(int index);
79
80  /**
81   * Deletes the named property. Returns true on success.
82   */
83  public boolean delete(String name);
84
85  /**
86   * Deletes the indexed property. Returns true on success.
87   */
88  public boolean delete(int index);
89}
90