001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.faces.component;
030:
031: import java.io.*;
032: import java.util.*;
033:
034: import javax.el.*;
035:
036: import javax.faces.*;
037: import javax.faces.context.*;
038: import javax.faces.el.*;
039: import javax.faces.event.*;
040: import javax.faces.render.*;
041:
042: public abstract class UIComponent implements StateHolder {
043: public abstract Map<String, Object> getAttributes();
044:
045: @Deprecated
046: public abstract ValueBinding getValueBinding(String name);
047:
048: @Deprecated
049: public abstract void setValueBinding(String name,
050: ValueBinding binding);
051:
052: /**
053: * @Since 1.2
054: */
055: public javax.el.ValueExpression getValueExpression(String name) {
056: throw new UnsupportedOperationException();
057: }
058:
059: /**
060: * @Since 1.2
061: */
062: public void setValueExpression(String name, ValueExpression binding) {
063: throw new UnsupportedOperationException();
064: }
065:
066: public abstract String getClientId(FacesContext context);
067:
068: /**
069: * @Since 1.2
070: */
071: public String getContainerClientId(FacesContext context) {
072: return getClientId(context);
073: }
074:
075: public abstract String getFamily();
076:
077: public abstract String getId();
078:
079: public abstract void setId(String id);
080:
081: public abstract UIComponent getParent();
082:
083: public abstract void setParent(UIComponent parent);
084:
085: public abstract boolean isRendered();
086:
087: public abstract void setRendered(boolean rendered);
088:
089: public abstract String getRendererType();
090:
091: public abstract void setRendererType(String rendererType);
092:
093: public abstract boolean getRendersChildren();
094:
095: public abstract List<UIComponent> getChildren();
096:
097: public abstract int getChildCount();
098:
099: public abstract UIComponent findComponent(String expr);
100:
101: /**
102: * @Since 1.2
103: */
104: public boolean invokeOnComponent(FacesContext context,
105: String clientId, ContextCallback callback)
106: throws FacesException {
107: if (context == null || clientId == null || callback == null)
108: throw new NullPointerException();
109:
110: if (clientId.equals(getClientId(context))) {
111: callback.invokeContextCallback(context, this );
112: return true;
113: } else {
114: Iterator<UIComponent> iter = getFacetsAndChildren();
115:
116: while (iter.hasNext()) {
117: UIComponent comp = iter.next();
118:
119: boolean result = comp.invokeOnComponent(context,
120: clientId, callback);
121: if (result)
122: return true;
123: }
124:
125: return false;
126: }
127: }
128:
129: public abstract Map<String, UIComponent> getFacets();
130:
131: /**
132: * @Since 1.2
133: */
134: public int getFacetCount() {
135: Map<String, UIComponent> map = getFacets();
136:
137: if (map == null)
138: return 0;
139: else
140: return getFacets().size();
141: }
142:
143: public abstract UIComponent getFacet(String name);
144:
145: public abstract Iterator<UIComponent> getFacetsAndChildren();
146:
147: public abstract void broadcast(FacesEvent event)
148: throws AbortProcessingException;
149:
150: public abstract void decode(FacesContext context);
151:
152: public abstract void encodeBegin(FacesContext context)
153: throws IOException;
154:
155: public abstract void encodeChildren(FacesContext context)
156: throws IOException;
157:
158: public abstract void encodeEnd(FacesContext context)
159: throws IOException;
160:
161: /**
162: * @Since 1.2
163: */
164:
165: /**
166: * Encodes all children
167: */
168: public void encodeAll(FacesContext context) throws IOException {
169: if (context == null)
170: throw new NullPointerException();
171:
172: if (!isRendered()) {
173: return;
174: }
175:
176: encodeBegin(context);
177:
178: if (getRendersChildren()) {
179: encodeChildren(context);
180: } else {
181: int childCount = getChildCount();
182:
183: if (childCount > 0) {
184: List<UIComponent> children = getChildren();
185:
186: for (int i = 0; i < childCount; i++) {
187: UIComponent child = children.get(i);
188:
189: child.encodeAll(context);
190: }
191: }
192: }
193:
194: encodeEnd(context);
195: }
196:
197: protected abstract void addFacesListener(FacesListener listener);
198:
199: protected abstract FacesListener[] getFacesListeners(Class cl);
200:
201: protected abstract void removeFacesListener(FacesListener listener);
202:
203: public abstract void queueEvent(FacesEvent event);
204:
205: public abstract void processRestoreState(FacesContext context,
206: Object state);
207:
208: public abstract void processDecodes(FacesContext context);
209:
210: public abstract void processValidators(FacesContext context);
211:
212: public abstract void processUpdates(FacesContext context);
213:
214: public abstract Object processSaveState(FacesContext context);
215:
216: protected abstract FacesContext getFacesContext();
217:
218: protected abstract Renderer getRenderer(FacesContext context);
219: }
|