KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > jsfext > event > handlers > HandlerContextImpl


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 package com.sun.enterprise.tools.jsfext.event.handlers;
24
25 import com.sun.enterprise.tools.jsfext.layout.descriptor.LayoutElement;
26
27 import java.util.EventObject JavaDoc;
28
29 import javax.faces.context.FacesContext;
30
31
32 /**
33  *
34  * @author Ken Paulsen (ken.paulsen@sun.com)
35  */

36 public class HandlerContextImpl implements HandlerContext {
37
38     /**
39      * <p> Constructor.</p>
40      */

41     public HandlerContextImpl(FacesContext context, LayoutElement layoutDesc, EventObject JavaDoc event, String JavaDoc eventType) {
42     _facesContext = context;
43     _layoutDesc = layoutDesc;
44     _event = event;
45     _eventType = eventType;
46     }
47
48     /**
49      * <p> Constructor that gets all its values from the given
50      * HandlerContext.</p>
51      *
52      * @param context The HandlerContext to clone.
53      */

54     public HandlerContextImpl(HandlerContext context) {
55     _facesContext = context.getFacesContext();
56     _layoutDesc = context.getLayoutElement();
57     _event = context.getEventObject();
58     _eventType = context.getEventType();
59     _handler = context.getHandler();
60     }
61
62     /**
63      * <p> Accessor for the FacesContext.</p>
64      *
65      * @return FacesContext
66      */

67     public FacesContext getFacesContext() {
68     return _facesContext;
69     }
70
71     /**
72      * <p> Accessor for the LayoutElement associated with this Handler.</p>
73      */

74     public LayoutElement getLayoutElement() {
75     return _layoutDesc;
76     }
77
78     /**
79      * <p> Accessor for the EventObject associated with this Handler. This
80      * may be null if an EventObject was not created for this handler.
81      * An EventObject, if it does exist, may provide additional details
82      * describing the context in which this Event is invoked.</p>
83      */

84     public EventObject JavaDoc getEventObject() {
85     return _event;
86     }
87
88     /**
89      * <p> This method provides access to the EventType. This is mostly
90      * helpful for diagnostics, but may be used in a handler to determine
91      * more information about the context in which the code is
92      * executing.</p>
93      */

94     public String JavaDoc getEventType() {
95     return _eventType;
96     }
97
98     /**
99      * <p> Accessor for the Handler descriptor for this Handler. The Handler
100      * descriptor object contains specific meta information describing
101      * the invocation of this handler. This includes details such as
102      * input values, and where output values are to be set.</p>
103      */

104     public Handler getHandler() {
105     return _handler;
106     }
107
108     /**
109      * <p> Setter for the Handler descriptor for this Handler.</p>
110      */

111     public void setHandler(Handler handler) {
112     _handler = handler;
113     }
114
115     /**
116      * <p> Accessor for the Handler descriptor for this Handler. The
117      * HandlerDefinition descriptor contains meta information about the
118      * actual Java handler that will handle the processing. This
119      * includes the inputs required, outputs produces, and the types for
120      * both.</p>
121      */

122     public HandlerDefinition getHandlerDefinition() {
123     return _handler.getHandlerDefinition();
124     }
125
126     /**
127      * <p> This method returns the value for the named input. Input values
128      * are not stored in this HandlerContext itself, but in the Handler.
129      * If you are trying to set input values for a handler, you must
130      * create a new Handler object and set its input values.</p>
131      *
132      * <p> This method attempts to resolve $...{...} expressions. It also
133      * will return the default value if the value is null. If you don't
134      * want these things to happen, look at
135      * Handler.getInputValue(String).</p>
136      *
137      * @param name The input name
138      *
139      * @return The value of the input (null if not found)
140      */

141     public Object JavaDoc getInputValue(String JavaDoc name) {
142     return getHandler().getInputValue(this, name);
143     }
144
145     /**
146      * <p> This method retrieves an Output value. Output values must not be
147      * stored in this Context itself (remember HandlerContext objects
148      * are shared). Output values are stored according to what is
149      * specified in the HandlerDefintion.</p>
150      *
151      * @param name The output name
152      *
153      * @return The value of the output (null if not found)
154      */

155     public Object JavaDoc getOutputValue(String JavaDoc name) {
156     return getHandler().getOutputValue(this, name);
157     }
158
159     /**
160      * <p> This method sets an Output value. Output values must not be
161      * stored in this Context itself (remember HandlerContext objects
162      * are shared). Output values are stored according to what is
163      * specified in the HandlerDefintion.</p>
164      */

165     public void setOutputValue(String JavaDoc name, Object JavaDoc value) {
166     getHandler().setOutputValue(this, name, value);
167     }
168
169     private String JavaDoc _eventType = null;
170     private FacesContext _facesContext = null;
171     private LayoutElement _layoutDesc = null;
172     private EventObject JavaDoc _event = null;
173     private Handler _handler = null;
174 }
175
Popular Tags