View Javadoc

1   /*
2    * $Id: MockTag.java 471756 2006-11-06 15:01:43Z husted $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.struts2.views.jsp.ui;
22  
23  import java.util.Calendar;
24  import java.util.Date;
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  import javax.servlet.jsp.tagext.BodyTagSupport;
29  
30  
31  /***
32   */
33  public class MockTag extends BodyTagSupport {
34  
35      private static final long serialVersionUID = 2694367759647164641L;
36  
37      private static String s;
38      private static Integer i;
39      private static Double d;
40      private static Long l;
41      private static Float f;
42      private static Date date;
43      private static Calendar cal;
44      private static HashMap params;
45      private static MockTag instance = new MockTag();
46  
47  
48      public static MockTag getInstance() {
49          return instance;
50      }
51  
52      public void setCal(Calendar cal) {
53          MockTag.cal = cal;
54      }
55  
56      public Calendar getCal() {
57          return cal;
58      }
59  
60      public void setDate(Date date) {
61          MockTag.date = date;
62      }
63  
64      public Date getDate() {
65          return date;
66      }
67  
68      public void setDouble(Double d) {
69          MockTag.d = d;
70      }
71  
72      public Double getDouble() {
73          return d;
74      }
75  
76      public void setFloat(Float f) {
77          MockTag.f = f;
78      }
79  
80      public Float getFloat() {
81          return f;
82      }
83  
84      public void setInteger(Integer i) {
85          MockTag.i = i;
86      }
87  
88      public Integer getInteger() {
89          return i;
90      }
91  
92      public void setLong(Long l) {
93          MockTag.l = l;
94      }
95  
96      public Long getLong() {
97          return l;
98      }
99  
100     public Map getParameters() {
101         return MockTag.params;
102     }
103 
104     public void setString(String s) {
105         MockTag.s = s;
106     }
107 
108     public String getString() {
109         return s;
110     }
111 
112     public void addParameter(String key, Object value) {
113         MockTag.params.put(key, value);
114     }
115 
116     /***
117      * resets all the static variables to their initial state.  this must be called before each test!
118      */
119     public void reset() {
120         s = null;
121         i = null;
122         l = null;
123         f = null;
124         date = null;
125         cal = null;
126         params = new HashMap();
127     }
128 }