⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlobjectimpl.java

📁 這是一個javascript 的 interpreter是了解 web browser的好材料
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Rhino code, released * May 6, 1999. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1997-2000 * the Initial Developer. All Rights Reserved. * * Contributor(s): *   Igor Bukanov *   Ethan Hugg *   Terry Lucas *   Milen Nankov * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 2 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. If * you wish to allow use of your version of this file only under the terms of * the GPL and not to allow others to use your version of this file under the * MPL, indicate your decision by deleting the provisions above and replacing * them with the notice and other provisions required by the GPL. If you do * not delete the provisions above, a recipient may use your version of this * file under either the MPL or the GPL. * * ***** END LICENSE BLOCK ***** */package org.mozilla.javascript.xml.impl.xmlbeans;import org.mozilla.javascript.*;import org.mozilla.javascript.xml.*;/** *  This abstract class describes what all XML objects (XML, XMLList) should have in common. * * @see XML */abstract class XMLObjectImpl extends XMLObject{    private static final Object XMLOBJECT_TAG = new Object();    protected final XMLLibImpl lib;    protected boolean prototypeFlag;    protected XMLObjectImpl(XMLLibImpl lib, XMLObject prototype)    {        super(lib.globalScope(), prototype);        this.lib = lib;    }    /**     * ecmaHas(cx, id) calls this after resolving when id to XMLName     * and checking it is not Uint32 index.     */    abstract boolean hasXMLProperty(XMLName name);    /**     * ecmaGet(cx, id) calls this after resolving when id to XMLName     * and checking it is not Uint32 index.     */    abstract Object getXMLProperty(XMLName name);    /**     * ecmaPut(cx, id, value) calls this after resolving when id to XMLName     * and checking it is not Uint32 index.     */    abstract void putXMLProperty(XMLName name, Object value);    /**     * ecmaDelete(cx, id) calls this after resolving when id to XMLName     * and checking it is not Uint32 index.     */    abstract void deleteXMLProperty(XMLName name);    /**     * Test XML equality with target the target.     */    abstract boolean equivalentXml(Object target);    // Methods from section 12.4.4 in the spec    abstract XML addNamespace(Namespace ns);    abstract XML appendChild(Object xml);    abstract XMLList attribute(XMLName xmlName);    abstract XMLList attributes();    abstract XMLList child(long index);    abstract XMLList child(XMLName xmlName);    abstract int childIndex();    abstract XMLList children();    abstract XMLList comments();    abstract boolean contains(Object xml);    abstract Object copy();    abstract XMLList descendants(XMLName xmlName);    abstract Object[] inScopeNamespaces();    abstract XML insertChildAfter(Object child, Object xml);    abstract XML insertChildBefore(Object child, Object xml);    abstract boolean hasOwnProperty(XMLName xmlName);    abstract boolean hasComplexContent();    abstract boolean hasSimpleContent();    abstract int length();    abstract String localName();    abstract QName name();    abstract Object namespace(String prefix);    abstract Object[] namespaceDeclarations();    abstract Object nodeKind();    abstract void normalize();    abstract Object parent();    abstract XML prependChild(Object xml);    abstract Object processingInstructions(XMLName xmlName);    abstract boolean propertyIsEnumerable(Object member);    abstract XML removeNamespace(Namespace ns);    abstract XML replace(long index, Object xml);    abstract XML replace(XMLName name, Object xml);    abstract XML setChildren(Object xml);    abstract void setLocalName(String name);    abstract void setName(QName xmlName);    abstract void setNamespace(Namespace ns);    abstract XMLList text();    public abstract String toString();    abstract String toSource(int indent);    abstract String toXMLString(int indent);    abstract Object valueOf();    /**     * Extension to access native implementation from scripts     */    abstract org.apache.xmlbeans.XmlObject getXmlObject();    protected abstract Object jsConstructor(Context cx, boolean inNewExpr,                                            Object[] args);    final Object getMethod(String id)    {        return super.get(id, this);    }    //    //    // Methods overriding ScriptableObject    //    //    public final Object getDefaultValue(Class hint)    {        return toString();    }    public void delete(String name)    {        throw new IllegalArgumentException("String: [" + name + "]");    }    /**     * XMLObject always compare with any value and equivalentValues     * never returns {@link Scriptable#NOT_FOUND} for them but rather     * calls equivalentXml(value) and wrap the result as Boolean.     */    protected final Object equivalentValues(Object value)    {        boolean result = equivalentXml(value);        return result ? Boolean.TRUE : Boolean.FALSE;    }    //    //    // Methods overriding XMLObject    //    //    public final XMLLib lib()    {        return lib;    }    /**     * Implementation of ECMAScript [[Has]]     */    public final boolean ecmaHas(Context cx, Object id)    {        if (cx == null) cx = Context.getCurrentContext();        XMLName xmlName = lib.toXMLNameOrIndex(cx, id);        if (xmlName == null) {            long index = ScriptRuntime.lastUint32Result(cx);            // XXX Fix this cast            return has((int)index, this);        }        return hasXMLProperty(xmlName);    }    /**     * Implementation of ECMAScript [[Get]]     */    public final Object ecmaGet(Context cx, Object id)    {        if (cx == null) cx = Context.getCurrentContext();        XMLName xmlName = lib.toXMLNameOrIndex(cx, id);        if (xmlName == null) {            long index = ScriptRuntime.lastUint32Result(cx);            // XXX Fix this cast            Object result = get((int)index, this);            if (result == Scriptable.NOT_FOUND) {                result = Undefined.instance;            }            return result;        }        return getXMLProperty(xmlName);    }    /**     * Implementation of ECMAScript [[Put]]     */    public final void ecmaPut(Context cx, Object id, Object value)    {        if (cx == null) cx = Context.getCurrentContext();        XMLName xmlName = lib.toXMLNameOrIndex(cx, id);        if (xmlName == null) {            long index = ScriptRuntime.lastUint32Result(cx);            // XXX Fix this cast            put((int)index, this, value);            return;        }        putXMLProperty(xmlName, value);    }    /**     * Implementation of ECMAScript [[Delete]].     */    public final boolean ecmaDelete(Context cx, Object id)    {        if (cx == null) cx = Context.getCurrentContext();        XMLName xmlName = lib.toXMLNameOrIndex(cx, id);        if (xmlName == null) {            long index = ScriptRuntime.lastUint32Result(cx);            // XXX Fix this            delete((int)index);            return true;        }        deleteXMLProperty(xmlName);        return true;    }    public Ref memberRef(Context cx, Object elem, int memberTypeFlags)    {        XMLName xmlName;        if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0) {            xmlName = lib.toAttributeName(cx, elem);        } else {            if ((memberTypeFlags & Node.DESCENDANTS_FLAG) == 0) {                // Code generation would use ecma(Get|Has|Delete|Set) for                // normal name idenrifiers so one ATTRIBUTE_FLAG                // or DESCENDANTS_FLAG has to be set                throw Kit.codeBug();            }            xmlName = lib.toXMLName(cx, elem);        }        if ((memberTypeFlags & Node.DESCENDANTS_FLAG) != 0) {            xmlName.setIsDescendants();        }        xmlName.initXMLObject(this);        return xmlName;    }    /**     * Generic reference to implement x::ns, x.@ns::y, x..@ns::y etc.     */    public Ref memberRef(Context cx, Object namespace, Object elem,                         int memberTypeFlags)    {        XMLName xmlName = lib.toQualifiedName(cx, namespace, elem);        if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0) {            if (!xmlName.isAttributeName()) {                xmlName.setAttributeName();            }        }        if ((memberTypeFlags & Node.DESCENDANTS_FLAG) != 0) {            xmlName.setIsDescendants();        }        xmlName.initXMLObject(this);        return xmlName;    }    public NativeWith enterWith(Scriptable scope)    {        return new XMLWithScope(lib, scope, this);    }    public NativeWith enterDotQuery(Scriptable scope)    {        XMLWithScope xws = new XMLWithScope(lib, scope, this);        xws.initAsDotQuery();        return xws;    }    public final Object addValues(Context cx, boolean thisIsLeft,                                     Object value)    {        if (value instanceof XMLObject) {            XMLObject v1, v2;            if (thisIsLeft) {                v1 = this;                v2 = (XMLObject)value;            } else {                v1 = (XMLObject)value;                v2 = this;            }            return lib.addXMLObjects(cx, v1, v2);        }        if (value == Undefined.instance) {            // both "xml + undefined" and "undefined + xml" gives String(xml)            return ScriptRuntime.toString(this);        }        return super.addValues(cx, thisIsLeft, value);    }    //    //    // IdScriptableObject machinery    //    //    final void exportAsJSClass(boolean sealed)    {        prototypeFlag = true;        exportAsJSClass(MAX_PROTOTYPE_ID, lib.globalScope(), sealed);    }// #string_id_map#    private final static int        Id_constructor             = 1,        Id_addNamespace            = 2,        Id_appendChild             = 3,        Id_attribute               = 4,        Id_attributes              = 5,        Id_child                   = 6,        Id_childIndex              = 7,        Id_children                = 8,        Id_comments                = 9,        Id_contains                = 10,        Id_copy                    = 11,        Id_descendants             = 12,        Id_inScopeNamespaces       = 13,        Id_insertChildAfter        = 14,        Id_insertChildBefore       = 15,        Id_hasOwnProperty          = 16,        Id_hasComplexContent       = 17,        Id_hasSimpleContent        = 18,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -