📄 xmlobjectimpl.java
字号:
/* -*- 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 * David P. Caldwell <inonit@inonit.com> * * 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.xmlimpl;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(); private XMLLibImpl lib; private boolean prototypeFlag; protected XMLObjectImpl(XMLLibImpl lib, Scriptable scope, XMLObject prototype) { initialize(lib, scope, prototype); } final void initialize(XMLLibImpl lib, Scriptable scope, XMLObject prototype) { setParentScope(scope); setPrototype(prototype); prototypeFlag = (prototype == null); this.lib = lib; } final boolean isPrototype() { return prototypeFlag; } XMLLibImpl getLib() { return lib; } final XML newXML(XmlNode node) { return lib.newXML(node); } XML xmlFromNode(XmlNode node) { if (node.getXml() == null) { node.setXml( newXML(node) ); } return node.getXml(); } final XMLList newXMLList() { return lib.newXMLList(); } final XMLList newXMLListFrom(Object o) { return lib.newXMLListFrom(o); } final XmlProcessor getProcessor() { return lib.getProcessor(); } final QName newQName(String uri, String localName, String prefix) { return lib.newQName(uri, localName, prefix); } final QName newQName(XmlNode.QName name) { return lib.newQName(name); } final Namespace createNamespace(XmlNode.Namespace declaration) { if (declaration == null) return null; return lib.createNamespaces( new XmlNode.Namespace[] { declaration } )[0]; } final Namespace[] createNamespaces(XmlNode.Namespace[] declarations) { return lib.createNamespaces(declarations); } // // Scriptable // public final Object get(String name, Scriptable start) { return super.get(name, start); } public final boolean has(String name, Scriptable start) { return super.has(name, start); } public final void put(String name, Scriptable start, Object value) { super.put(name, start, value); } public final void delete(String name) { // TODO I am not sure about this, but this is how I found it. DPC throw new IllegalArgumentException("String: [" + name + "]"); } public final Scriptable getPrototype() { return super.getPrototype(); } public final void setPrototype(Scriptable prototype) { super.setPrototype(prototype); } public final Scriptable getParentScope() { return super.getParentScope(); } public final void setParentScope(Scriptable parent) { super.setParentScope(parent); } public final Object getDefaultValue(Class hint) { return this.toString(); } public final boolean hasInstance(Scriptable scriptable) { return super.hasInstance(scriptable); } /** * 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); abstract void addMatches(XMLList rv, XMLName name); private XMLList getMatches(XMLName name) { XMLList rv = newXMLList(); addMatches(rv, name); return rv; } abstract XML getXML(); // Methods from section 12.4.4 in the spec abstract XMLList child(int index); abstract XMLList child(XMLName xmlName); abstract XMLList children(); abstract XMLList comments(); abstract boolean contains(Object xml); abstract XMLObjectImpl copy(); abstract XMLList elements(XMLName xmlName); abstract boolean hasOwnProperty(XMLName xmlName); abstract boolean hasComplexContent(); abstract boolean hasSimpleContent(); abstract int length(); abstract void normalize(); abstract Object parent(); abstract XMLList processingInstructions(XMLName xmlName); abstract boolean propertyIsEnumerable(Object member); abstract XMLList text(); public abstract String toString(); abstract String toXMLString(); abstract Object valueOf(); protected abstract Object jsConstructor(Context cx, boolean inNewExpr, Object[] args); final Object getMethod(String id) { return super.get(id, this); } // // // Methods overriding ScriptableObject // // /** * 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 // // /** * 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]] */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -