KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > component > UIExoComponentBase


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.faces.core.component;
6
7 import java.io.IOException JavaDoc;
8 import java.util.List JavaDoc;
9 import javax.faces.component.UIComponent;
10 import javax.faces.component.UIComponentBase;
11 import javax.faces.context.ExternalContext;
12 import javax.faces.context.FacesContext;
13 import javax.faces.render.Renderer;
14 import org.exoplatform.Constants;
15 import org.exoplatform.container.SessionContainer;
16 import org.exoplatform.faces.UIComponentFactory;
17 import org.exoplatform.faces.context.PortletExternalContext;
18 import org.exoplatform.faces.core.Util;
19 import org.exoplatform.faces.core.renderer.html.Decorator;
20 import org.exoplatform.portal.session.RequestInfo;
21 import org.exoplatform.text.template.DataHandler;
22 import org.exoplatform.text.template.xhtml.Element;
23
24 /**
25  * Wed, Dec 22, 2003 @ 23:14
26  * @author: Tuan Nguyen
27  * @email: tuan08@users.sourceforge.net
28  * @version: $Id: UIExoComponentBase.java,v 1.28 2004/10/27 02:52:15 tuan08 Exp $
29  */

30 public class UIExoComponentBase extends UIComponentBase implements UIExoComponent {
31   private String JavaDoc baseURL_ ;
32   private String JavaDoc clazz_;
33   private Decorator decorator_ ;
34   private transient Renderer cacheRenderer_ ;
35
36   public String JavaDoc getClazz() { return clazz_ ; }
37   public UIExoComponent setClazz(String JavaDoc clazz) {
38     clazz_ = clazz ;
39     return this ;
40   }
41
42   public String JavaDoc getFamily() { return UIExoComponent.COMPONENT_FAMILY ; }
43   
44   public boolean canDecodeInvalidState() { return true ; }
45   
46   public UIExoComponent setDecorator(Decorator decorator) {
47     decorator_ = decorator ;
48     return this ;
49   }
50   
51   public void processDecodes(FacesContext context) {
52     List JavaDoc children = getChildren() ;
53     for(int i = 0 ; i < children.size(); i++) {
54       UIComponent child = (UIComponent) children.get(i);
55       if (child.isRendered()) {
56         child.processDecodes(context) ;
57         if (context.getRenderResponse()) return ;
58       }
59     }
60     decode(context) ;
61   }
62   
63   public void setRendererType(String JavaDoc type) {
64     cacheRenderer_ = null ;
65     super.setRendererType(type) ;
66   }
67   
68   protected Renderer getRenderer(FacesContext context) {
69     if(cacheRenderer_ == null) {
70       cacheRenderer_ = Util.getRenderer(context, getRendererType(), getFamily());
71     }
72     return cacheRenderer_ ;
73   }
74   
75   public UIExoComponent findComponentById(String JavaDoc id) {
76     return ComponentUtil.findComponentById(this, id) ;
77   }
78   
79   public UIExoComponent findRenderedComponentById(String JavaDoc id) {
80     return ComponentUtil.findRenderedComponentById(this, id) ;
81   }
82   
83   
84   public UIComponent getAncestorOfType(Class JavaDoc classType) {
85     return ComponentUtil.getAncestorOfType(this, classType) ;
86   }
87   
88   public Object JavaDoc getChildComponentOfType(Class JavaDoc classType) {
89     return ComponentUtil.getChildComponentOfType(this, classType) ;
90   }
91   
92   public void setRenderedComponent(String JavaDoc id) {
93     ComponentUtil.setRenderedComponent(this, id) ;
94   }
95   
96   public void setRenderedComponent(Class JavaDoc type) {
97     ComponentUtil.setRenderedComponent(this, type) ;
98   }
99   
100   public void setRenderedSibling(Class JavaDoc type) {
101     ComponentUtil.setRenderedSibling(this, type) ;
102   }
103   
104   public UIComponent getSibling(Class JavaDoc type) {
105     return ComponentUtil.getSibling(this, type) ;
106   }
107   
108   public String JavaDoc getBaseURL(FacesContext context) {
109     if (baseURL_ == null) {
110       ExternalContext econtext = context.getExternalContext() ;
111       if(econtext instanceof PortletExternalContext) {
112         baseURL_ = econtext.encodeActionURL("") ;
113         baseURL_ += Constants.AMPERSAND + UICOMPONENT + "=" + getId() ;
114       } else {
115         RequestInfo rinfo = (RequestInfo)SessionContainer.getComponent(RequestInfo.class);
116         baseURL_ = rinfo.getOwnerURI();
117         baseURL_ += "?" + UICOMPONENT + "=" + getId() ;
118       }
119     }
120     return baseURL_ ;
121   }
122   
123   public String JavaDoc getBaseURL() { return getBaseURL(FacesContext.getCurrentInstance()); }
124
125   public void decorate(FacesContext context) throws IOException JavaDoc {
126     if(decorator_ != null) {
127       decorator_.decorate(context, this) ;
128     } else {
129       encodeBegin(context) ;
130       encodeChildren(context) ;
131       encodeEnd(context) ;
132     }
133   }
134   
135   public UIExoComponent addChild(Class JavaDoc cl) throws Exception JavaDoc {
136     UIExoComponent uiComponent = UIComponentFactory.createComponent(cl) ;
137     getChildren().add(uiComponent) ;
138     uiComponent.registerActionListener(this) ;
139     uiComponent.registerComponentObserver(this) ;
140     return uiComponent ;
141   }
142   
143   public void registerActionListener(UIExoComponent parent) {
144     
145   }
146   
147   public void registerComponentObserver(UIExoComponent parent) {
148     
149   }
150   
151   public DataHandler getDataHandler(Class JavaDoc classType) {
152     throw new RuntimeException JavaDoc("You need to override this method and return at least one default data handler") ;
153   }
154   
155   public Element getTemplate() {
156     throw new RuntimeException JavaDoc("You need to override this method") ;
157   }
158 }
159
Popular Tags