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 version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.faces.component;
030:
031: import java.util.*;
032:
033: import javax.el.*;
034: import javax.faces.context.*;
035:
036: public class UIParameter extends UIComponentBase {
037: public static final String COMPONENT_FAMILY = "javax.faces.Parameter";
038: public static final String COMPONENT_TYPE = "javax.faces.Parameter";
039:
040: private String _name;
041: private ValueExpression _nameExpr;
042:
043: private Object _value;
044: private ValueExpression _valueExpr;
045:
046: public UIParameter() {
047: setRendererType(null);
048: }
049:
050: /**
051: * Returns the component family, used to select the renderer.
052: */
053: public String getFamily() {
054: return COMPONENT_FAMILY;
055: }
056:
057: //
058: // properties
059: //
060:
061: public String getName() {
062: if (_name != null)
063: return _name;
064: else if (_nameExpr != null)
065: return Util.evalString(_nameExpr, getFacesContext());
066: else
067: return null;
068: }
069:
070: public void setName(String value) {
071: _name = value;
072: }
073:
074: public Object getValue() {
075: if (_value != null)
076: return _value;
077: else if (_valueExpr != null)
078: return Util.eval(_valueExpr, getFacesContext());
079: else
080: return null;
081: }
082:
083: public void setValue(Object value) {
084: _value = value;
085: }
086:
087: /**
088: * Returns the value expression with the given name.
089: */
090: @Override
091: public ValueExpression getValueExpression(String name) {
092: if ("name".equals(name))
093: return _nameExpr;
094: else if ("value".equals(name))
095: return _valueExpr;
096: else
097: return super .getValueExpression(name);
098: }
099:
100: /**
101: * Sets the value expression with the given name.
102: */
103: @Override
104: public void setValueExpression(String name, ValueExpression expr) {
105: if ("name".equals(name)) {
106: if (expr != null && expr.isLiteralText()) {
107: _name = String.valueOf(expr.getValue(null));
108: return;
109: } else
110: _nameExpr = expr;
111: } else if ("value".equals(name)) {
112: if (expr != null && expr.isLiteralText()) {
113: _value = String.valueOf(expr.getValue(null));
114: return;
115: } else
116: _valueExpr = expr;
117: }
118:
119: super .setValueExpression(name, expr);
120: }
121:
122: //
123: // state
124: //
125:
126: public Object saveState(FacesContext context) {
127: return new Object[] { super .saveState(context),
128:
129: _name, _value, };
130: }
131:
132: public void restoreState(FacesContext context, Object value) {
133: Object[] state = (Object[]) value;
134:
135: super .restoreState(context, state[0]);
136:
137: _name = (String) state[1];
138: _value = (String) state[2];
139: }
140: }
|