View Javadoc

1   package org.kuali.rice.ksb.api.registry;
2   
3   import org.kuali.rice.core.api.mo.common.Coded;
4   import org.kuali.rice.core.api.util.jaxb.EnumStringAdapter;
5   
6   import javax.xml.bind.annotation.XmlEnum;
7   import javax.xml.bind.annotation.XmlEnumValue;
8   import javax.xml.bind.annotation.XmlRootElement;
9   import javax.xml.bind.annotation.XmlType;
10  
11  /**
12   * Defines the possible statuses for a service endpoint in the KSB registry.
13   * 
14   * @author Kuali Rice Team (rice.collab@kuali.org)
15   */
16  @XmlRootElement(name = "serviceEndpointStatus")
17  @XmlType(name = "ServiceEndpointStatusType")
18  @XmlEnum
19  public enum ServiceEndpointStatus implements Coded {
20  
21  	/**
22  	 * Indicates the service is online and available to receieve requests.
23  	 */
24  	@XmlEnumValue("A") ONLINE("A"),
25  	
26  	/**
27  	 * Indicates the service has been taken offline, most likely as the
28  	 * result of the instance hosting the service being taken offline
29  	 * (i.e. for maintenance or otherwise)
30  	 */
31  	@XmlEnumValue("I") OFFLINE("I"),
32  	
33  	/**
34  	 * Indicates the service has been disabled because the registry has
35  	 * detected that it, or it's host instance is defective or not
36  	 * processing requests properly.
37  	 */
38  	@XmlEnumValue("D") DISABLED("D");
39  	
40  	private final String code;
41  	
42  	ServiceEndpointStatus(final String code) {
43  		this.code = code;
44  	}
45  	
46  	@Override
47  	public String getCode() {
48  		return this.code;
49  	}
50  	
51  	/**
52  	 * Returns the endpoint status for the given status code.  This method will
53  	 * return null if the given code value is null.
54  	 * 
55  	 * @param code the code for which to locate the {@link ServiceEndpointStatus}
56  	 * @return the {@link ServiceEndpointStatus} which has the given code, or null
57  	 * if the given code value was null
58  	 * @throws IllegalArgumentException if an endpoint status does not match the given code
59  	 */
60  	public static ServiceEndpointStatus fromCode(String code) {
61  		if (code == null) {
62  			return null;
63  		}
64  		for (ServiceEndpointStatus status : values()) {
65  			if (status.code.equals(code)) {
66  				return status;
67  			}
68  		}
69  		throw new IllegalArgumentException("Failed to locate the ServiceEndpointStatus with the given code: " + code);
70  	}
71  	
72  	/**
73  	 * Adapts the ServiceEndpointStatus to and from a string during JAXB operations.
74  	 */
75  	static final class Adapter extends EnumStringAdapter<ServiceEndpointStatus> {
76  		
77  		protected Class<ServiceEndpointStatus> getEnumClass() {
78  			return ServiceEndpointStatus.class;
79  		}
80  		
81  	}
82  	
83  }