001package com.nimbusds.openid.connect.sdk;
002
003
004import com.nimbusds.oauth2.sdk.ParseException;
005
006
007/**
008 * Enumeration of the subject identifier types.
009 *
010 * @author Vladimir Dzhuvinov
011 */
012public enum SubjectType {
013
014
015        /**
016         * Pairwise.
017         */
018        PAIRWISE,
019        
020        
021        /**
022         * Public.
023         */
024        PUBLIC;
025        
026        
027        /**
028         * Returns the string representation of this subject identifier 
029         * type.
030         *
031         * @return The string representation of this subject identifier
032         *         type.
033         */
034        public String toString() {
035
036                return super.toString().toLowerCase();
037        }
038
039
040        /**
041         * Parses a subject identifier type.
042         *
043         * @param s The string to parse.
044         *
045         * @return The subject identifier type.
046         *
047         * @throws ParseException If the parsed string is {@code null} or
048         *                        doesn't match a subject identifier type.
049         */
050        public static SubjectType parse(final String s)
051                throws ParseException {
052
053                if (s == null || s.trim().isEmpty())
054                        throw new ParseException("Null or empty subject type string");
055
056                if (s.equals("pairwise")) {
057
058                        return PAIRWISE;
059                
060                } else if (s.equals("public")) {
061
062                        return PUBLIC;
063                        
064                } else {
065
066                        throw new ParseException("Unknown subject type: " + s);
067                }
068        }
069}