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

📄 xmllist.java

📁 javascript语言的解释器源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        if (_annos != null)        {            result = _annos.length();        }        return result;    }    /**     *     * @return     */    String localName()    {        if (length() == 1)        {            return name().localName();        }        else        {            throw ScriptRuntime.typeError("The localName method works only on lists containing one item");        }    }    /**     *     * @return     */    QName name()    {        if (length() == 1)        {            return getXmlFromAnnotation(0).name();        }        else        {            throw ScriptRuntime.typeError("The name method works only on lists containing one item");        }    }    /**     *     * @param prefix     * @return     */    Object namespace(String prefix)    {        if (length() == 1)        {            return getXmlFromAnnotation(0).namespace(prefix);        }        else        {            throw ScriptRuntime.typeError("The namespace method works only on lists containing one item");        }    }    /**     *     * @return     */    Object[] namespaceDeclarations()    {        if (length() == 1)        {            return getXmlFromAnnotation(0).namespaceDeclarations();        }        else        {            throw ScriptRuntime.typeError("The namespaceDeclarations method works only on lists containing one item");        }    }    /**     *     * @return     */    Object nodeKind()    {        if (length() == 1)        {            return getXmlFromAnnotation(0).nodeKind();        }        else        {            throw ScriptRuntime.typeError("The nodeKind method works only on lists containing one item");        }    }    /**     *     */    void normalize()    {        for (int i = 0; i < length(); i++)        {            getXmlFromAnnotation(i).normalize();        }    }    /**     * If list is empty, return undefined, if elements have different parents return undefined,     * If they all have the same parent, return that parent.     *     * @return     */    Object parent()    {        Object sameParent = Undefined.instance;        if ((length() == 0) && (targetObject != null) && (targetObject instanceof XML))        {            sameParent = targetObject;        }        else        {            for (int i = 0; i < length(); i++)            {                Object currParent = getXmlFromAnnotation(i).parent();                if (i == 0)                {                    // Set the first for the rest to compare to.                    sameParent = currParent;                }                else if (sameParent != currParent)                {                    sameParent = Undefined.instance;                    break;                }            }        }        // If everything in the list is the sameParent then return that as the parent.        return sameParent;    }    /**     *     * @param xml     * @return     */    XML prependChild(Object xml)    {        if (length() == 1)        {            return getXmlFromAnnotation(0).prependChild(xml);        }        else        {            throw ScriptRuntime.typeError("The prependChild method works only on lists containing one item");        }    }    /**     *     * @return     */    Object processingInstructions(XMLName xmlName)    {        XMLList result = new XMLList(lib);        for (int i = 0; i < length(); i++)        {            XML xml = getXmlFromAnnotation(i);            result.addToList(xml.processingInstructions(xmlName));        }        return result;    }    /**     *     * @param name     * @return     */    boolean propertyIsEnumerable(Object name)    {        long index;        if (name instanceof Integer) {            index = ((Integer)name).intValue();        } else if (name instanceof Number) {            double x = ((Number)name).doubleValue();            index = (long)x;            if ((double)index != x) {                return false;            }            if (index == 0 && 1.0 / x < 0) {                // Negative 0                return false;            }        } else {            String s = ScriptRuntime.toString(name);            index = ScriptRuntime.testUint32String(s);        }        return (0 <= index && index < length());    }    /**     *     * @param ns     */    XML removeNamespace(Namespace ns)    {        if(length() == 1)        {            return getXmlFromAnnotation(0).removeNamespace(ns);        }        else        {            throw ScriptRuntime.typeError("The removeNamespace method works only on lists containing one item");        }    }    XML replace(long index, Object xml)    {        if (length() == 1)        {            return getXmlFromAnnotation(0).replace(index, xml);        }        else        {            throw ScriptRuntime.typeError("The replace method works only on lists containing one item");        }    }    /**     *     * @param propertyName     * @param xml     * @return     */    XML replace(XMLName xmlName, Object xml)    {        if (length() == 1)        {            return getXmlFromAnnotation(0).replace(xmlName, xml);        }        else        {            throw ScriptRuntime.typeError("The replace method works only on lists containing one item");        }    }    /**     *     * @param xml     */    XML setChildren(Object xml)    {        if (length() == 1)        {            return getXmlFromAnnotation(0).setChildren(xml);        }        else        {            throw ScriptRuntime.typeError("The setChildren method works only on lists containing one item");        }    }    /**     *     * @param name     */    void setLocalName(String localName)    {        if (length() == 1)        {            getXmlFromAnnotation(0).setLocalName(localName);        }        else        {            throw ScriptRuntime.typeError("The setLocalName method works only on lists containing one item");        }    }    /**     *     * @param name     */    void setName(QName qname)    {        if (length() == 1)        {            getXmlFromAnnotation(0).setName(qname);        }        else        {            throw ScriptRuntime.typeError("The setName method works only on lists containing one item");        }    }    /**     *     * @param ns     */    void setNamespace(Namespace ns)    {        if (length() == 1)        {            getXmlFromAnnotation(0).setNamespace(ns);        }        else        {            throw ScriptRuntime.typeError("The setNamespace method works only on lists containing one item");        }    }    /**     *     * * @return     */    XMLList text()    {        XMLList result = new XMLList(lib);        for (int i = 0; i < length(); i++)        {            result.addToList(getXmlFromAnnotation(i).text());        }        return result;    }    /**     *     * @return     */    public String toString()    {        if (hasSimpleContent())        {            StringBuffer sb = new StringBuffer();            for(int i = 0; i < length(); i++)            {                XML next = getXmlFromAnnotation(i);                sb.append(next.toString());            }            return sb.toString();        }        else        {            return toXMLString(0);        }    }    String toSource(int indent)    {        // XXX indent is ignored        return "<>"+toXMLString(0)+"</>";    }    /**     *     * @return     */    String toXMLString(int indent)    {        StringBuffer sb = new StringBuffer();        for(int i = 0; i < length(); i++)        {            if (i > 0)            {                sb.append('\n');            }            sb.append(getXmlFromAnnotation(i).toXMLString(indent));        }        return sb.toString();    }    /**     *     * @return     */    Object valueOf()    {        return this;    }    //    // Other public Functions from XMLObject    //    /**     *     * @param target     * @return     */    boolean equivalentXml(Object target)    {        boolean result = false;        // Zero length list should equate to undefined        if (target instanceof Undefined && length() == 0)        {            result = true;        }        else if (length() == 1)        {            result = getXmlFromAnnotation(0).equivalentXml(target);        }        else if (target instanceof XMLList)        {            XMLList otherList = (XMLList) target;            if (otherList.length() == length())            {                result = true;                for (int i = 0; i < length(); i++)                {                    if (!getXmlFromAnnotation(i).equivalentXml(otherList.getXmlFromAnnotation(i)))                    {                        result = false;                        break;                    }                }            }        }        return result;    }    /**     *     * @param name     * @param start     * @return     */    private XMLList getPropertyList(XMLName name)    {        XMLList propertyList = new XMLList(lib);        javax.xml.namespace.QName qname = null;        if (!name.isDescendants() && !name.isAttributeName())        {            // Only set the targetProperty if this is a regular child get            // and not a descendant or attribute get            qname = new javax.xml.namespace.QName(name.uri(), name.localName());        }        propertyList.setTargets(this, qname);        for (int i = 0; i < length(); i++)        {            propertyList.addToList(                getXmlFromAnnotation(i).getPropertyList(name));        }        return propertyList;    }    private Object applyOrCall(boolean isApply,                               Context cx, Scriptable scope,                               Scriptable thisObj, Object[] args)    {        String methodName = isApply ? "apply" : "call";        if(!(thisObj instanceof XMLList) ||           ((XMLList)thisObj).targetProperty == null)            throw ScriptRuntime.typeError1("msg.isnt.function",                                           methodName);        return ScriptRuntime.applyOrCall(isApply, cx, scope, thisObj, args);    }    protected Object jsConstructor(Context cx, boolean inNewExpr,                                   Object[] args)    {        if (args.length == 0) {            return new XMLList(lib);        } else {            Object arg0 = args[0];            if (!inNewExpr && arg0 instanceof XMLList) {                // XMLList(XMLList) returns the same object.                return arg0;            }            return new XMLList(lib, arg0);        }    }    org.apache.xmlbeans.XmlObject getXmlObject()    {        if (length() == 1) {            return getXmlFromAnnotation(0).getXmlObject();        } else {            throw ScriptRuntime.typeError("getXmlObject method works only on lists containing one item");        }    }    /**     * See ECMA 357, 11_2_2_1, Semantics, 3_e.     */    public Scriptable getExtraMethodSource(Context cx)    {        if (length() == 1) {            return getXmlFromAnnotation(0);        }        return null;    }    public Object call(Context cx, Scriptable scope, Scriptable thisObj,                       Object[] args)    {        // This XMLList is being called as a Function.        // Let's find the real Function object.        if(targetProperty == null)            throw ScriptRuntime.notFunctionError(this);        String methodName = targetProperty.getLocalPart();        boolean isApply = methodName.equals("apply");        if(isApply || methodName.equals("call"))            return applyOrCall(isApply, cx, scope, thisObj, args);        Callable method = ScriptRuntime.getElemFunctionAndThis(                              this, methodName, cx);        // Call lastStoredScriptable to clear stored thisObj        // but ignore the result as the method should use the supplied        // thisObj, not one from redirected call        ScriptRuntime.lastStoredScriptable(cx);        return method.call(cx, scope, thisObj, args);    }    public Scriptable construct(Context cx, Scriptable scope, Object[] args)    {        throw ScriptRuntime.typeError1("msg.not.ctor", "XMLList");    }}

⌨️ 快捷键说明

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