001: /*
002: * $Id: ProxyNodeAdapter.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.xslt;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.w3c.dom.DOMException;
026: import org.w3c.dom.NamedNodeMap;
027: import org.w3c.dom.Node;
028:
029: /**
030: * ProxyNodeAdapter is a read-only delegating adapter for objects which already
031: * implement the Node interface. All methods are proxied to the underlying
032: * Node except getParent(), getNextSibling() and getPreviousSibling(), which
033: * are implemented by the abstract adapter node to work with the parent adapter.
034: */
035: public abstract class ProxyNodeAdapter extends AbstractAdapterNode {
036:
037: private Log log = LogFactory.getLog(this .getClass());
038:
039: public ProxyNodeAdapter(AdapterFactory factory, AdapterNode parent,
040: Node value) {
041: setContext(factory, parent, "document"/*propname unused*/,
042: value);
043: log.debug("proxied node is: " + value);
044: log.debug("node class is: " + value.getClass());
045: log.debug("node type is: " + value.getNodeType());
046: log.debug("node name is: " + value.getNodeName());
047: }
048:
049: /**
050: * Get the proxied Node value
051: */
052: protected Node node() {
053: return (Node) getPropertyValue();
054: }
055:
056: /**
057: * Get and adapter to wrap the proxied node.
058: *
059: * @param node
060: */
061: protected Node wrap(Node node) {
062: return getAdapterFactory().proxyNode(this , node);
063: }
064:
065: protected NamedNodeMap wrap(NamedNodeMap nnm) {
066: return getAdapterFactory().proxyNamedNodeMap(this , nnm);
067: }
068:
069: //protected NodeList wrap( NodeList nl ) { }
070:
071: //protected Node unwrap( Node child ) {
072: // return ((ProxyNodeAdapter)child).node();
073: //}
074:
075: // Proxied Node methods
076:
077: public String getNodeName() {
078: log.trace("getNodeName");
079: return node().getNodeName();
080: }
081:
082: public String getNodeValue() throws DOMException {
083: log.trace("getNodeValue");
084: return node().getNodeValue();
085: }
086:
087: public short getNodeType() {
088: if (log.isTraceEnabled())
089: log.trace("getNodeType: " + getNodeName() + ": "
090: + node().getNodeType());
091: return node().getNodeType();
092: }
093:
094: public NamedNodeMap getAttributes() {
095: NamedNodeMap nnm = wrap(node().getAttributes());
096: if (log.isTraceEnabled())
097: log.trace("getAttributes: " + nnm);
098: return nnm;
099: }
100:
101: public boolean hasChildNodes() {
102: log.trace("hasChildNodes");
103: return node().hasChildNodes();
104: }
105:
106: public boolean isSupported(String s, String s1) {
107: log.trace("isSupported");
108: // Is this ok? What kind of features are they asking about?
109: return node().isSupported(s, s1);
110: }
111:
112: public String getNamespaceURI() {
113: log.trace("getNamespaceURI");
114: return node().getNamespaceURI();
115: }
116:
117: public String getPrefix() {
118: log.trace("getPrefix");
119: return node().getPrefix();
120: }
121:
122: public String getLocalName() {
123: log.trace("getLocalName");
124: return node().getLocalName();
125: }
126:
127: public boolean hasAttributes() {
128: log.trace("hasAttributes");
129: return node().hasAttributes();
130: }
131:
132: // End proxied Node methods
133:
134: public String toString() {
135: return "ProxyNode for: " + node();
136: }
137: }
|