KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.iplanet.jato.RequestContext;
27
28 import com.sun.enterprise.tools.guiframework.FrameworkDescriptor;
29 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
30 import com.sun.enterprise.tools.guiframework.util.PermissionChecker;
31 import com.sun.enterprise.tools.guiframework.util.Util;
32 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
33
34 import java.lang.reflect.Method JavaDoc;
35 import java.util.EventObject JavaDoc;
36 import java.util.HashMap JavaDoc;
37 import java.util.Map JavaDoc;
38
39
40 /**
41  * This class holds information about "call" element. A "call"
42  * refers to a handler and provides the inputs needed for the
43  * handler. A "call" is either a child of an EventDescriptor, or a
44  * child of handler definition.
45  */

46 public class UseHandlerDescriptor implements FrameworkDescriptor {
47
48     /**
49      * Constructor.
50      *
51      * @param parent The EventDescriptor which contains this Handler.
52      */

53     public UseHandlerDescriptor(FrameworkDescriptor parent, HandlerDescriptor handlerDesc) {
54     setParent(parent);
55     setHandlerDescriptor(handlerDesc);
56     }
57
58
59     /**
60      * This method returns the EventDescriptor that contains this handler.
61      *
62      * @return The parent descriptor
63      */

64     public FrameworkDescriptor getParent() {
65     return _parent;
66     }
67
68
69     /**
70      *
71      */

72     public HandlerDescriptor getHandlerDescriptor() {
73     return _handler;
74     }
75
76
77     /**
78      * This method sets the parent EventDescriptor.
79      *
80      * @param parent The parent EventDescriptor
81      */

82     protected void setParent(FrameworkDescriptor parent) {
83     if (parent == null) {
84         throw new FrameworkException("You must provide a the " +
85         "FrameworkDescriptor which contains this " +
86         "UseHandlerDescriptor!");
87     }
88     _parent = parent;
89     }
90
91
92     /**
93      * This method sets the handler descriptor used by this "useHandler".
94      */

95     protected void setHandlerDescriptor(HandlerDescriptor handler) {
96     _handler = handler;
97     }
98
99
100     /**
101      * Accessor for the ifCheck String
102      */

103     public String JavaDoc getIfCheck() {
104     return _ifCheck;
105     }
106
107
108     /**
109      * Setter for the ifCheck String
110      */

111     public void setIfCheck(String JavaDoc ifCheck) {
112     _ifCheck = ifCheck;
113     }
114
115
116     /**
117      * This method uses a PermissionChecker to evaluate the "ifCheck
118      * String". The ifCheck String is a boolean expression, see
119      * PermissionChecker for details. If the ifCheck String is null,
120      * then this method will return true. $(attribute-name) entries within
121      * the ifCheck String will be evaluated; they should evaluate to the
122      * Strings "true" or "false".
123      *
124      * @param vd The ViewDescriptor
125      *
126      * @return True if this Mapping has permission, false if not
127      */

128     public boolean hasPermission(ViewDescriptor vd) {
129     // Get the if="" value
130
String JavaDoc ifCheck = getIfCheck();
131     if ((ifCheck == null) || (ifCheck.trim().length() == 0)) {
132         // Default is to allow access
133
return true;
134     }
135
136     // Delegate to permission checker to determine result
137
return new PermissionChecker(ifCheck, vd).hasPermission();
138     }
139
140
141     /**
142      *
143      */

144     public void setInputValue(String JavaDoc name, Object JavaDoc value) {
145     _inputs.put(name, value);
146     }
147
148
149     /**
150      *
151      */

152     public Object JavaDoc getInputValue(String JavaDoc name) {
153     return _inputs.get(name);
154     }
155
156
157     /**
158      *
159      */

160     public void setOutputMapping(String JavaDoc name, String JavaDoc targetKey, String JavaDoc targetType) {
161     if ((name == null) || (name.length() == 0)) {
162         throw new FrameworkException("Name is required!");
163     }
164     if (targetKey != null) {
165         targetKey = targetKey.trim();
166         if (targetKey.length() == 0) {
167         targetKey = null;
168         }
169     }
170     if (targetType != null) {
171         targetType = targetType.trim();
172         if (targetType.length() == 0) {
173         targetType = null;
174         }
175     }
176     String JavaDoc outputDesc[] = new String JavaDoc[2];
177     outputDesc[0] = targetKey;
178     outputDesc[1] = targetType;
179     _outputs.put(name, outputDesc);
180     }
181
182
183     /**
184      *
185      */

186     public Object JavaDoc getOutputTargetKey(String JavaDoc name) {
187     return ((String JavaDoc[])_outputs.get(name))[0];
188     }
189
190
191     /**
192      *
193      */

194     public Object JavaDoc getOutputTargetType(String JavaDoc name) {
195     return ((String JavaDoc[])_outputs.get(name))[1];
196     }
197
198
199     /**
200      *
201      */

202     public String JavaDoc[] getOutputMapping(String JavaDoc name) {
203     return (String JavaDoc[])_outputs.get(name);
204     }
205
206
207     private FrameworkDescriptor _parent = null;
208     private String JavaDoc _ifCheck = null;
209     private HandlerDescriptor _handler = null;
210     private Map JavaDoc _inputs = new HashMap JavaDoc();
211     private Map JavaDoc _outputs = new HashMap JavaDoc();
212 }
213
Popular Tags