KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > samples > components > taglib > MapTag


1 /*
2  * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or
5  * without modification, are permitted provided that the following
6  * conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * - Redistribution in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials
14  * provided with the distribution.
15  *
16  * Neither the name of Sun Microsystems, Inc. or the names of
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * This software is provided "AS IS," without a warranty of any
21  * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
22  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
24  * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
25  * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
26  * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
27  * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
28  * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
29  * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
30  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
31  * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
32  * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
33  *
34  * You acknowledge that this software is not designed, licensed or
35  * intended for use in the design, construction, operation or
36  * maintenance of any nuclear facility.
37  */

38
39 package org.apache.cocoon.faces.samples.components.taglib;
40
41
42 import org.apache.cocoon.faces.FacesUtils;
43 import org.apache.cocoon.faces.taglib.UIComponentTag;
44 import org.apache.cocoon.faces.samples.components.components.MapComponent;
45 import org.apache.cocoon.faces.samples.components.renderkit.Util;
46 import org.apache.commons.lang.BooleanUtils;
47
48 import javax.faces.component.UIComponent;
49 import javax.faces.context.FacesContext;
50 import javax.faces.el.MethodBinding;
51 import javax.faces.el.ValueBinding;
52 import javax.faces.event.ActionEvent;
53
54
55 /**
56  * <p>{@link UIComponentTag} for an image map.</p>
57  */

58
59 public class MapTag extends UIComponentTag {
60
61
62     private String JavaDoc current = null;
63
64
65     public void setCurrent(String JavaDoc current) {
66         this.current = current;
67     }
68
69
70     private String JavaDoc actionListener = null;
71
72
73     public void setActionListener(String JavaDoc actionListener) {
74         this.actionListener = actionListener;
75     }
76
77
78     private String JavaDoc action = null;
79
80
81     public void setAction(String JavaDoc action) {
82         this.action = action;
83     }
84
85
86     private String JavaDoc immediate = null;
87
88
89     public void setImmediate(String JavaDoc immediate) {
90         this.immediate = immediate;
91     }
92
93
94     private String JavaDoc styleClass = null;
95
96
97     public void setStyleClass(String JavaDoc styleClass) {
98         this.styleClass = styleClass;
99     }
100
101
102     public String JavaDoc getComponentType() {
103         return ("DemoMap");
104     }
105
106
107     public String JavaDoc getRendererType() {
108         return ("DemoMap");
109     }
110
111
112     public void recycle() {
113         super.recycle();
114         current = null;
115         styleClass = null;
116         actionListener = null;
117         action = null;
118         immediate = null;
119         styleClass = null;
120     }
121
122
123     protected void setProperties(UIComponent component) {
124         super.setProperties(component);
125         MapComponent map = (MapComponent) component;
126         // if (current != null) {
127
// map.setCurrent(current);
128
// }
129
if (styleClass != null) {
130             if (FacesUtils.isExpression(styleClass)) {
131                 ValueBinding vb = FacesContext.getCurrentInstance()
132                     .getApplication().
133                     createValueBinding(styleClass);
134                 map.setValueBinding("styleClass", vb);
135             } else {
136                 map.getAttributes().put("styleClass", styleClass);
137             }
138         }
139         if (actionListener != null) {
140             if (FacesUtils.isExpression(actionListener)) {
141                 Class JavaDoc args[] = {ActionEvent.class};
142                 MethodBinding mb = FacesContext.getCurrentInstance()
143                     .getApplication()
144                     .createMethodBinding(actionListener, args);
145                 map.setActionListener(mb);
146             } else {
147                 Object JavaDoc params [] = {actionListener};
148                 throw new javax.faces.FacesException();
149             }
150         }
151
152         if (action != null) {
153             if (FacesUtils.isExpression(action)) {
154                 MethodBinding vb = FacesContext.getCurrentInstance()
155                     .getApplication()
156                     .createMethodBinding(action, null);
157                 map.setAction(vb);
158             } else {
159                 map.setAction(Util.createConstantMethodBinding(action));
160             }
161         }
162         if (immediate != null) {
163             if (FacesUtils.isExpression(immediate)) {
164                 ValueBinding vb = FacesContext.getCurrentInstance()
165                     .getApplication().
166                     createValueBinding(immediate);
167                 map.setValueBinding("immediate", vb);
168             } else {
169                 map.setImmediate(BooleanUtils.toBoolean(immediate));
170             }
171         }
172
173     }
174
175
176 }
177
Popular Tags