View Javadoc

1   /*
2    * $Id: ProxyNamedNodeMap.java 440597 2006-09-06 03:34:39Z wsmoak $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.views.xslt;
19  
20  import org.w3c.dom.DOMException;
21  import org.w3c.dom.NamedNodeMap;
22  import org.w3c.dom.Node;
23  
24  /***
25   * A NamedNodeMap that wraps the Nodes returned in their proxies.
26   *
27   * Note: Since maps have no guaranteed order we don't need to worry about identity
28   * here as we do with "child" adapters.  In that case we need to preserve identity
29   * in order to support finding the next/previous siblings.
30   */
31  public class ProxyNamedNodeMap implements NamedNodeMap {
32  
33      private NamedNodeMap nodes;
34      private AdapterFactory adapterFactory;
35      private AdapterNode parent;
36  
37      public ProxyNamedNodeMap(AdapterFactory factory, AdapterNode parent, NamedNodeMap nodes) {
38          this.nodes = nodes;
39          this.adapterFactory = factory;
40          this.parent = parent;
41      }
42  
43      protected Node wrap(Node node) {
44          return adapterFactory.proxyNode(parent, node);
45      }
46  
47      public int getLength() {
48          return nodes.getLength();
49      }
50  
51      public Node item(int index) {
52          return wrap(nodes.item(index));
53      }
54  
55      public Node getNamedItem(String name) {
56          return wrap(nodes.getNamedItem(name));
57      }
58  
59      public Node removeNamedItem(String name) throws DOMException {
60          throw new UnsupportedOperationException();
61      }
62  
63      public Node setNamedItem(Node arg) throws DOMException {
64          throw new UnsupportedOperationException();
65      }
66  
67      public Node setNamedItemNS(Node arg) throws DOMException {
68          throw new UnsupportedOperationException();
69      }
70  
71      public Node getNamedItemNS(String namespaceURI, String localName) {
72          return wrap(nodes.getNamedItemNS(namespaceURI, localName));
73      }
74  
75      public Node removeNamedItemNS(String namespaceURI, String localName) throws DOMException {
76          throw new UnsupportedOperationException();
77      }
78  }