KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > event > descriptors > EventDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.guiframework.event.descriptors;
25
26
27 import com.iplanet.jato.view.View;
28
29 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
30 import com.sun.enterprise.tools.guiframework.FrameworkDescriptor;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.Map JavaDoc;
36
37
38 /**
39  * This class describes an Event. It contains a List of UseHandlerDescriptors
40  * and a type. The UseHandlerDescriptors further describe where a handler's
41  * method is, and if any mappings should be performed before or after the
42  * handler method is invoked.
43  */

44 public class EventDescriptor implements FrameworkDescriptor {
45
46     /**
47      * Constructor.
48      *
49      * @param parent The ViewDescriptor shich contains this Event.
50      * @param eventType The type of event (beginDisplay, command, etc.)
51      */

52     public EventDescriptor(ViewDescriptor parent, String JavaDoc eventType) {
53     setParent(parent);
54     setType(eventType);
55     }
56
57
58     /**
59      * This method returns the ViewDescriptor that contains this event.
60      *
61      * @return The parent descriptor
62      */

63     public ViewDescriptor getParent() {
64     return _parent;
65     }
66
67
68     /**
69      * This method sets the parent ViewDescriptor.
70      *
71      * @param parent The parent ViewDescriptor
72      */

73     protected void setParent(ViewDescriptor parent) {
74     if (parent == null) {
75         throw new RuntimeException JavaDoc("You must provide a the " +
76         "ViewDescriptor which contains this EventDescriptor!");
77     }
78     _parent = parent;
79     }
80
81
82     /**
83      * This method returns the EventDescriptor type
84      *
85      * @return The Event descriptor type
86      */

87     public String JavaDoc getType() {
88     return _eventType;
89     }
90
91
92     /**
93      * This method sets the event type.
94      *
95      * @param type The event type.
96      */

97     protected void setType(String JavaDoc type) {
98     if (type == null) {
99             throw new IllegalArgumentException JavaDoc(
100         "You must provide an Event type!");
101     }
102
103     // Try to find the registered event type
104
_eventType = (String JavaDoc)_eventTypesMap.get(type.toLowerCase());
105     if (_eventType == null) {
106             throw new IllegalArgumentException JavaDoc(
107         "Illegal event type: "+type);
108     }
109     }
110
111
112     /**
113      * <P>This method allows UseHandlerDescriptors to be added. You can add
114      * as many handlers as you desire, they will be invoked in the order they
115      * are added.</P>
116      *
117      * <P>The method should be public; return void; accept 2 parameters: 1 of
118      * type "RequestContext", one of type "HandlerContext" Example:</P>
119      *
120      * <P> <BLOCKQUOTE>
121      * public void beginDisplay(
122      * RequestContext reqCtx, HandlerContext handlerCtx)
123      * throws ModelControlException
124      * </BLOCKQUOTE></P>
125      *
126      * @param desc The UserHandlerDescriptor to add.
127      */

128     public void addEventHandler(UseHandlerDescriptor desc) {
129     // Add to the list
130
_handlers.add(desc);
131     }
132
133     
134     /**
135      * This method returns the List of handlers for this descriptor. Each
136      * item in the List is of type UseHandlerDescriptor, which in turn, refer
137      * to a HandlerDescriptor which describes the actual Method to invoke.
138      *
139      * @return List of handlers for this EventDescriptor.
140      *
141      * @see #addEventHandler(UseHandlerDescriptor)
142      */

143     public List JavaDoc getEventHandlers() {
144     return _handlers;
145     }
146
147
148     /**
149      * This method allows the List of handlers to be set.
150      *
151      * @param handlers The List of UseHandlerDescriptor objects
152      *
153      * @see #addEventHandler(UseHandlerDescriptor)
154      */

155     public void setEventHandlers(List JavaDoc handlers) {
156     _handlers = handlers;
157     }
158
159
160     public interface TYPES {
161     // These are the valid Event types
162
String JavaDoc BEGIN_DISPLAY = "beginDisplay";
163     String JavaDoc END_DISPLAY = "endDisplay";
164     String JavaDoc COMMAND = "command";
165     String JavaDoc BEFORE_CREATE = "beforeCreate";
166     String JavaDoc AFTER_CREATE = "afterCreate";
167     String JavaDoc AFTER_REQUEST = "afterRequest";
168     String JavaDoc ERROR = "error";
169         String JavaDoc END_WIZARD = "endWizard";
170         String JavaDoc NEXT_WIZARD_STEP = "nextWizardStep";
171         String JavaDoc PREV_WIZARD_STEP = "prevWizardStep";
172         String JavaDoc GOTO_WIZARD_STEP = "gotoWizardStep";
173         String JavaDoc FINISH_WIZARD_STEP = "finishWizardStep";
174         String JavaDoc CANCEL_WIZARD_STEP = "cancelWizardStep";
175     }
176
177     private ViewDescriptor _parent = null;
178     private String JavaDoc _eventType = null;
179     private List JavaDoc _handlers = new ArrayList JavaDoc();
180
181     private static Map JavaDoc _eventTypesMap = new HashMap JavaDoc();
182
183     static {
184     _eventTypesMap.put(TYPES.BEGIN_DISPLAY.toLowerCase(), TYPES.BEGIN_DISPLAY);
185     _eventTypesMap.put(TYPES.END_DISPLAY.toLowerCase(), TYPES.END_DISPLAY);
186     _eventTypesMap.put(TYPES.COMMAND.toLowerCase(), TYPES.COMMAND);
187     _eventTypesMap.put(TYPES.BEFORE_CREATE.toLowerCase(), TYPES.BEFORE_CREATE);
188     _eventTypesMap.put(TYPES.AFTER_CREATE.toLowerCase(), TYPES.AFTER_CREATE);
189     _eventTypesMap.put(TYPES.AFTER_REQUEST.toLowerCase(), TYPES.AFTER_REQUEST);
190     _eventTypesMap.put(TYPES.ERROR.toLowerCase(), TYPES.ERROR);
191     _eventTypesMap.put(TYPES.END_WIZARD.toLowerCase(), TYPES.END_WIZARD);
192     _eventTypesMap.put(TYPES.NEXT_WIZARD_STEP.toLowerCase(), TYPES.NEXT_WIZARD_STEP);
193     _eventTypesMap.put(TYPES.PREV_WIZARD_STEP.toLowerCase(), TYPES.PREV_WIZARD_STEP);
194     _eventTypesMap.put(TYPES.GOTO_WIZARD_STEP.toLowerCase(), TYPES.GOTO_WIZARD_STEP);
195     _eventTypesMap.put(TYPES.FINISH_WIZARD_STEP.toLowerCase(), TYPES.FINISH_WIZARD_STEP);
196     _eventTypesMap.put(TYPES.CANCEL_WIZARD_STEP.toLowerCase(), TYPES.CANCEL_WIZARD_STEP);
197     }
198 }
199
Popular Tags