001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.ksb.api.registry;
017    
018    import org.kuali.rice.core.api.mo.common.Coded;
019    import org.kuali.rice.core.api.util.jaxb.EnumStringAdapter;
020    
021    import javax.xml.bind.annotation.XmlEnum;
022    import javax.xml.bind.annotation.XmlEnumValue;
023    import javax.xml.bind.annotation.XmlRootElement;
024    import javax.xml.bind.annotation.XmlType;
025    
026    /**
027     * Defines the possible statuses for a service endpoint in the KSB registry.
028     * 
029     * @author Kuali Rice Team (rice.collab@kuali.org)
030     */
031    @XmlRootElement(name = "serviceEndpointStatus")
032    @XmlType(name = "ServiceEndpointStatusType")
033    @XmlEnum
034    public enum ServiceEndpointStatus implements Coded {
035    
036            /**
037             * Indicates the service is online and available to receieve requests.
038             */
039            @XmlEnumValue("A") ONLINE("A"),
040            
041            /**
042             * Indicates the service has been taken offline, most likely as the
043             * result of the instance hosting the service being taken offline
044             * (i.e. for maintenance or otherwise)
045             */
046            @XmlEnumValue("I") OFFLINE("I"),
047            
048            /**
049             * Indicates the service has been disabled because the registry has
050             * detected that it, or it's host instance is defective or not
051             * processing requests properly.
052             */
053            @XmlEnumValue("D") DISABLED("D");
054            
055            private final String code;
056            
057            ServiceEndpointStatus(final String code) {
058                    this.code = code;
059            }
060            
061            @Override
062            public String getCode() {
063                    return this.code;
064            }
065            
066            /**
067             * Returns the endpoint status for the given status code.  This method will
068             * return null if the given code value is null.
069             * 
070             * @param code the code for which to locate the {@link ServiceEndpointStatus}
071             * @return the {@link ServiceEndpointStatus} which has the given code, or null
072             * if the given code value was null
073             * @throws IllegalArgumentException if an endpoint status does not match the given code
074             */
075            public static ServiceEndpointStatus fromCode(String code) {
076                    if (code == null) {
077                            return null;
078                    }
079                    for (ServiceEndpointStatus status : values()) {
080                            if (status.code.equals(code)) {
081                                    return status;
082                            }
083                    }
084                    throw new IllegalArgumentException("Failed to locate the ServiceEndpointStatus with the given code: " + code);
085            }
086            
087            /**
088             * Adapts the ServiceEndpointStatus to and from a string during JAXB operations.
089             */
090            static final class Adapter extends EnumStringAdapter<ServiceEndpointStatus> {
091                    
092                    protected Class<ServiceEndpointStatus> getEnumClass() {
093                            return ServiceEndpointStatus.class;
094                    }
095                    
096            }
097            
098    }