001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019: package de.schlund.pfixcore.util;
020:
021: import org.apache.tools.ant.BuildException;
022:
023: /**
024: * @author adam
025: *
026: * Class used to store XSL parameters specified as nested
027: * <code><param></code>-Elements to the Xslt-Tasks.
028: */
029: public class XsltParam {
030:
031: /** The parameter name */
032: private String name;
033:
034: /** The parameter's XSL expression */
035: private String expression;
036:
037: public XsltParam() {
038: this (null, null);
039: }
040:
041: public XsltParam(String name, String expression) {
042: setName(name);
043: setExpression(expression);
044: }
045:
046: /**
047: * Set the parameter name.
048: *
049: * @param name the name of the parameter.
050: */
051: public void setName(String name) {
052: this .name = name;
053: }
054:
055: /**
056: * The XSL expression for the parameter value
057: *
058: * @param expression the XSL expression representing the
059: * parameter's value.
060: */
061: public void setExpression(String expression) {
062: this .expression = expression;
063: }
064:
065: /**
066: * Get the parameter name
067: *
068: * @return the parameter name
069: * @exception BuildException if the name is not set.
070: */
071: public String getName() throws BuildException {
072: if (name == null) {
073: throw new BuildException("Name attribute is missing.");
074: }
075: return name;
076: }
077:
078: /**
079: * Get the parameter expression
080: *
081: * @return the parameter expression
082: * @exception BuildException if the expression is not set.
083: */
084: public String getExpression() throws BuildException {
085: if (expression == null) {
086: throw new BuildException("Expression attribute is missing.");
087: }
088: return expression;
089: }
090:
091: public boolean equals(XsltParam that) {
092: if (that == null) {
093: return false;
094: }
095: if (this == that) {
096: return true;
097: }
098: if (name == null) {
099: if (that.name != null) {
100: return false;
101: }
102: } else {
103: if (name.equals(that.name) == false) {
104: return false;
105: }
106: }
107: if (expression == null) {
108: if (that.expression != null) {
109: return false;
110: }
111: } else {
112: if (expression.equals(that.expression) == false) {
113: return false;
114: }
115: }
116: return true;
117: }
118:
119: public String toString() {
120: return shortClassname(getClass().getName()) + "[name=" + name
121: + "; expression=" + expression + "]";
122: }
123:
124: //
125: // Helper methods
126: //
127:
128: /**
129: * @return classname without package prefix
130: */
131: public static String shortClassname(String classname) {
132: try {
133: int idx = classname.lastIndexOf('.');
134: if (idx >= 0) {
135: classname = classname.substring(idx + 1, classname
136: .length());
137: }
138: } catch (IndexOutOfBoundsException e) {
139: // This should never happen
140: e.printStackTrace();
141: }
142: return classname;
143: }
144:
145: }
|