001:/*
002: * The contents of this file are subject to the Sapient Public License
003: * Version 1.0 (the "License"); you may not use this file except in compliance
004: * with the License. You may obtain a copy of the License at
005: * http://carbon.sf.net/License.html.
006: *
007: * Software distributed under the License is distributed on an "AS IS" basis,
008: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009: * the specific language governing rights and limitations under the License.
010: *
011: * The Original Code is The Carbon Component Framework.
012: *
013: * The Initial Developer of the Original Code is Sapient Corporation
014: *
015: * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
016: */
017:
018:package org.sape.carbon.services.threadpool;
019:
020:import java.io.ObjectStreamException;
021:import java.io.Serializable;
022:
023:import org.sape.carbon.core.util.enum.BaseEnum;
024:import org.sape.carbon.core.util.enum.EnumNotFoundException;
025:
026:/**
027: * This class enumerates the possible task states.
028: *
029: * <br>Copyright 2002 Sapient
030: * @since carbon 2.1
031: * @author Douglas Voet, Nov 5, 2002
032: * @version $Revision: 1.7 $($Author: dvoet $ / $Date: 2003/11/20 18:49:59 $)
033: */
034:public class TaskStatusEnum extends BaseEnum implements Serializable {
035:
036: /** the task is queued and waiting for execution */
037: public static final TaskStatusEnum PENDING =
038: new TaskStatusEnum("Pending");
039:
040: /** the task is currently assigned to a thread and is executing */
041: public static final TaskStatusEnum EXECUTING =
042: new TaskStatusEnum("Executing");
043:
044: /** the task completed successfully */
045: public static final TaskStatusEnum SUCCESS =
046: new TaskStatusEnum("Success");
047:
048: /** the task completed with an exception */
049: public static final TaskStatusEnum FAILED =
050: new TaskStatusEnum("Failed");
051:
052: /**
053: * Constructor for TaskStatusEnum.
054: * @param enumeratedType
055: * @param name
056: * @param ordinal
057: */
058: private TaskStatusEnum(String name) {
059: super (TaskStatusEnum.class, name);
060: }
061:
062: /**
063: * Strongly typed enum retriever
064: */
065: public static final TaskStatusEnum getByName(String name)
066: throws TaskStatusEnumNotFoundException {
067:
068: TaskStatusEnum status =
069: (TaskStatusEnum) BaseEnum.getByName(name, TaskStatusEnum.class);
070:
071: if (status == null) {
072: throw new TaskStatusEnumNotFoundException(
073: TaskStatusEnum.class,
074: name);
075: }
076:
077: return status;
078: }
079:
080: /**
081: * Strongly typed enum retriever
082: */
083: public static final TaskStatusEnum getByOrdinal(int ordinal)
084: throws TaskStatusEnumNotFoundException {
085:
086: TaskStatusEnum status =
087: (TaskStatusEnum) BaseEnum.getByOrdinal(
088: ordinal,
089: TaskStatusEnum.class);
090:
091: if (status == null) {
092: throw new TaskStatusEnumNotFoundException(
093: TaskStatusEnum.class,
094: new Integer(ordinal).toString());
095: }
096:
097: return status;
098: }
099:
100: /**
101: * Overrides part of serialization to return a reference to an existing
102: * static Enumeration
103: */
104: final Object readResolve() throws ObjectStreamException {
105: return super .getByOrdinal(this .ordinal, this .getClass());
106: }
107:
108: /**
109: * This class is a typesafe retriever exception for an enumeration
110: */
111: public static class TaskStatusEnumNotFoundException
112: extends EnumNotFoundException {
113: /**
114: * Constructor for LifecycleStateEnumNotFoundException.
115: * @param sourceClass
116: * @param name
117: */
118: public TaskStatusEnumNotFoundException(Class sourceClass, String name) {
119: super(sourceClass, name);
120: }
121: }
122:}
|