KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > event > handlers > ViewHandlers


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.handlers;
25
26 import com.iplanet.jato.RequestContext;
27 import com.iplanet.jato.ViewBeanManager;
28 import com.iplanet.jato.view.ContainerView;
29 import com.iplanet.jato.view.View;
30
31 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
32 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
33 import com.sun.enterprise.tools.guiframework.view.DescriptorViewManager;
34
35 import java.util.Iterator JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.Map JavaDoc;
38
39
40 /**
41  *
42  */

43 public class ViewHandlers {
44
45     /**
46      * <P>This method locates the specified View. It requires the id of the
47      * View specified as a Parameter. The key for the View is "viewID". The
48      * value of this field may be a List of viewID's -- this walks the
49      * hierachy to the specified View.</P>
50      *
51      * @param reqCtx The RequestContext
52      * @param handlerCtx The HandlerContext
53      */

54     public void getView(RequestContext reqCtx, HandlerContext handlerCtx) {
55     // Get the View ID
56
Object JavaDoc viewID = handlerCtx.getInputValue(VIEW_ID);
57     if (viewID == null) {
58         throw new FrameworkException(
59         "The parameter map did not contain "+VIEW_ID+"!");
60     }
61
62     // Try to obtain the ContainerView
63
ViewBeanManager vm = reqCtx.getViewBeanManager();
64     View view = null;
65     String JavaDoc topName = (viewID instanceof List JavaDoc) ?
66         ((List JavaDoc)viewID).get(0).toString() : viewID.toString();
67     try {
68         view = vm.getViewBean(topName);
69     } catch (ClassCastException JavaDoc ex) {
70         view = ((DescriptorViewManager)vm).getView(null, topName);
71     } catch (ClassNotFoundException JavaDoc ex) {
72         throw new FrameworkException(ex);
73     }
74     if (view == null) {
75         throw new FrameworkException(
76         "Unable to obtain the view for mapping!");
77     }
78
79     // If we have more than 1 ID, walk the View...
80
if (viewID instanceof List JavaDoc) {
81         Iterator JavaDoc iter = ((List JavaDoc)viewID).iterator();
82         iter.next(); // Already used the first one
83
while (iter.hasNext()) {
84         if (!(view instanceof ContainerView)) {
85             throw new FrameworkException("View ("+
86             view.getQualifiedName()+") is not a ContainerView!",
87             null, view);
88         }
89         view = ((ContainerView)view).getChild(""+iter.next());
90         }
91     }
92
93     // Return the View
94
handlerCtx.setOutputValue(VALUE, view);
95     }
96
97
98     /**
99      * <P>This method locates the specified View. It requires the id of the
100      * View specified as a Parameter. The key for the View is "viewID". The
101      * value of this field may be a List of viewID's -- this walks the
102      * hierachy to the specified View.</P>
103      *
104      * <P>Optionally one more child can be looked up. The child name is
105      * specified in the LEAF_VIEW parameter.
106      *
107      * @param reqCtx The RequestContext
108      * @param handlerCtx The HandlerContext
109      */

110     public void getQualifiedName(RequestContext reqCtx, HandlerContext handlerCtx) {
111     View view = (View)handlerCtx.getOutputValue(VIEW);
112     if (view == null) {
113         // We can get the result of the getView() handler using handlerCtx
114
getView(reqCtx, handlerCtx);
115         view = (View)handlerCtx.getOutputValue(VALUE);
116     }
117
118     String JavaDoc leaf = (String JavaDoc)handlerCtx.getInputValue(LEAF_VIEW);
119     if (leaf != null) {
120         view = ((ContainerView)view).getChild(leaf);
121     }
122
123     // Set the output value
124
handlerCtx.setOutputValue(VALUE, view.getQualifiedName());
125     }
126
127
128     /**
129      *
130      */

131     public static final String JavaDoc VALUE = "value";
132
133     /**
134      *
135      */

136     public static final String JavaDoc VIEW = "view";
137
138     /**
139      *
140      */

141     public static final String JavaDoc VIEW_ID = "viewID";
142
143     /**
144      *
145      */

146     public static final String JavaDoc LEAF_VIEW = "leafView";
147 }
148
Popular Tags