View Javadoc

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