001: /*
002: * Copyright 2005-2007 Noelios Consulting.
003: *
004: * The contents of this file are subject to the terms of the Common Development
005: * and Distribution License (the "License"). You may not use this file except in
006: * compliance with the License.
007: *
008: * You can obtain a copy of the license at
009: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
010: * language governing permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL HEADER in each file and
013: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
014: * applicable, add the following below this CDDL HEADER, with the fields
015: * enclosed by brackets "[]" replaced with your own identifying information:
016: * Portions Copyright [yyyy] [name of copyright owner]
017: */
018:
019: package org.restlet.util;
020:
021: /**
022: * Variable descriptor for reference templates.
023: *
024: * @see Template
025: * @author Jerome Louvel (contact@noelios.com)
026: */
027: public final class Variable {
028: /** Matches all characters. */
029: public static final int TYPE_ALL = 1;
030:
031: /** Matches all alphabetical characters. */
032: public static final int TYPE_ALPHA = 2;
033:
034: /** Matches all alphabetical and digital characters. */
035: public static final int TYPE_ALPHA_DIGIT = 3;
036:
037: /** Matches all digital characters. */
038: public static final int TYPE_DIGIT = 4;
039:
040: /** Matches all URI characters. */
041: public static final int TYPE_URI_ALL = 5;
042:
043: /** Matches URI fragment characters. */
044: public static final int TYPE_URI_FRAGMENT = 6;
045:
046: /** Matches URI query characters. */
047: public static final int TYPE_URI_QUERY = 7;
048:
049: /** Matches URI scheme characters. */
050: public static final int TYPE_URI_SCHEME = 8;
051:
052: /** Matches URI segment characters. */
053: public static final int TYPE_URI_SEGMENT = 9;
054:
055: /** Matches unreserved URI characters. */
056: public static final int TYPE_URI_UNRESERVED = 10;
057:
058: /** Matches all alphabetical and digital characters plus the underscore. */
059: public static final int TYPE_WORD = 11;
060:
061: /** The type of variable. See TYPE_* constants. */
062: private int type;
063:
064: /** The default value to use if the key couldn't be found in the model. */
065: private String defaultValue;
066:
067: /** Indicates if the variable is required or optional. */
068: private boolean required;
069:
070: /**
071: * Indicates if the value is fixed, in which case the "defaultValue"
072: * property is always used.
073: */
074: private boolean fixed;
075:
076: /**
077: * Default constructor. Type is TYPE_ALL, default value is "", required is
078: * true and fixed is false.
079: */
080: public Variable() {
081: this (Variable.TYPE_ALL, "", true, false);
082: }
083:
084: /**
085: * Constructor. Default value is "", required is true and fixed is false.
086: *
087: * @param type
088: * The type of variable. See TYPE_* constants.
089: */
090: public Variable(int type) {
091: this (type, "", true, false);
092: }
093:
094: /**
095: * Constructor.
096: *
097: * @param type
098: * The type of variable. See TYPE_* constants.
099: * @param defaultValue
100: * The default value to use if the key couldn't be found in the
101: * model.
102: * @param required
103: * Indicates if the variable is required or optional.
104: * @param fixed
105: * Indicates if the value is fixed, in which case the
106: * "defaultValue" property is always used.
107: */
108: public Variable(int type, String defaultValue, boolean required,
109: boolean fixed) {
110: this .type = type;
111: this .defaultValue = defaultValue;
112: this .required = required;
113: this .fixed = fixed;
114: }
115:
116: /**
117: * Returns the type of variable. See TYPE_* constants.
118: *
119: * @return The type of variable. See TYPE_* constants.
120: */
121: public int getType() {
122: return this .type;
123: }
124:
125: /**
126: * Returns the default value to use if the key couldn't be found in the
127: * model.
128: *
129: * @return The default value to use if the key couldn't be found in the
130: * model.
131: */
132: public String getDefaultValue() {
133: return this .defaultValue;
134: }
135:
136: /**
137: * Returns true if the variable is required or optional.
138: *
139: * @return True if the variable is required or optional.
140: */
141: public boolean isRequired() {
142: return this .required;
143: }
144:
145: /**
146: * Returns true if the value is fixed, in which case the "defaultValue"
147: * property is always used.
148: *
149: * @return True if the value is fixed, in which case the "defaultValue"
150: * property is always used.
151: */
152: public boolean isFixed() {
153: return this.fixed;
154: }
155:
156: }
|