1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.trinidad.model;
20
21 import java.io.Serializable;
22 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
23
24
25 /**
26 * Default BoundedRangeModel implementation. Defaults 'maximum' and 'value' to
27 * be -1. Validates that value <= maximum.
28 * This model implementation can conveniently be used by the 'progress'
29 * components.
30 *
31 * @version $Name: $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/model/DefaultBoundedRangeModel.java#0 $) $Date: 10-nov-2005.19:08:52 $
32 */
33 public class DefaultBoundedRangeModel extends BoundedRangeModel implements Serializable {
34 /**
35 * Construct a new DefaultBoundedRangeModel with defaults.
36 */
37 public DefaultBoundedRangeModel()
38 {
39 _maximum = -1;
40 _value = -1;
41 }
42
43 /**
44 * Constructs a new DefaultBoundedRangeModel with specified 'maximum' and
45 * 'value'.
46 * value should be in the range -1 <-> maximum.
47 * @param value - the value for this model.
48 * @param maximum - the maximum for this bounded range.
49 * @exception IllegalArgumentException if the value is not in the valid range.
50 */
51 public DefaultBoundedRangeModel(long value, long maximum)
52 {
53 if (value > maximum || value < -1)
54 {
55 throw new IllegalArgumentException(_LOG.getMessage(
56 "SETTING_ILLEGAL_VALUE"));
57 }
58 _maximum = maximum;
59 _value = value;
60 }
61
62 @Override
63 public long getMaximum()
64 {
65 return _maximum;
66 }
67
68 @Override
69 public long getValue()
70 {
71 return _value;
72 }
73
74 /**
75 * Sets the maximum value for this model.
76 * Defaults to -1 which indicates that maximum is unknown.
77 * @param maximum the maximum value to be set
78 */
79 public void setMaximum(long maximum)
80 {
81 _maximum = maximum;
82 }
83
84 /**
85 * Sets the current value for this model.
86 * Ensure that the maximum is set before the value is being set.
87 * Value should be in the range -1 <-> maximum. Defaults to -1.
88 * @param value the current value to be set.
89 * @exception IllegalArgumentException if the value is not in the valid range.
90 */
91 public void setValue(long value)
92 {
93 if (value > _maximum || value < -1)
94 {
95 throw new IllegalArgumentException(_LOG.getMessage(
96 "SETTING_ILLEGAL_VALUE"));
97 }
98 _value = value;
99 }
100
101 private long _value;
102 private long _maximum;
103 private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
104 DefaultBoundedRangeModel.class);
105
106 private static final long serialVersionUID = 1L;
107 }