001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.model.scheduler;
042:
043: import java.io.IOException;
044: import java.io.Serializable;
045: import java.util.Calendar;
046: import javax.faces.context.FacesContext;
047: import com.sun.rave.web.ui.theme.Theme;
048: import com.sun.rave.web.ui.util.ThemeUtilities;
049:
050: import javax.faces.context.FacesContext;
051:
052: // Delete the setters once you have reimplemented this not to
053: // use the default Serializable mechanism, but the same as
054: // in the converter....
055:
056: public class RepeatInterval implements Serializable {
057:
058: public final static String ONETIME = "ONETIME";
059: public final static String HOURLY = "HOURLY";
060: public final static String DAILY = "DAILY";
061: public final static String WEEKLY = "WEEKLY";
062: public final static String MONTHLY = "MONTHLY";
063:
064: private static final boolean DEBUG = false;
065:
066: private static RepeatInterval ONETIME_RI = null;
067: private static RepeatInterval HOURLY_RI = null;
068: private static RepeatInterval DAILY_RI = null;
069: private static RepeatInterval WEEKLY_RI = null;
070: private static RepeatInterval MONTHLY_RI = null;
071:
072: private Integer calField = null;
073: private String key = null;
074: private String representation = null;
075: private String defaultRepeatUnitString = null;
076:
077: public RepeatInterval() {
078: }
079:
080: public RepeatInterval(int calFieldInt, String key, String rep,
081: String repUnit) {
082: if (DEBUG)
083: log("Create new RI");
084: this .calField = new Integer(calFieldInt);
085: this .key = key;
086: this .representation = rep;
087: this .defaultRepeatUnitString = repUnit;
088: if (DEBUG)
089: log("Representation is " + this .representation);
090: }
091:
092: public static RepeatInterval getInstance(String representation) {
093:
094: if (DEBUG)
095: log("getInstance(" + representation + ")");
096:
097: if (representation.equals(ONETIME)) {
098: if (ONETIME_RI == null) {
099: ONETIME_RI = new RepeatInterval(-1,
100: "Scheduler.oneTime", ONETIME, null);
101: }
102: return ONETIME_RI;
103: } else if (representation.equals(HOURLY)) {
104: if (HOURLY_RI == null) {
105: HOURLY_RI = new RepeatInterval(Calendar.HOUR_OF_DAY,
106: "Scheduler.hourly", HOURLY, RepeatUnit.HOURS);
107: }
108: return HOURLY_RI;
109: }
110: if (representation.equals(DAILY)) {
111: if (DAILY_RI == null) {
112: DAILY_RI = new RepeatInterval(Calendar.DATE,
113: "Scheduler.daily", DAILY, RepeatUnit.DAYS);
114: }
115: return DAILY_RI;
116: }
117: if (representation.equals(WEEKLY)) {
118: if (WEEKLY_RI == null) {
119: WEEKLY_RI = new RepeatInterval(Calendar.WEEK_OF_YEAR,
120: "Scheduler.weekly", WEEKLY, RepeatUnit.WEEKS);
121: }
122: return WEEKLY_RI;
123: }
124: if (representation.equals(MONTHLY)) {
125: if (MONTHLY_RI == null) {
126: MONTHLY_RI = new RepeatInterval(Calendar.MONTH,
127: "Scheduler.monthly", MONTHLY, RepeatUnit.MONTHS);
128: }
129: return MONTHLY_RI;
130: }
131: return null;
132: }
133:
134: /**
135: * Getter for property calendarField.
136: * @return Value of property calendarField.
137: */
138: public Integer getCalendarField() {
139: return calField;
140: }
141:
142: /**
143: * Setter for property calendarField.
144: * @return Value of property calendarField.
145: */
146: public void setCalendarField(Integer calField) {
147: this .calField = calField;
148: }
149:
150: public void setKey(String key) {
151: this .key = key;
152: }
153:
154: public String getKey() {
155: return key;
156: }
157:
158: public void setRepresentation(String representation) {
159: this .representation = representation;
160: }
161:
162: public String getRepresentation() {
163: return representation;
164: }
165:
166: /**
167: * Getter for property labelKey.
168: * @return Value of property labelKey.
169: */
170: public String getLabel(FacesContext context) {
171: return ThemeUtilities.getTheme(context).getMessage(key);
172: }
173:
174: public boolean equals(Object object) {
175: if (object == null) {
176: return false;
177: }
178: if (!(object instanceof RepeatInterval)) {
179: return false;
180: }
181: return (((RepeatInterval) object).getRepresentation()
182: .equals(representation));
183: }
184:
185: public RepeatUnit getDefaultRepeatUnit() {
186: if (defaultRepeatUnitString == null) {
187: return null;
188: }
189: return RepeatUnit.getInstance(defaultRepeatUnitString);
190: }
191:
192: private static void log(String s) {
193: System.out.println("RepeatInterval::" + s);
194: }
195: }
|