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: * $Id: TagExtraInfo.java,v 1.2 2004/09/29 00:12:48 cvs Exp $
029: */
030:
031: package javax.servlet.jsp.tagext;
032:
033: /**
034: * Extra tag information for a custom tag. It performs a similar function
035: * to BeanInfo classes, but for tag libraries. The TagExtraInfo class will
036: * be called at JSP compile time to:
037: * <ol>
038: * <li>instantiate and initialize runtime variables
039: * <li>validate tags
040: * </ol>
041: *
042: * <p/>The TagExtraInfo class is specified in the TLD
043: * using the teiclass attribute:
044: *
045: * <code><pre>
046: * <tag>
047: * <name>foo</name>
048: * <tagclass>com.caucho.tags.FooTag</tagclass>
049: * <teiclass>com.caucho.tags.FooTagInfo</teiclass>
050: * </tag>
051: * </pre></code>
052: */
053: public abstract class TagExtraInfo {
054: private TagInfo _tagInfo;
055:
056: /**
057: * Implementing classes must implement a zero-arg constructor.
058: */
059: public TagExtraInfo() {
060: }
061:
062: /**
063: * Returns information needed to instantiate runtime variables.
064: *
065: * <p>The default implementation returns null.
066: *
067: * <p>For example, if the tag initializes a nested integer named by
068: * the foo attribute, getVariableInfo might return the following:
069: * <code><pre>
070: * public VariableInfo []getVariableInfo(TagData data)
071: * {
072: * VariableInfo []info = new VariableInfo[1];
073: * String foo = data.getAttribute("foo");
074: * info[0] = new VariableInfo(foo, "int", true, VariableInfo.NESTED);
075: * return info;
076: * }
077: * </pre></code>
078: *
079: * @param data The tag's static attributes and values.
080: */
081: public VariableInfo[] getVariableInfo(TagData data) {
082: return null;
083: }
084:
085: /**
086: * Validates the tag, so errors can be caught at compile-time instead of
087: * waiting for runtime.
088: *
089: * <p>The default implementation returns true.
090: */
091: public boolean isValid(TagData data) {
092: return true;
093: }
094:
095: /**
096: * Sets the TLD tag info for this tag.
097: */
098: public final void setTagInfo(TagInfo tagInfo) {
099: _tagInfo = tagInfo;
100: }
101:
102: /**
103: * Gets the TLD tag info for this tag.
104: */
105: public final TagInfo getTagInfo() {
106: return _tagInfo;
107: }
108:
109: /**
110: * Validates the tag.
111: */
112: public ValidationMessage[] validate(TagData data) {
113: if (isValid(data))
114: return null;
115: else {
116: ValidationMessage msg;
117: String prefix = getTagInfo().getTagLibrary().getShortName();
118: String name = getTagInfo().getTagName();
119:
120: if (prefix != null)
121: name = prefix + ':' + name;
122:
123: msg = new ValidationMessage(null, "tag <" + name
124: + "> was not valid according to validator `"
125: + getClass().getName() + "'");
126:
127: return new ValidationMessage[] { msg };
128: }
129: }
130: }
|