001: /**
002: * $Id: OSTasksImpl.java,v 1.11 2006/07/28 02:40:00 portalbld Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.fabric.util.os;
014:
015: import com.sun.portal.admin.common.context.PSConfigContext;
016: import com.sun.portal.fabric.util.ExecuteUtil;
017:
018: import java.util.logging.Logger;
019: import java.util.logging.Level;
020: import java.util.*;
021:
022: import com.sun.portal.log.common.PortalLogger;
023:
024: public abstract class OSTasksImpl implements OSTasks {
025:
026: private static final String COMMAND_SEPARATOR = "|";
027: public HashMap valuesMap = null;
028: PSConfigContext context;
029: private static Logger logger = PortalLogger
030: .getLogger(OSTasksImpl.class);
031: ExecuteUtil execUtil;
032:
033: public OSTasksImpl(PSConfigContext globalContext) {
034: super ();
035: context = globalContext;
036: execUtil = new ExecuteUtil();
037: valuesMap = new HashMap();
038: }
039:
040: public ArrayList getSchedules(String command) {
041: setValue(COMMAND, command);
042: return schedules();
043: }
044:
045: public void scheduling(String action, String mode) {
046: StringTokenizer st1 = new StringTokenizer(action,
047: COMMAND_SEPARATOR);
048: String command = (st1.hasMoreTokens()) ? st1.nextToken().trim()
049: : "";
050: if (command.equals("")) {
051: logger.log(Level.SEVERE, "PSFB_CSPFUOS0005", action);
052: return;
053: }
054: String schedules = (st1.hasMoreTokens()) ? st1.nextToken()
055: .trim() : "";
056: if (schedules.equals("")) {
057: logger.log(Level.SEVERE, "PSFB_CSPFUOS0006", action);
058: return;
059: }
060: StringTokenizer st2 = new StringTokenizer(schedules, ";");
061: while (st2.hasMoreTokens()) {
062: String schedule = st2.nextToken().trim();
063: StringTokenizer st3 = new StringTokenizer(schedule, "@");
064: String dayOfTheWeek = (st3.hasMoreTokens()) ? st3
065: .nextToken().trim() : "";
066: if (dayOfTheWeek.equals("")) {
067: logger.log(Level.SEVERE, "PSFB_CSPFUOS0007", action);
068: return;
069: }
070: int dayOfTheWeekValue = new Integer(dayOfTheWeek)
071: .intValue();
072: if (dayOfTheWeekValue < 0 || dayOfTheWeekValue > 6) {
073: logger.log(Level.SEVERE, "PSFB_CSPFUOS0008", action);
074: return;
075: }
076: String time = (st3.hasMoreTokens()) ? st3.nextToken()
077: .trim() : "";
078: if (time.equals("")) {
079: logger.log(Level.SEVERE, "PSFB_CSPFUOS0009", action);
080: return;
081: }
082: StringTokenizer st4 = new StringTokenizer(time, ":");
083: String hour = (st4.hasMoreTokens()) ? st4.nextToken()
084: .trim() : "";
085: if (hour.equals("")) {
086: logger.log(Level.SEVERE, "PSFB_CSPFUOS0010", action);
087: return;
088: }
089: int hourValue = new Integer(hour).intValue();
090: if (hourValue < 0 || hourValue > 23) {
091: logger.log(Level.SEVERE, "PSFB_CSPFUOS0011", action);
092: return;
093: }
094: String minute = (st4.hasMoreTokens()) ? st4.nextToken()
095: .trim() : "";
096: if (minute.equals("")) {
097: logger.log(Level.SEVERE, "PSFB_CSPFUOS0012", action);
098: return;
099: }
100: int minuteValue = new Integer(minute).intValue();
101: if (minuteValue < 0 || minuteValue > 59) {
102: logger.log(Level.SEVERE, "PSFB_CSPFUOS0013", action);
103: return;
104: }
105:
106: setValue(COMMAND, command);
107: setValue(DAYOFTHEWEEK, dayOfTheWeek);
108: setValue(HOUR, hour);
109: setValue(MINUTE, minute);
110:
111: if (mode.equals("schedule")) {
112: schedule();
113: } else {
114: unschedule();
115: }
116: }
117: }
118:
119: public String getValue(String key) {
120: if (valuesMap.containsKey(key)) {
121: return (String) valuesMap.get(key);
122: } else {
123: return "";
124: }
125: }
126:
127: public void setValue(String key, String value) {
128: if (valuesMap.containsKey(key)) {
129: valuesMap.remove(key);
130: }
131: valuesMap.put(key, value);
132: }
133:
134: public void preconfig() {
135: }
136:
137: public void postconfig() {
138: }
139:
140: public void preunconfig() {
141: }
142:
143: public void postunconfig() {
144: }
145:
146: }
|