📄 defaultelement.java
字号:
return new ContentListFacade(this, attributeList()); } public void setAttributes(List attributes) { this.attributes = attributes; if (attributes instanceof ContentListFacade) { this.attributes = ((ContentListFacade) attributes).getBackingList(); } } public Iterator attributeIterator() { if (attributes instanceof List) { List list = (List) attributes; return list.iterator(); } else if (attributes != null) { return createSingleIterator(attributes); } else { return EMPTY_ITERATOR; } } public Attribute attribute(int index) { if (attributes instanceof List) { List list = (List) attributes; return (Attribute) list.get(index); } else if (attributes != null && index == 0) { return (Attribute) attributes; } else { return null; } } public int attributeCount() { if (attributes instanceof List) { List list = (List) attributes; return list.size(); } else { return (attributes != null) ? 1 : 0; } } public Attribute attribute(String name) { if (attributes instanceof List) { List list = (List) attributes; int size = list.size(); for (int i = 0; i < size; i++) { Attribute attribute = (Attribute) list.get(i); if (name.equals(attribute.getName())) { return attribute; } } } else if (attributes != null) { Attribute attribute = (Attribute) attributes; if (name.equals(attribute.getName())) { return attribute; } } return null; } public Attribute attribute(QName qName) { if (attributes instanceof List) { List list = (List) attributes; int size = list.size(); for (int i = 0; i < size; i++) { Attribute attribute = (Attribute) list.get(i); if (qName.equals(attribute.getQName())) { return attribute; } } } else if (attributes != null) { Attribute attribute = (Attribute) attributes; if (qName.equals(attribute.getQName())) { return attribute; } } return null; } public Attribute attribute(String name, Namespace namespace) { return attribute(getNodeFactory().createQName(name, namespace)); } public void add(Attribute attribute) { if (attribute.getParent() != null) { String message = "The Attribute already has an existing parent \"" + attribute.getParent().getQualifiedName() + "\""; throw new IllegalAddException(this, attribute, message); } if (attribute.getValue() == null) { // try remove a previous attribute with the same // name since adding an attribute with a null value // is equivalent to removing it. Attribute oldAttribute = attribute(attribute.getQName()); if (oldAttribute != null) { remove(oldAttribute); } } else { if (attributes == null) { attributes = attribute; } else { attributeList().add(attribute); } childAdded(attribute); } } public boolean remove(Attribute attribute) { boolean answer = false; if (attributes instanceof List) { List list = (List) attributes; answer = list.remove(attribute); if (!answer) { // we may have a copy of the attribute Attribute copy = attribute(attribute.getQName()); if (copy != null) { list.remove(copy); answer = true; } } } else if (attributes != null) { if (attribute.equals(attributes)) { attributes = null; answer = true; } else { // we may have a copy of the attribute Attribute other = (Attribute) attributes; if (attribute.getQName().equals(other.getQName())) { attributes = null; answer = true; } } } if (answer) { childRemoved(attribute); } return answer; } // Implementation methods //------------------------------------------------------------------------- protected void addNewNode(Node node) { if (content == null) { content = node; } else { if (content instanceof List) { List list = (List) content; list.add(node); } else { List list = createContentList(); list.add(content); list.add(node); content = list; } } childAdded(node); } protected boolean removeNode(Node node) { boolean answer = false; if (content != null) { if (content == node) { content = null; answer = true; } else if (content instanceof List) { List list = (List) content; answer = list.remove(node); } } if (answer) { childRemoved(node); } return answer; } protected List contentList() { if (content instanceof List) { return (List) content; } else { List list = createContentList(); if (content != null) { list.add(content); } content = list; return list; } } protected List attributeList() { if (attributes instanceof List) { return (List) attributes; } else if (attributes != null) { List list = createAttributeList(); list.add(attributes); attributes = list; return list; } else { List list = createAttributeList(); attributes = list; return list; } } protected List attributeList(int size) { if (attributes instanceof List) { return (List) attributes; } else if (attributes != null) { List list = createAttributeList(size); list.add(attributes); attributes = list; return list; } else { List list = createAttributeList(size); attributes = list; return list; } } protected void setAttributeList(List attributes) { this.attributes = attributes; }}/* * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "DOM4J" must not be used to endorse or promote * products derived from this Software without prior written * permission of MetaStuff, Ltd. For written permission, * please contact dom4j-info@metastuff.com. * * 4. Products derived from this Software may not be called "DOM4J" * nor may "DOM4J" appear in their names without prior written * permission of MetaStuff, Ltd. DOM4J is a registered * trademark of MetaStuff, Ltd. * * 5. Due credit should be given to the DOM4J Project * (http://dom4j.org/). * * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. * * $Id: DefaultElement.java,v 1.1 2003/11/02 18:10:03 per_nyfelt Exp $ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -