View Javadoc

1   /*
2    * $Id: ProxyNodeAdapter.java 471756 2006-11-06 15:01:43Z husted $
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  package org.apache.struts2.views.xslt;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.w3c.dom.DOMException;
26  import org.w3c.dom.NamedNodeMap;
27  import org.w3c.dom.Node;
28  
29  /***
30   * ProxyNodeAdapter is a read-only delegating adapter for objects which already
31   * implement the Node interface.  All methods are proxied to the underlying
32   * Node except getParent(), getNextSibling() and getPreviousSibling(), which
33   * are implemented by the abstract adapter node to work with the parent adapter.
34   */
35  public abstract class ProxyNodeAdapter extends AbstractAdapterNode {
36  
37      private Log log = LogFactory.getLog(this.getClass());
38  
39      public ProxyNodeAdapter(AdapterFactory factory, AdapterNode parent, Node value) {
40          setContext(factory, parent, "document"/*propname unused*/, value);
41          log.debug("proxied node is: " + value);
42          log.debug("node class is: " + value.getClass());
43          log.debug("node type is: " + value.getNodeType());
44          log.debug("node name is: " + value.getNodeName());
45      }
46  
47      /***
48       * Get the proxied Node value
49       */
50      protected Node node() {
51          return (Node) getPropertyValue();
52      }
53  
54      /***
55       * Get and adapter to wrap the proxied node.
56       *
57       * @param node
58       */
59      protected Node wrap(Node node) {
60          return getAdapterFactory().proxyNode(this, node);
61      }
62  
63      protected NamedNodeMap wrap(NamedNodeMap nnm) {
64          return getAdapterFactory().proxyNamedNodeMap(this, nnm);
65      }
66      //protected NodeList wrap( NodeList nl ) { }
67  
68      //protected Node unwrap( Node child ) {
69      //  return ((ProxyNodeAdapter)child).node();
70      //}
71  
72      // Proxied Node methods
73  
74      public String getNodeName() {
75          log.trace("getNodeName");
76          return node().getNodeName();
77      }
78  
79      public String getNodeValue() throws DOMException {
80          log.trace("getNodeValue");
81          return node().getNodeValue();
82      }
83  
84      public short getNodeType() {
85          if (log.isTraceEnabled())
86              log.trace("getNodeType: " + getNodeName() + ": " + node().getNodeType());
87          return node().getNodeType();
88      }
89  
90      public NamedNodeMap getAttributes() {
91          NamedNodeMap nnm = wrap(node().getAttributes());
92          if (log.isTraceEnabled())
93              log.trace("getAttributes: " + nnm);
94          return nnm;
95      }
96  
97      public boolean hasChildNodes() {
98          log.trace("hasChildNodes");
99          return node().hasChildNodes();
100     }
101 
102     public boolean isSupported(String s, String s1) {
103         log.trace("isSupported");
104         // Is this ok?  What kind of features are they asking about?
105         return node().isSupported(s, s1);
106     }
107 
108     public String getNamespaceURI() {
109         log.trace("getNamespaceURI");
110         return node().getNamespaceURI();
111     }
112 
113     public String getPrefix() {
114         log.trace("getPrefix");
115         return node().getPrefix();
116     }
117 
118     public String getLocalName() {
119         log.trace("getLocalName");
120         return node().getLocalName();
121     }
122 
123     public boolean hasAttributes() {
124         log.trace("hasAttributes");
125         return node().hasAttributes();
126     }
127 
128     // End proxied Node methods
129 
130     public String toString() {
131         return "ProxyNode for: " + node();
132     }
133 }
134