001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.subscriptions.admin.model;
007:
008: import java.lang.*;
009: import java.io.*;
010: import java.util.*;
011:
012: import com.sun.portal.subscriptions.admin.SubscriptionsAdminConstants;
013: import com.sun.portal.subscriptions.admin.util.Task;
014: import com.sun.portal.subscriptions.admin.util.ScheduleFactory;
015: import com.iplanet.jato.model.*;
016:
017: public class ScheduleModel extends DefaultModel implements
018: RetrievingModel, UpdatingModel {
019: public static final String FIELD_NAME = "FieldName";
020: public static final String FIELD_HOUR = "FieldHour";
021: public static final String FIELD_MIN = "FieldMin";
022: public static final String FIELD_COMMAND = "Command";
023: public static final String FIELD_DIR = "Dir";
024: public static final String FIELD_SUN = "Sun";
025: public static final String FIELD_MON = "Mon";
026: public static final String FIELD_TUE = "Tue";
027: public static final String FIELD_WED = "Wed";
028: public static final String FIELD_THU = "Thu";
029: public static final String FIELD_FRI = "Fri";
030: public static final String FIELD_SAT = "Sat";
031: private static final String[] WEEKDAYS_ARRAY = { FIELD_SUN,
032: FIELD_MON, FIELD_TUE, FIELD_WED, FIELD_THU, FIELD_FRI,
033: FIELD_SAT };
034:
035: public static final String hourLabel[] = { "00", "01", "02", "03",
036: "04", "05", "06", "07", "08", "09", "10", "11", "12", "13",
037: "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" };
038: public static final String hourValues[] = { "0", "1", "2", "3",
039: "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14",
040: "15", "16", "17", "18", "19", "20", "21", "22", "23" };
041: public static final String minValues[] = { "00", "10", "20", "30",
042: "40", "50" };
043:
044: protected String name = null;
045: protected String organization = null;
046: protected String serverRoot = null;
047:
048: /**
049: * @param req The HttpServletRequest object passed to the super class.
050: * @param rbName The name of the resource bundle.
051: */
052: public ScheduleModel() {
053: super ();
054: }
055:
056: public ScheduleModel(String name, String organization,
057: String serverRoot) {
058: super (name);
059: setName(name);
060: setOrganization(organization);
061: setServerRoot(serverRoot);
062: }
063:
064: public void setName(String name) {
065: this .name = name;
066: }
067:
068: public void setOrganization(String org) {
069: this .organization = org;
070: }
071:
072: public void setServerRoot(String serverRoot) {
073: this .serverRoot = serverRoot;
074: }
075:
076: // Model execution methods
077: ////////////////////////////////////////////////////////////////////////////////
078:
079: /**
080: *
081: *
082: */
083: public Object execute(ModelExecutionContext context)
084: throws ModelControlException {
085: String operationName = null;
086: if (context != null)
087: operationName = context.getOperationName();
088: else
089: operationName = ModelExecutionContext.OPERATION_RETRIEVE;
090:
091: Object result = null;
092: if (operationName
093: .equals(ModelExecutionContext.OPERATION_RETRIEVE)) {
094: result = retrieve(context);
095: }
096: return result;
097: }
098:
099: /**
100: *
101: *
102: */
103: public Object update(ModelExecutionContext context)
104: throws ModelControlException {
105: Task task = newTaskObject();
106: task.init(name, organization, serverRoot);
107: task.setValue(Task.MINUTES, (String) getValue(FIELD_MIN));
108: task.setValue(Task.HOURS, (String) getValue(FIELD_HOUR));
109: String dir = (String) getValue(FIELD_DIR);
110: String d = "";
111: if (((String) getValue(FIELD_SUN)).compareTo("true") == 0) {
112: d = d + "0,";
113: }
114: if (((String) getValue(FIELD_MON)).compareTo("true") == 0) {
115: d = d + "1,";
116: }
117: if (((String) getValue(FIELD_TUE)).compareTo("true") == 0) {
118: d = d + "2,";
119: }
120: if (((String) getValue(FIELD_WED)).compareTo("true") == 0) {
121: d = d + "3,";
122: }
123: if (((String) getValue(FIELD_THU)).compareTo("true") == 0) {
124: d = d + "4,";
125: }
126: if (((String) getValue(FIELD_FRI)).compareTo("true") == 0) {
127: d = d + "5,";
128: }
129: if (((String) getValue(FIELD_SAT)).compareTo("true") == 0) {
130: d = d + "6,";
131: }
132: if (d.trim().length() > 0) {
133: task.setValue(Task.DAYS_OF_WEEK, d.substring(0,
134: d.length() - 1));
135: task.Update();
136: } else {
137: task.Remove();
138: }
139: return null;
140: }
141:
142: /**
143: *
144: *
145: */
146: public Object retrieve(ModelExecutionContext context)
147: throws ModelControlException {
148: // Perform a dummy retrieve operation. We ignore the
149: // execution context for now.
150: clear();
151: if (name != null) {
152: Task task = newTaskObject();
153: task.init(name, organization, serverRoot);
154: setValue(FIELD_NAME, name);
155: String hrs = task.getValue(Task.HOURS);
156: String mins = task.getValue(Task.MINUTES);
157: if (hrs != null && mins != null) {
158: setValue(FIELD_HOUR, hrs);
159: setValue(FIELD_MIN, mins);
160: }
161:
162: String v = task.getValue(Task.DAYS_OF_WEEK);
163: if (v != null) {
164: StringTokenizer st = new StringTokenizer(v, ",");
165: while (st.hasMoreTokens()) {
166: String d = st.nextToken();
167: int ndx = Integer.parseInt(d);
168: try {
169: setValue(WEEKDAYS_ARRAY[ndx], "true");
170: } catch (Exception e) {
171: }
172: }
173: }
174: }
175: // Nothing useful to return
176: return null;
177: }
178:
179: public Object delete(ModelExecutionContext context)
180: throws ModelControlException {
181: if (name != null) {
182: Task task = newTaskObject();
183: task.init(name, organization, serverRoot);
184: task.Remove();
185: }
186: return null;
187: }
188:
189: private Task newTaskObject() {
190: try {
191: return ScheduleFactory.getNewTask();
192: } catch (Exception e) {
193: return null;
194: }
195: }
196:
197: }
|