View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.api.registry;
17  
18  import org.kuali.rice.core.api.mo.common.Coded;
19  import org.kuali.rice.core.api.util.jaxb.EnumStringAdapter;
20  
21  import javax.xml.bind.annotation.XmlEnum;
22  import javax.xml.bind.annotation.XmlEnumValue;
23  import javax.xml.bind.annotation.XmlRootElement;
24  import javax.xml.bind.annotation.XmlType;
25  
26  /**
27   * Defines the possible statuses for a service endpoint in the KSB registry.
28   * 
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  @XmlRootElement(name = "serviceEndpointStatus")
32  @XmlType(name = "ServiceEndpointStatusType")
33  @XmlEnum
34  public enum ServiceEndpointStatus implements Coded {
35  
36  	/**
37  	 * Indicates the service is online and available to receieve requests.
38  	 */
39  	@XmlEnumValue("A") ONLINE("A"),
40  	
41  	/**
42  	 * Indicates the service has been taken offline, most likely as the
43  	 * result of the instance hosting the service being taken offline
44  	 * (i.e. for maintenance or otherwise)
45  	 */
46  	@XmlEnumValue("I") OFFLINE("I"),
47  	
48  	/**
49  	 * Indicates the service has been disabled because the registry has
50  	 * detected that it, or it's host instance is defective or not
51  	 * processing requests properly.
52  	 */
53  	@XmlEnumValue("D") DISABLED("D");
54  	
55  	private final String code;
56  	
57  	ServiceEndpointStatus(final String code) {
58  		this.code = code;
59  	}
60  	
61  	@Override
62  	public String getCode() {
63  		return this.code;
64  	}
65  	
66  	/**
67  	 * Returns the endpoint status for the given status code.  This method will
68  	 * return null if the given code value is null.
69  	 * 
70  	 * @param code the code for which to locate the {@link ServiceEndpointStatus}
71  	 * @return the {@link ServiceEndpointStatus} which has the given code, or null
72  	 * if the given code value was null
73  	 * @throws IllegalArgumentException if an endpoint status does not match the given code
74  	 */
75  	public static ServiceEndpointStatus fromCode(String code) {
76  		if (code == null) {
77  			return null;
78  		}
79  		for (ServiceEndpointStatus status : values()) {
80  			if (status.code.equals(code)) {
81  				return status;
82  			}
83  		}
84  		throw new IllegalArgumentException("Failed to locate the ServiceEndpointStatus with the given code: " + code);
85  	}
86  	
87  	/**
88  	 * Adapts the ServiceEndpointStatus to and from a string during JAXB operations.
89  	 */
90  	static final class Adapter extends EnumStringAdapter<ServiceEndpointStatus> {
91  		
92  		protected Class<ServiceEndpointStatus> getEnumClass() {
93  			return ServiceEndpointStatus.class;
94  		}
95  		
96  	}
97  	
98  }