001: /*
002: * Copyright (C) 2004 TiongHiang Lee
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library 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 GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * Email: thlee@onemindsoft.org
019: */
020:
021: package org.onemind.swingweb.session;
022:
023: import org.onemind.commons.java.lang.ref.ValueRef;
024:
025: /**
026: * Represent a variable that will response to url parameter
027: * (In non-swingweb mode, this just act as a normal variable value holder)
028: * @author TiongHiang Lee (thlee@onemindsoft.org)
029: */
030: public class URLLocal implements Comparable, ValueRef {
031:
032: /** the name **/
033: private final String _name;
034:
035: /** the default value **/
036: private final String _defValue;
037:
038: /** the order used when generate url. Higher number will be further front in url. Default order = 0 **/
039: private final int _order;
040:
041: /** whether the value will always show in url **/
042: private final boolean _alwaysShow;
043:
044: /** the value **/
045: private final SessionLocal _value = new SessionLocal();
046:
047: public URLLocal(String name) {
048: this (name, null, 0, false);
049: }
050:
051: public URLLocal(String name, String defValue) {
052: this (name, defValue, 0, false);
053: }
054:
055: public URLLocal(String name, String defValue, boolean alwaysShow) {
056: this (name, defValue, 0, alwaysShow);
057: }
058:
059: public URLLocal(String name, String defValue, int order) {
060: this (name, defValue, order, false);
061: }
062:
063: public URLLocal(String name, String defValue, int order,
064: boolean alwaysShow) {
065: _name = name;
066: _defValue = defValue;
067: _order = order;
068: _alwaysShow = alwaysShow;
069: }
070:
071: /**
072: * Set the value object
073: * @param obj
074: */
075: public final void setValue(Object value) {
076: if (value != null && !(value instanceof String)) {
077: throw new IllegalArgumentException(
078: "Value for URLLocal must be string type");
079: }
080: _value.setValue(value);
081: }
082:
083: /**
084: * Get the actual set value (not returning the default)
085: * @param obj
086: */
087: public final String getSetValue() {
088: return (String) _value.getValue();
089: }
090:
091: /**
092: * Get the value object
093: * @return the value object
094: */
095: public final Object getValue() {
096: String value = (String) _value.getValue();
097: if (value == null) {
098: return _defValue;
099: } else {
100: return value;
101: }
102: }
103:
104: /**
105: * Get the name
106: * @return the name
107: */
108: public final String getName() {
109: return _name;
110: }
111:
112: /**
113: * Return the alwaysShow
114: * @return the alwaysShow.
115: */
116: public final boolean isAlwaysShow() {
117: return _alwaysShow;
118: }
119:
120: /**
121: * Return the defValue
122: * @return the defValue.
123: */
124: public final String getDefValue() {
125: return _defValue;
126: }
127:
128: /**
129: * Return the order
130: * @return the order.
131: */
132: protected final int getOrder() {
133: return _order;
134: }
135:
136: /**
137: * {@inheritDoc}
138: */
139: public int compareTo(Object o) {
140: URLLocal local = (URLLocal) o;
141: if (equals(o)) {
142: return 0;
143: }
144: if (_order < local._order) {
145: return -1;
146: } else {
147: return 1;
148: }
149: }
150: }
|