KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > shim > MockModule


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.shim;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.http.HttpServletResponse JavaDoc;
25 import javax.servlet.jsp.JspWriter JavaDoc;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.DynaActionForm;
29 import java.io.IOException JavaDoc;
30
31 public class MockModule
32 implements
33   Module {
34
35   // constructors /////////////////////////////////////////////////////////////
36

37   // constants ////////////////////////////////////////////////////////////////
38

39   // classes //////////////////////////////////////////////////////////////////
40

41   // methods //////////////////////////////////////////////////////////////////
42

43   /**
44    * Returns a short descriptive name for the module.
45    */

46   public String JavaDoc getName() {
47     return "Mock";
48   }
49
50   /**
51    * Returns <tt>true</tt> if the module has a configuration interface; that
52    * is, if {@link #configure} actually does something.
53    */

54   public boolean isConfigurable() {
55     return configurable_;
56   }
57
58   public static void setConfigurable( boolean configurable ) {
59     configurable_ = configurable;
60   }
61
62   public boolean isEditable() {
63     return editable_;
64   }
65
66   public static void setEditable( boolean editable ) {
67     editable_ = editable;
68   }
69
70   /**
71    * Sets the module's <tt>page</tt> and <tt>panel</tt>. This method is called
72    * before any other operations are performed.
73    */

74   public void init(
75     Page page,
76     String JavaDoc panel ) {
77
78     text_ = "";
79   }
80
81   /**
82    * Creates the module. This method is called when a module is instantiated
83    * for a page and panel. The module should be initialized such that future
84    * calls to {@link #configure} and {@link #display} are successful.
85    */

86   public void create() {
87   }
88
89   /**
90    * Manages the configuration interface for the module.
91    */

92   public ActionForward configure(
93     ActionMapping mapping,
94     DynaActionForm form,
95     HttpServletRequest JavaDoc request,
96     HttpServletResponse JavaDoc response ) {
97
98     return mapping.findForward( "accessDenied" );
99   }
100
101   public void update(
102     String JavaDoc text ) {
103
104     //
105
// use a null text_ to indicate whether the module has been init'd; this
106
// turned up in PageActionTest.testDoSavePanel()
107
//
108
if ( text_ != null );
109       text_ = text;
110   }
111
112   public static String JavaDoc getText() {
113     return text_;
114   }
115
116   /**
117    * Displays the module.
118    */

119   public void display(
120     HttpServletRequest JavaDoc request,
121     HttpServletResponse JavaDoc response,
122     JspWriter JavaDoc out )
123   throws
124     IOException JavaDoc {
125
126     out.println( "Hello from MockModule.display()." );
127   }
128
129   public static void setDestroyed( boolean destroyed ) {
130     destroyed_ = destroyed;
131   }
132
133   public static boolean isDestroyed() {
134     return destroyed_;
135   }
136
137   public static void setCopied( boolean copied ) {
138     copied_ = copied;
139   }
140
141   public static boolean isCopied() {
142     return copied_;
143   }
144
145   /**
146    * Destroys the module, freeing any resources associated with the module.
147    */

148   public void destroy() {
149     destroyed_ = true;
150   }
151
152   /**
153    * Copies the module to <tt>page</tt>.
154    */

155   public void copyTo(
156     Page page ) {
157     copied_ = true;
158   }
159
160   // properties ///////////////////////////////////////////////////////////////
161

162   private static boolean configurable_ = false;
163
164   private static boolean editable_ = false;
165
166   private static String JavaDoc text_ = null;
167
168   private static boolean destroyed_ = false;
169
170   private static boolean copied_ = false;
171
172   // attributes ///////////////////////////////////////////////////////////////
173
}
174
Popular Tags