KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.faces.context.FacesContext;
20 import javax.faces.el.ValueBinding;
21
22 /**
23  * @author kevinr
24  *
25  * Evaluates to true if the value exactly matches the supplied string condition.
26  */

27 public class StringEqualsEvaluator extends BaseEvaluator
28 {
29    /**
30     * Evaluate against the component attributes. Return true to allow the inner
31     * components to render, false to hide them during rendering.
32     *
33     * @return true to allow rendering of child components, false otherwise
34     */

35    public boolean evaluate()
36    {
37       boolean result = false;
38       
39       try
40       {
41          result = getCondition().equals((String JavaDoc)getValue());
42       }
43       catch (Exception JavaDoc err)
44       {
45          // return default value on error
46
s_logger.debug("Expected String value for evaluation: " + getValue());
47       }
48       
49       return result;
50    }
51    
52    /**
53     * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
54     */

55    public void restoreState(FacesContext context, Object JavaDoc state)
56    {
57       Object JavaDoc values[] = (Object JavaDoc[])state;
58       // standard component attributes are restored by the super class
59
super.restoreState(context, values[0]);
60       this.condition = (String JavaDoc)values[1];
61    }
62    
63    /**
64     * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
65     */

66    public Object JavaDoc saveState(FacesContext context)
67    {
68       Object JavaDoc values[] = new Object JavaDoc[2];
69       // standard component attributes are saved by the super class
70
values[0] = super.saveState(context);
71       values[1] = this.condition;
72       return (values);
73    }
74    
75    /**
76     * Get the string condition to match value against
77     *
78     * @return the string condition to match value against
79     */

80    public String JavaDoc getCondition()
81    {
82       ValueBinding vb = getValueBinding("condition");
83       if (vb != null)
84       {
85          this.condition = (String JavaDoc)vb.getValue(getFacesContext());
86       }
87       
88       return this.condition;
89    }
90    
91    /**
92     * Set the string condition to match value against
93     *
94     * @param condition string condition to match value against
95     */

96    public void setCondition(String JavaDoc condition)
97    {
98       this.condition = condition;
99    }
100    
101    
102    /** the string condition to match value against */
103    private String JavaDoc condition = null;
104 }
105
Popular Tags