001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package javax.jbi.messaging;
018    
019    /**
020     * Typesafe enumeration containing status values for a message exchange.
021     *
022     * @author JSR208 Expert Group
023     */
024    public final class ExchangeStatus {
025    
026        /**
027         * Indicates that an ME has not been processed to completion.
028         */
029        public static final ExchangeStatus ACTIVE = new ExchangeStatus("Active");
030    
031        /**
032         * Indicates that an ME has terminated abnormally within the JBI environment.
033         */
034        public static final ExchangeStatus ERROR = new ExchangeStatus("Error");
035    
036        /**
037         * Indicates that an ME has been processed to completion.
038         */
039        public static final ExchangeStatus DONE = new ExchangeStatus("Done");
040    
041        /** String representation of status. */
042        private String mStatus;
043    
044        /**
045         * Private constructor used to create a new ExchangeStatus type.
046         *
047         * @param status value
048         */
049        private ExchangeStatus(String status) {
050            mStatus = status;
051        }
052    
053        /**
054         * Returns string value of enumerated type.
055         *
056         * @return String representation of status value.
057         */
058        public String toString() {
059            return mStatus;
060        }
061    
062        /**
063         * Returns instance of ExchangeStatus that corresponds to given string.
064         *
065         * @param status string value of status
066         * @return ExchangeStatus
067         * @throws java.lang.IllegalArgumentException if string can't be translated
068         */
069        public static ExchangeStatus valueOf(String status) {
070            ExchangeStatus instance;
071    
072            //
073            //  Convert symbolic name to object reference.
074            //
075            if (status.equals(DONE.toString())) {
076                instance = DONE;
077            } else if (status.equals(ERROR.toString())) {
078                instance = ERROR;
079            } else if (status.equals(ACTIVE.toString())) {
080                instance = ACTIVE;
081    
082            } else {
083                //
084                //  Someone has a problem.
085                //
086                throw new java.lang.IllegalArgumentException(status);
087            }
088    
089            return instance;
090        }
091    
092        /**
093         * Returns hash code value for this object.
094         *
095         * @return hash code value
096         */
097        public int hashCode() {
098            return mStatus.hashCode();
099        }
100    }