001: /*
002: * Copyright (c) 2002-2006 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.xslt;
006:
007: import org.apache.commons.logging.Log;
008: import org.apache.commons.logging.LogFactory;
009: import org.w3c.dom.*;
010:
011: /**
012: * ProxyNodeAdapter is a read-only delegating adapter for objects which already
013: * implement the Node interface. All methods are proxied to the underlying
014: * Node except getParent(), getNextSibling() and getPreviousSibling(), which
015: * are implemented by the abstract adapter node to work with the parent adapter.
016: *
017: * @author Pat Niemeyer (pat@pat.net)
018: */
019: public abstract class ProxyNodeAdapter extends AbstractAdapterNode {
020: private Log log = LogFactory.getLog(this .getClass());
021:
022: public ProxyNodeAdapter(AdapterFactory factory, AdapterNode parent,
023: Node value) {
024: setContext(factory, parent, "document"/*propname unused*/,
025: value);
026: log.debug("proxied node is: " + value);
027: log.debug("node class is: " + value.getClass());
028: log.debug("node type is: " + value.getNodeType());
029: log.debug("node name is: " + value.getNodeName());
030: }
031:
032: /**
033: * Get the proxied Node value
034: */
035: protected Node node() {
036: return (Node) getPropertyValue();
037: }
038:
039: /**
040: * Get and adapter to wrap the proxied node.
041: *
042: * @param node
043: */
044: protected Node wrap(Node node) {
045: return getAdapterFactory().proxyNode(this , node);
046: }
047:
048: protected NamedNodeMap wrap(NamedNodeMap nnm) {
049: return getAdapterFactory().proxyNamedNodeMap(this , nnm);
050: }
051:
052: //protected NodeList wrap( NodeList nl ) { }
053:
054: //protected Node unwrap( Node child ) {
055: // return ((ProxyNodeAdapter)child).node();
056: //}
057:
058: // Proxied Node methods
059:
060: public String getNodeName() {
061: log.trace("getNodeName");
062: return node().getNodeName();
063: }
064:
065: public String getNodeValue() throws DOMException {
066: log.trace("getNodeValue");
067: return node().getNodeValue();
068: }
069:
070: public short getNodeType() {
071: if (log.isTraceEnabled())
072: log.trace("getNodeType: " + getNodeName() + ": "
073: + node().getNodeType());
074: return node().getNodeType();
075: }
076:
077: public NamedNodeMap getAttributes() {
078: NamedNodeMap nnm = wrap(node().getAttributes());
079: if (log.isTraceEnabled())
080: log.trace("getAttributes: " + nnm);
081: return nnm;
082: }
083:
084: public boolean hasChildNodes() {
085: log.trace("hasChildNodes");
086: return node().hasChildNodes();
087: }
088:
089: public boolean isSupported(String s, String s1) {
090: log.trace("isSupported");
091: // Is this ok? What kind of features are they asking about?
092: return node().isSupported(s, s1);
093: }
094:
095: public String getNamespaceURI() {
096: log.trace("getNamespaceURI");
097: return node().getNamespaceURI();
098: }
099:
100: public String getPrefix() {
101: log.trace("getPrefix");
102: return node().getPrefix();
103: }
104:
105: public String getLocalName() {
106: log.trace("getLocalName");
107: return node().getLocalName();
108: }
109:
110: public boolean hasAttributes() {
111: log.trace("hasAttributes");
112: return node().hasAttributes();
113: }
114:
115: // End proxied Node methods
116:
117: public String toString() {
118: return "ProxyNode for: " + node();
119: }
120: }
|