001    package org.apache.myfaces.tobago.component;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FREQUENCY;
021    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_UPDATE;
022    
023    import javax.faces.component.UIComponentBase;
024    import javax.faces.context.FacesContext;
025    import javax.faces.el.ValueBinding;
026    
027    /*
028     * Date: 28.05.2006
029     * Time: 21:57:46
030     */
031    public class UIReload extends UIComponentBase {
032      public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Reload";
033      public static final String COMPONENT_FAMILY = "org.apache.myfaces.tobago.Reload";
034    
035      private Integer frequency;
036    
037      private Boolean update;
038    
039      public Object saveState(FacesContext context) {
040        Object[] values = new Object[3];
041        values[0] = super.saveState(context);
042        values[1] = frequency;
043        values[2] = update;
044        return values;
045      }
046    
047      public void restoreState(FacesContext context, Object savedState) {
048        Object[] values = (Object[]) savedState;
049        super.restoreState(context, values[0]);
050        frequency = (Integer) values[1];
051        update = (Boolean) values[2];
052      }
053    
054      public int getFrequency() {
055        if (frequency != null) {
056          return frequency;
057        }
058        ValueBinding vb = getValueBinding(ATTR_FREQUENCY);
059        Integer value = null;
060        if (vb != null) {
061          value = (Integer) vb.getValue(getFacesContext());
062        }
063        if (value != null) {
064          return value;
065        } else {
066          return 5000;
067        }
068      }
069    
070      public void setFrequency(int frequency) {
071        this.frequency = frequency;
072      }
073    
074      public void setUpdate(boolean update) {
075        this.update = update;
076      }
077    
078      public boolean getUpdate() {
079        if (update != null) {
080          return update;
081        }
082        ValueBinding vb = getValueBinding(ATTR_UPDATE);
083        Boolean value = null;
084        if (vb != null) {
085          value = (Boolean) vb.getValue(getFacesContext());
086        }
087        if (value != null) {
088          return value;
089        } else {
090          return true;
091        }
092      }
093    
094      public String getFamily() {
095        return COMPONENT_FAMILY;
096      }
097    }