001: /*
002: * Copyright (c) 1998-2003 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.servlet.jsp.tagext;
030:
031: import javax.servlet.jsp.JspContext;
032: import javax.servlet.jsp.JspException;
033: import java.io.IOException;
034:
035: /**
036: * Support for SimpleTag.
037: */
038: public class SimpleTagSupport implements SimpleTag {
039: private JspTag _parent;
040: private JspFragment _jspBody;
041: private JspContext _jspContext;
042:
043: /**
044: * Create a new SimpleTagSupport.
045: */
046: public SimpleTagSupport() {
047: }
048:
049: /**
050: * returns the parent
051: */
052: public JspTag getParent() {
053: return _parent;
054: }
055:
056: /**
057: * Sets the parent
058: */
059: public void setParent(JspTag parent) {
060: _parent = parent;
061: }
062:
063: /**
064: * returns the body fragment.
065: */
066: protected JspFragment getJspBody() {
067: return _jspBody;
068: }
069:
070: /**
071: * Sets the body fragment.
072: */
073: public void setJspBody(JspFragment body) {
074: _jspBody = body;
075: }
076:
077: /**
078: * returns the context
079: */
080: protected JspContext getJspContext() {
081: return _jspContext;
082: }
083:
084: /**
085: * Sets the context
086: */
087: public void setJspContext(JspContext context) {
088: _jspContext = context;
089: }
090:
091: /**
092: * Does nothing.
093: */
094: public void doTag() throws IOException, JspException {
095: }
096:
097: /**
098: * Finds an ancestor of a tag matching the class. The search is strict,
099: * i.e. only parents will be searched, not the tag itself.
100: *
101: * @param tag child tag to start searching.
102: * @param cl the class that the tag should implement.
103: *
104: * @return the matching tag or null.
105: */
106: public static final JspTag findAncestorWithClass(JspTag tag,
107: Class cl) {
108: if (tag == null || cl == null)
109: return null;
110:
111: while (tag != null) {
112: if (tag instanceof Tag)
113: tag = ((Tag) tag).getParent();
114: else if (tag instanceof SimpleTag)
115: tag = ((SimpleTag) tag).getParent();
116:
117: if (tag == null)
118: return null;
119: else if (tag instanceof TagAdapter) {
120: TagAdapter adapter = (TagAdapter) tag;
121:
122: if (cl
123: .isAssignableFrom(adapter.getAdaptee()
124: .getClass()))
125: return adapter.getAdaptee();
126: } else if (cl.isAssignableFrom(tag.getClass()))
127: return tag;
128: }
129:
130: return null;
131: }
132: }
|