1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class NodeList<E, F> extends TranslatedList<E, F> {
48  
49      public NodeList(List<E> newList, List<F> oldList) {
50          super(newList, oldList);
51      }
52  
53      protected TranslatedList<E, F> newInstance(
54          List<E> newList, List<F> oldList) {
55  
56          return new NodeList<E, F>(newList, oldList);
57      }
58  
59      protected F toOldObject(E o) {
60          if (o instanceof Attribute) {
61              AttributeImpl attributeImpl = (AttributeImpl)o;
62  
63              return (F)attributeImpl.getWrappedAttribute();
64          }
65          else if (o instanceof CDATA) {
66              CDATAImpl cdataImpl = (CDATAImpl)o;
67  
68              return (F)cdataImpl.getWrappedCDATA();
69          }
70          else if (o instanceof Comment) {
71              CommentImpl commentImpl = (CommentImpl)o;
72  
73              return (F)commentImpl.getWrappedComment();
74          }
75          else if (o instanceof Document) {
76              DocumentImpl documentImpl = (DocumentImpl)o;
77  
78              return (F)documentImpl.getWrappedDocument();
79          }
80          else if (o instanceof Element) {
81              ElementImpl elementImpl = (ElementImpl)o;
82  
83              return (F)elementImpl.getWrappedElement();
84          }
85          else if (o instanceof Entity) {
86              EntityImpl entityImpl = (EntityImpl)o;
87  
88              return (F)entityImpl.getWrappedEntity();
89          }
90          else if (o instanceof Namespace) {
91              NamespaceImpl namespaceImpl = (NamespaceImpl)o;
92  
93              return (F)namespaceImpl.getWrappedNamespace();
94          }
95          else if (o instanceof ProcessingInstruction) {
96              ProcessingInstructionImpl processingInstructionImpl =
97                  (ProcessingInstructionImpl)o;
98  
99              return
100                 (F)processingInstructionImpl.getWrappedProcessingInstruction();
101         }
102         else if (o instanceof QName) {
103             QNameImpl qNameImpl = (QNameImpl)o;
104 
105             return (F)qNameImpl.getWrappedQName();
106         }
107         else if (o instanceof Text) {
108             TextImpl textImpl = (TextImpl)o;
109 
110             return (F)textImpl.getWrappedText();
111         }
112         else if (o instanceof XPath) {
113             XPathImpl xPathImpl = (XPathImpl)o;
114 
115             return (F)xPathImpl.getWrappedXPath();
116         }
117         else if (o instanceof Branch) {
118             BranchImpl branchImpl = (BranchImpl)o;
119 
120             return (F)branchImpl.getWrappedBranch();
121         }
122         else if (o instanceof Node) {
123             NodeImpl nodeImpl = (NodeImpl)o;
124 
125             return (F)nodeImpl.getWrappedNode();
126         }
127 
128         throw new IllegalArgumentException(o.getClass().getName());
129     }
130 
131 }