001: /*
002: * Copyright (c) 1998-2008 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: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.config.types;
031:
032: import com.caucho.config.Config;
033: import com.caucho.util.L10N;
034:
035: import javax.servlet.jsp.el.ELException;
036: import java.util.HashMap;
037:
038: /**
039: * Configuration for the init-param pattern.
040: */
041: public class InitParam {
042: private static L10N L = new L10N(InitParam.class);
043:
044: private HashMap<String, String> _parameters = new HashMap<String, String>();
045:
046: private boolean _allowEL = true;
047:
048: private String _paramName;
049: private String _paramValue;
050:
051: private String _description;
052:
053: public InitParam() {
054: }
055:
056: public InitParam(String name, String value) {
057: _parameters.put(name, value);
058: }
059:
060: /**
061: * Sets true if EL is allowed.
062: */
063: public void setAllowEL(boolean allowEL) {
064: _allowEL = allowEL;
065: }
066:
067: /**
068: * Sets the param-name.
069: */
070: public void setParamName(String paramName) {
071: _paramName = paramName;
072: }
073:
074: /**
075: * Sets the param-value.
076: */
077: public void setParamValue(RawString paramValue) throws ELException {
078: String value = paramValue.getValue().trim();
079:
080: if (_allowEL)
081: value = Config.evalString(value);
082:
083: _paramValue = value;
084: }
085:
086: /**
087: * Sets the description
088: */
089: public void setDescription(String description) {
090: _description = description;
091: }
092:
093: /**
094: * Sets a misc parameter.
095: */
096: public void setProperty(String name, RawString rawValue)
097: throws ELException {
098: String value = rawValue.getValue().trim();
099:
100: if (_allowEL)
101: value = Config.evalString(value);
102:
103: _parameters.put(name, value);
104: }
105:
106: /**
107: * Returns the parameters.
108: */
109: public HashMap<String, String> getParameters() {
110: if (_paramName != null)
111: _parameters.put(_paramName, _paramValue);
112:
113: return _parameters;
114: }
115:
116: public String toString() {
117: return "InitParam" + getParameters();
118: }
119: }
|