View Javadoc

1   /*
2    * $Id: MockTag.java 651946 2008-04-27 13:41:38Z apetrelli $
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  
22  package org.apache.struts2.views.jsp.ui;
23  
24  import java.util.Calendar;
25  import java.util.Date;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import javax.servlet.jsp.tagext.BodyTagSupport;
30  
31  
32  /***
33   */
34  public class MockTag extends BodyTagSupport {
35  
36      private static final long serialVersionUID = 2694367759647164641L;
37  
38      private static String s;
39      private static Integer i;
40      private static Double d;
41      private static Long l;
42      private static Float f;
43      private static Date date;
44      private static Calendar cal;
45      private static HashMap params;
46      private static MockTag instance = new MockTag();
47  
48  
49      public static MockTag getInstance() {
50          return instance;
51      }
52  
53      public void setCal(Calendar cal) {
54          MockTag.cal = cal;
55      }
56  
57      public Calendar getCal() {
58          return cal;
59      }
60  
61      public void setDate(Date date) {
62          MockTag.date = date;
63      }
64  
65      public Date getDate() {
66          return date;
67      }
68  
69      public void setDouble(Double d) {
70          MockTag.d = d;
71      }
72  
73      public Double getDouble() {
74          return d;
75      }
76  
77      public void setFloat(Float f) {
78          MockTag.f = f;
79      }
80  
81      public Float getFloat() {
82          return f;
83      }
84  
85      public void setInteger(Integer i) {
86          MockTag.i = i;
87      }
88  
89      public Integer getInteger() {
90          return i;
91      }
92  
93      public void setLong(Long l) {
94          MockTag.l = l;
95      }
96  
97      public Long getLong() {
98          return l;
99      }
100 
101     public Map getParameters() {
102         return MockTag.params;
103     }
104 
105     public void setString(String s) {
106         MockTag.s = s;
107     }
108 
109     public String getString() {
110         return s;
111     }
112 
113     public void addParameter(String key, Object value) {
114         MockTag.params.put(key, value);
115     }
116 
117     /***
118      * resets all the static variables to their initial state.  this must be called before each test!
119      */
120     public void reset() {
121         s = null;
122         i = null;
123         l = null;
124         f = null;
125         date = null;
126         cal = null;
127         params = new HashMap();
128     }
129 }