KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > common > component > evaluator > BaseEvaluator


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.ui.common.component.evaluator;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.faces.context.FacesContext;
22 import javax.faces.el.ValueBinding;
23
24 import org.apache.log4j.Logger;
25
26 import org.alfresco.web.ui.common.component.SelfRenderingComponent;
27
28 /**
29  * @author kevinr
30  */

31 public abstract class BaseEvaluator extends SelfRenderingComponent
32 {
33    /**
34     * @see javax.faces.component.UIComponent#getFamily()
35     */

36    public final String JavaDoc getFamily()
37    {
38       return "org.alfresco.faces.evaluators";
39    }
40
41    /**
42     * @see javax.faces.component.UIComponentBase#getRendersChildren()
43     */

44    public final boolean getRendersChildren()
45    {
46       return !evaluate();
47    }
48
49    /**
50     * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
51     */

52    public final void encodeBegin(FacesContext context) throws IOException JavaDoc
53    {
54       // no output for this component
55
}
56
57    /**
58     * @see javax.faces.component.UIComponentBase#encodeChildren(javax.faces.context.FacesContext)
59     */

60    public final void encodeChildren(FacesContext context) throws IOException JavaDoc
61    {
62       // if this is called, then the evaluate returned false which means
63
// the child components show not be allowed to render themselves
64
}
65
66    /**
67     * @see javax.faces.component.UIComponentBase#encodeEnd(javax.faces.context.FacesContext)
68     */

69    public final void encodeEnd(FacesContext context) throws IOException JavaDoc
70    {
71       // no output for this component
72
}
73    
74    /**
75     * Get the value for this component to be evaluated against
76     *
77     * @return the value for this component to be evaluated against
78     */

79    public Object JavaDoc getValue()
80    {
81       ValueBinding vb = getValueBinding("value");
82       if (vb != null)
83       {
84          this.value = vb.getValue(getFacesContext());
85       }
86       
87       return this.value;
88    }
89
90    /**
91     * Set the value for this component to be evaluated against
92     *
93     * @param value the value for this component to be evaluated against
94     */

95    public void setValue(Object JavaDoc value)
96    {
97       this.value = value;
98    }
99    
100    /**
101     * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
102     */

103    public void restoreState(FacesContext context, Object JavaDoc state)
104    {
105       Object JavaDoc values[] = (Object JavaDoc[])state;
106       // standard component attributes are restored by the super class
107
super.restoreState(context, values[0]);
108       this.value = values[1];
109    }
110    
111    /**
112     * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
113     */

114    public Object JavaDoc saveState(FacesContext context)
115    {
116       Object JavaDoc values[] = new Object JavaDoc[2];
117       // standard component attributes are saved by the super class
118
values[0] = super.saveState(context);
119       values[1] = this.value;
120       return (values);
121    }
122    
123    /**
124     * Evaluate against the component attributes. Return true to allow the inner
125     * components to render, false to hide them during rendering.
126     *
127     * @return true to allow rendering of child components, false otherwise
128     */

129    public abstract boolean evaluate();
130    
131    
132    protected static Logger s_logger = Logger.getLogger(BaseEvaluator.class);
133    
134    /** the value to be evaluated against */
135    private Object JavaDoc value;
136 }
137
Popular Tags