001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001-2003, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol;
037:
038: import java.io.ObjectStreamException;
039: import java.io.Serializable;
040: import java.util.HashMap;
041: import java.util.Map;
042:
043: /**
044: * An enumeration of Project states following standard typesafe enumeration
045: * pattern in Java.
046: */
047: public final class ProjectState implements Serializable {
048: private static final Map ALL_STATES = new HashMap();
049:
050: public static final ProjectState QUEUED = new ProjectState(1,
051: "queued", "in build queue");
052: public static final ProjectState IDLE = new ProjectState(0, "idle",
053: "idle");
054: public static final ProjectState BOOTSTRAPPING = new ProjectState(
055: 2, "bootstrapping", "bootstrapping");
056: public static final ProjectState MODIFICATIONSET = new ProjectState(
057: 3, "modificationset", "checking for modifications");
058: public static final ProjectState BUILDING = new ProjectState(4,
059: "building", "now building");
060: public static final ProjectState MERGING_LOGS = new ProjectState(5,
061: "merging", "merging accumulated log files");
062: public static final ProjectState PUBLISHING = new ProjectState(6,
063: "publishing", "publishing build results");
064: public static final ProjectState PAUSED = new ProjectState(7,
065: "paused", "paused");
066: public static final ProjectState STOPPED = new ProjectState(8,
067: "stopped", "stopped");
068: public static final ProjectState WAITING = new ProjectState(9,
069: "waiting", "waiting for next time to build");
070:
071: private String description;
072: private String name;
073: private int code;
074:
075: private ProjectState(int code, String name, String desc) {
076: this .code = code;
077: this .name = name;
078: this .description = desc;
079: ALL_STATES.put(name, this );
080: }
081:
082: public String getDescription() {
083: return description;
084: }
085:
086: public int getCode() {
087: return code;
088: }
089:
090: public String getName() {
091: return name;
092: }
093:
094: /**
095: * A <strong>magic</strong> method used by Java Object Serialization. This
096: * allows ProjectState to force the deserialization process to use one of
097: * the ProjectState enum instances that already exist.
098: *
099: * @return a replacement object instance
100: * @throws ObjectStreamException
101: * never actually thrown
102: */
103: private Object readResolve() throws ObjectStreamException {
104: return ALL_STATES.get(name);
105: }
106:
107: public boolean hasDescription(String description) {
108: return this.description.equals(description);
109: }
110: }
|