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