001: /*
002: * Copyright (c) 2003 The Visigoth Software Society. All rights
003: * reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * 1. Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * 2. Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in
014: * the documentation and/or other materials provided with the
015: * distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowledgement:
019: * "This product includes software developed by the
020: * Visigoth Software Society (http://www.visigoths.org/)."
021: * Alternately, this acknowledgement may appear in the software itself,
022: * if and wherever such third-party acknowledgements normally appear.
023: *
024: * 4. Neither the name "FreeMarker", "Visigoth", nor any of the names of the
025: * project contributors may be used to endorse or promote products derived
026: * from this software without prior written permission. For written
027: * permission, please contact visigoths@visigoths.org.
028: *
029: * 5. Products derived from this software may not be called "FreeMarker" or "Visigoth"
030: * nor may "FreeMarker" or "Visigoth" appear in their names
031: * without prior written permission of the Visigoth Software Society.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036: * DISCLAIMED. IN NO EVENT SHALL THE VISIGOTH SOFTWARE SOCIETY OR
037: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044: * SUCH DAMAGE.
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of the Visigoth Software Society. For more
049: * information on the Visigoth Software Society, please see
050: * http://www.visigoths.org/
051: */
052:
053: package freemarker.template.utility;
054:
055: import freemarker.template.SimpleNumber;
056: import freemarker.template.TemplateBooleanModel;
057: import freemarker.template.TemplateCollectionModel;
058: import freemarker.template.TemplateHashModelEx;
059: import freemarker.template.TemplateModel;
060: import freemarker.template.TemplateModelException;
061: import freemarker.template.TemplateModelIterator;
062: import freemarker.template.TemplateNumberModel;
063: import freemarker.template.TemplateScalarModel;
064: import freemarker.template.TemplateSequenceModel;
065:
066: /**
067: * Frequently used constant {@link TemplateModel} values.
068: *
069: * <p>These constants should be stored in the {@link TemplateModel}
070: * sub-interfaces, but for bacward compatibility they are stored here instead.
071: * Starting from FreeMarker 2.4 they should be copyed (not moved!) into the
072: * {@link TemplateModel} sub-interfaces, and this class should be marked as
073: * deprecated.</p>
074: *
075: * @version $Id: Constants.java,v 1.2 2004/11/28 12:58:34 ddekany Exp $
076: */
077: public class Constants {
078:
079: public static final TemplateBooleanModel TRUE = TemplateBooleanModel.TRUE;
080:
081: public static final TemplateBooleanModel FALSE = TemplateBooleanModel.FALSE;
082:
083: public static final TemplateScalarModel EMPTY_STRING = (TemplateScalarModel) TemplateScalarModel.EMPTY_STRING;
084:
085: public static final TemplateNumberModel ZERO = new SimpleNumber(0);
086:
087: public static final TemplateNumberModel ONE = new SimpleNumber(1);
088:
089: public static final TemplateNumberModel MINUS_ONE = new SimpleNumber(
090: -1);
091:
092: public static final TemplateModelIterator EMPTY_ITERATOR = new TemplateModelIterator() {
093:
094: public TemplateModel next() throws TemplateModelException {
095: throw new TemplateModelException(
096: "The collection has no more elements.");
097: }
098:
099: public boolean hasNext() throws TemplateModelException {
100: return false;
101: }
102:
103: };
104:
105: public static final TemplateCollectionModel EMPTY_COLLECTION = new TemplateCollectionModel() {
106:
107: public TemplateModelIterator iterator()
108: throws TemplateModelException {
109: return EMPTY_ITERATOR;
110: }
111:
112: };
113:
114: public static final TemplateSequenceModel EMPTY_SEQUENCE = new TemplateSequenceModel() {
115:
116: public TemplateModel get(int index)
117: throws TemplateModelException {
118: return null;
119: }
120:
121: public int size() throws TemplateModelException {
122: return 0;
123: }
124:
125: };
126:
127: public static final TemplateHashModelEx EMPTY_HASH = new TemplateHashModelEx() {
128:
129: public int size() throws TemplateModelException {
130: return 0;
131: }
132:
133: public TemplateCollectionModel keys()
134: throws TemplateModelException {
135: return EMPTY_COLLECTION;
136: }
137:
138: public TemplateCollectionModel values()
139: throws TemplateModelException {
140: return EMPTY_COLLECTION;
141: }
142:
143: public TemplateModel get(String key)
144: throws TemplateModelException {
145: return null;
146: }
147:
148: public boolean isEmpty() throws TemplateModelException {
149: return true;
150: }
151:
152: };
153:
154: }
|