1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.xml;
24  
25  import com.liferay.portal.kernel.util.TranslatedList;
26  import com.liferay.portal.kernel.xml.Attribute;
27  import com.liferay.portal.kernel.xml.Branch;
28  import com.liferay.portal.kernel.xml.CDATA;
29  import com.liferay.portal.kernel.xml.Comment;
30  import com.liferay.portal.kernel.xml.Document;
31  import com.liferay.portal.kernel.xml.Element;
32  import com.liferay.portal.kernel.xml.Entity;
33  import com.liferay.portal.kernel.xml.Namespace;
34  import com.liferay.portal.kernel.xml.Node;
35  import com.liferay.portal.kernel.xml.ProcessingInstruction;
36  import com.liferay.portal.kernel.xml.QName;
37  import com.liferay.portal.kernel.xml.Text;
38  import com.liferay.portal.kernel.xml.XPath;
39  
40  import java.util.List;
41  
42  /**
43   * <a href="NodeList.java.html"><b><i>View Source</i></b></a>
44   *
45   * @author Brian Wing Shun Chan
46   *
47   */
48  public class NodeList<E, F> extends TranslatedList<E, F> {
49  
50      public NodeList(List<E> newList, List<F> oldList) {
51          super(newList, oldList);
52      }
53  
54      protected TranslatedList<E, F> newInstance(
55          List<E> newList, List<F> oldList) {
56  
57          return new NodeList<E, F>(newList, oldList);
58      }
59  
60      protected F toOldObject(E o) {
61          if (o instanceof Attribute) {
62              AttributeImpl attributeImpl = (AttributeImpl)o;
63  
64              return (F)attributeImpl.getWrappedAttribute();
65          }
66          else if (o instanceof CDATA) {
67              CDATAImpl cdataImpl = (CDATAImpl)o;
68  
69              return (F)cdataImpl.getWrappedCDATA();
70          }
71          else if (o instanceof Comment) {
72              CommentImpl commentImpl = (CommentImpl)o;
73  
74              return (F)commentImpl.getWrappedComment();
75          }
76          else if (o instanceof Document) {
77              DocumentImpl documentImpl = (DocumentImpl)o;
78  
79              return (F)documentImpl.getWrappedDocument();
80          }
81          else if (o instanceof Element) {
82              ElementImpl elementImpl = (ElementImpl)o;
83  
84              return (F)elementImpl.getWrappedElement();
85          }
86          else if (o instanceof Entity) {
87              EntityImpl entityImpl = (EntityImpl)o;
88  
89              return (F)entityImpl.getWrappedEntity();
90          }
91          else if (o instanceof Namespace) {
92              NamespaceImpl namespaceImpl = (NamespaceImpl)o;
93  
94              return (F)namespaceImpl.getWrappedNamespace();
95          }
96          else if (o instanceof ProcessingInstruction) {
97              ProcessingInstructionImpl processingInstructionImpl =
98                  (ProcessingInstructionImpl)o;
99  
100             return
101                 (F)processingInstructionImpl.getWrappedProcessingInstruction();
102         }
103         else if (o instanceof QName) {
104             QNameImpl qNameImpl = (QNameImpl)o;
105 
106             return (F)qNameImpl.getWrappedQName();
107         }
108         else if (o instanceof Text) {
109             TextImpl textImpl = (TextImpl)o;
110 
111             return (F)textImpl.getWrappedText();
112         }
113         else if (o instanceof XPath) {
114             XPathImpl xPathImpl = (XPathImpl)o;
115 
116             return (F)xPathImpl.getWrappedXPath();
117         }
118         else if (o instanceof Branch) {
119             BranchImpl branchImpl = (BranchImpl)o;
120 
121             return (F)branchImpl.getWrappedBranch();
122         }
123         else if (o instanceof Node) {
124             NodeImpl nodeImpl = (NodeImpl)o;
125 
126             return (F)nodeImpl.getWrappedNode();
127         }
128 
129         throw new IllegalArgumentException(o.getClass().getName());
130     }
131 
132 }