001    /**
002     * Copyright 2005-2013 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.core.api.membership;
017    
018    import org.kuali.rice.core.api.mo.common.Coded;
019    
020    import javax.xml.bind.annotation.XmlEnum;
021    import javax.xml.bind.annotation.XmlEnumValue;
022    import javax.xml.bind.annotation.XmlRootElement;
023    import javax.xml.bind.annotation.XmlType;
024    
025    /**
026     * A MemberType is an enum that represents valid membership type for Role, Group, and Delegate members.
027     * This enum is currently slightly overloaded, as only PRINCIPAL and GROUP are valid Group membership types.
028     * @see org.kuali.rice.kim.impl.membership.AbstractMemberBo
029     * @see org.kuali.rice.kim.impl.group.GroupMemberBo
030     * @see org.kuali.rice.kim.impl.role.RoleMemberBo
031     * @see org.kuali.rice.kim.impl.common.delegate.DelegateMemberBo
032     */
033    @XmlRootElement(name = "memberType")
034    @XmlType(name = "MemberTypeType")
035    @XmlEnum
036    public enum MemberType implements Coded {
037    
038        /**
039         * Member type corresponding to KIM roles
040         */
041        @XmlEnumValue("R") ROLE("R"),
042    
043        /**
044         * Member type corresponding to KIM groups
045         */
046        @XmlEnumValue("G") GROUP("G"),
047    
048        /**
049         * Member type corresponding to KIM principals
050         */
051        @XmlEnumValue("P") PRINCIPAL("P");
052    
053        public final String code;
054    
055        private MemberType(String code) {
056            this.code = code;
057        }
058    
059        @Override
060        public String getCode() {
061            return this.code;
062        }
063    
064        public static MemberType fromCode(String code) {
065            if (code == null) {
066                return null;
067            }
068            for (MemberType memberType : values()) {
069                if (memberType.code.equals(code)) {
070                    return memberType;
071                }
072            }
073            throw new IllegalArgumentException("Failed to locate the MemberType with the given code: " + code);
074        }
075    
076    }