View Javadoc

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