KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > lang > jstl > EmptyOperator


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18
19 package org.apache.taglibs.standard.lang.jstl;
20
21
22
23 import java.lang.reflect.Array JavaDoc;
24
25 import java.util.Collection JavaDoc;
26
27 import java.util.Map JavaDoc;
28
29
30
31 /**
32
33  *
34
35  * <p>The implementation of the empty operator
36
37  *
38
39  * @author Nathan Abramson - Art Technology Group
40
41  * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: pierred $
42
43  **/

44
45
46
47 public class EmptyOperator
48
49   extends UnaryOperator
50
51 {
52
53   //-------------------------------------
54

55   // Singleton
56

57   //-------------------------------------
58

59
60
61   public static final EmptyOperator SINGLETON =
62
63     new EmptyOperator ();
64
65
66
67   //-------------------------------------
68

69   /**
70
71    *
72
73    * Constructor
74
75    **/

76
77   public EmptyOperator ()
78
79   {
80
81   }
82
83
84
85   //-------------------------------------
86

87   // Expression methods
88

89   //-------------------------------------
90

91   /**
92
93    *
94
95    * Returns the symbol representing the operator
96
97    **/

98
99   public String JavaDoc getOperatorSymbol ()
100
101   {
102
103     return "empty";
104
105   }
106
107
108
109   //-------------------------------------
110

111   /**
112
113    *
114
115    * Applies the operator to the given value
116
117    **/

118
119   public Object JavaDoc apply (Object JavaDoc pValue,
120
121                Object JavaDoc pContext,
122
123                Logger pLogger)
124
125     throws ELException
126
127   {
128
129     // See if the value is null
130

131     if (pValue == null) {
132
133       return PrimitiveObjects.getBoolean (true);
134
135     }
136
137
138
139     // See if the value is a zero-length String
140

141     else if ("".equals (pValue)) {
142
143       return PrimitiveObjects.getBoolean (true);
144
145     }
146
147
148
149     // See if the value is a zero-length array
150

151     else if (pValue.getClass ().isArray () &&
152
153          Array.getLength (pValue) == 0) {
154
155       return PrimitiveObjects.getBoolean (true);
156
157     }
158
159
160
161     // See if the value is an empty Collection
162

163     else if (pValue instanceof Collection JavaDoc &&
164
165          ((Collection JavaDoc) pValue).isEmpty ()) {
166
167       return PrimitiveObjects.getBoolean (true);
168
169     }
170
171
172
173     // See if the value is an empty Map
174

175     else if (pValue instanceof Map JavaDoc &&
176
177          ((Map JavaDoc) pValue).isEmpty ()) {
178
179       return PrimitiveObjects.getBoolean (true);
180
181     }
182
183
184
185     // Otherwise, not empty
186

187     else {
188
189       return PrimitiveObjects.getBoolean (false);
190
191     }
192
193   }
194
195
196
197   //-------------------------------------
198

199 }
200
201
Popular Tags