View Javadoc
1   /**
2    * Copyright 2005-2014 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.kew.rule;
17  
18  /**
19   * Helper class that encapsulates a qualified rolename, and can encode and decode to String representation.
20   * 
21   * @author Kuali Rice Team (rice.collab@kuali.org)
22   */
23  public class QualifiedRoleName {
24      private final String baseRoleName;
25      private final String qualifier;
26  
27      public QualifiedRoleName(String baseRoleName) {
28          this(baseRoleName, null);
29      }
30      public QualifiedRoleName(String baseRoleName, String qualifier) {
31          this.baseRoleName = baseRoleName;
32          this.qualifier = qualifier;
33      }
34      public String getBaseRoleName() {
35          return baseRoleName;
36      }
37      public String getQualifier() {
38          return qualifier;
39      }
40      public String encode() {
41          if (qualifier == null) {
42              return baseRoleName;
43          } else {
44              return baseRoleName + '\0' + qualifier;
45          }
46      }
47  
48      public static QualifiedRoleName parse(String qualifiedRoleName) {
49          String[] parts = qualifiedRoleName.split("\0", 2);
50          return new QualifiedRoleName(parts[0], parts.length > 1 ? parts[1] : null);
51      }
52  
53      public String toString() {
54          return "[QualifiedRoleName: baseRoleName=" + baseRoleName +
55                                   ", qualifier=" + qualifier + "]";
56      }
57  }