| 1 | /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 2 | * |
| 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 | |
| 7 | package org.mozilla.javascript.xml; |
| 8 | |
| 9 | import org.mozilla.javascript.*; |
| 10 | |
| 11 | /** |
| 12 | * This Interface describes what all XML objects (XML, XMLList) should have in common. |
| 13 | * |
| 14 | */ |
| 15 | public abstract class XMLObject extends IdScriptableObject |
| 16 | { |
| 17 | |
| 18 | static final long serialVersionUID = 8455156490438576500L; |
| 19 | |
| 20 | public XMLObject() |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | public XMLObject(Scriptable scope, Scriptable prototype) |
| 25 | { |
| 26 | super(scope, prototype); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Implementation of ECMAScript [[Has]]. |
| 31 | */ |
| 32 | public abstract boolean has(Context cx, Object id); |
| 33 | |
| 34 | /** |
| 35 | * Implementation of ECMAScript [[Get]]. |
| 36 | */ |
| 37 | public abstract Object get(Context cx, Object id); |
| 38 | |
| 39 | /** |
| 40 | * Implementation of ECMAScript [[Put]]. |
| 41 | */ |
| 42 | public abstract void put(Context cx, Object id, Object value); |
| 43 | |
| 44 | /** |
| 45 | * Implementation of ECMAScript [[Delete]]. |
| 46 | */ |
| 47 | public abstract boolean delete(Context cx, Object id); |
| 48 | |
| 49 | |
| 50 | public abstract Object getFunctionProperty(Context cx, String name); |
| 51 | |
| 52 | public abstract Object getFunctionProperty(Context cx, int id); |
| 53 | |
| 54 | /** |
| 55 | * Return an additional object to look for methods that runtime should |
| 56 | * consider during method search. Return null if no such object available. |
| 57 | */ |
| 58 | public abstract Scriptable getExtraMethodSource(Context cx); |
| 59 | |
| 60 | /** |
| 61 | * Generic reference to implement x.@y, x..y etc. |
| 62 | */ |
| 63 | public abstract Ref memberRef(Context cx, Object elem, |
| 64 | int memberTypeFlags); |
| 65 | |
| 66 | /** |
| 67 | * Generic reference to implement x::ns, x.@ns::y, x..@ns::y etc. |
| 68 | */ |
| 69 | public abstract Ref memberRef(Context cx, Object namespace, Object elem, |
| 70 | int memberTypeFlags); |
| 71 | |
| 72 | /** |
| 73 | * Wrap this object into NativeWith to implement the with statement. |
| 74 | */ |
| 75 | public abstract NativeWith enterWith(Scriptable scope); |
| 76 | |
| 77 | /** |
| 78 | * Wrap this object into NativeWith to implement the .() query. |
| 79 | */ |
| 80 | public abstract NativeWith enterDotQuery(Scriptable scope); |
| 81 | |
| 82 | /** |
| 83 | * Custom <tt>+</tt> operator. |
| 84 | * Should return {@link Scriptable#NOT_FOUND} if this object does not have |
| 85 | * custom addition operator for the given value, |
| 86 | * or the result of the addition operation. |
| 87 | * <p> |
| 88 | * The default implementation returns {@link Scriptable#NOT_FOUND} |
| 89 | * to indicate no custom addition operation. |
| 90 | * |
| 91 | * @param cx the Context object associated with the current thread. |
| 92 | * @param thisIsLeft if true, the object should calculate this + value |
| 93 | * if false, the object should calculate value + this. |
| 94 | * @param value the second argument for addition operation. |
| 95 | */ |
| 96 | public Object addValues(Context cx, boolean thisIsLeft, Object value) |
| 97 | { |
| 98 | return Scriptable.NOT_FOUND; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Gets the value returned by calling the typeof operator on this object. |
| 103 | * @see org.mozilla.javascript.ScriptableObject#getTypeOf() |
| 104 | * @return "xml" or "undefined" if {@link #avoidObjectDetection()} returns <code>true</code> |
| 105 | */ |
| 106 | @Override |
| 107 | public String getTypeOf() |
| 108 | { |
| 109 | return avoidObjectDetection() ? "undefined" : "xml"; |
| 110 | } |
| 111 | } |