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.kew.rule;
017    
018    /**
019     * Helper class that encapsulates a qualified rolename, and can encode and decode to String representation.
020     * 
021     * @author Kuali Rice Team (rice.collab@kuali.org)
022     */
023    public class QualifiedRoleName {
024        private final String baseRoleName;
025        private final String qualifier;
026    
027        public QualifiedRoleName(String baseRoleName) {
028            this(baseRoleName, null);
029        }
030        public QualifiedRoleName(String baseRoleName, String qualifier) {
031            this.baseRoleName = baseRoleName;
032            this.qualifier = qualifier;
033        }
034        public String getBaseRoleName() {
035            return baseRoleName;
036        }
037        public String getQualifier() {
038            return qualifier;
039        }
040        public String encode() {
041            if (qualifier == null) {
042                return baseRoleName;
043            } else {
044                return baseRoleName + '\0' + qualifier;
045            }
046        }
047    
048        public static QualifiedRoleName parse(String qualifiedRoleName) {
049            String[] parts = qualifiedRoleName.split("\0", 2);
050            return new QualifiedRoleName(parts[0], parts.length > 1 ? parts[1] : null);
051        }
052    
053        public String toString() {
054            return "[QualifiedRoleName: baseRoleName=" + baseRoleName +
055                                     ", qualifier=" + qualifier + "]";
056        }
057    }