View Javadoc
1   /**
2    * Copyright 2005-2015 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.api.identity;
17  
18  import org.kuali.rice.kew.api.user.UserId;
19  
20  /**
21   * The primary ID of a Principal in KIM
22   * 
23   * @author Kuali Rice Team (rice.collab@kuali.org)
24   *
25   */
26  public class PrincipalId implements UserId {
27      private static final long serialVersionUID = -5551723348738932404L;
28  
29      private String principalId;
30  
31  	public PrincipalId() { }
32  
33  	public PrincipalId(String principalId) {
34  		setPrincipalId(principalId);
35  	}
36  	
37  	public String getPrincipalId() {
38  		return this.principalId;
39  	}
40  	
41  	public void setPrincipalId(String principalId) {
42  		this.principalId = (principalId == null ? null : principalId.trim());
43  	}
44  
45      @Override
46      public String getId() {
47          return getPrincipalId();
48      }
49  
50  
51      /**
52       * Returns true if this userId has an empty value. Empty userIds can't be used as keys in a Hash, among other things.
53       *
54       * @return true if this instance doesn't have a value
55       */
56      @Override
57      public boolean isEmpty() {
58      	return (principalId == null || principalId.trim().length() == 0);
59      }
60  
61      /**
62       * If you make this class non-final, you must rewrite equals to work for subclasses.
63       */
64      public boolean equals(Object obj) {
65          if (obj != null && (obj instanceof PrincipalId)) {
66              PrincipalId w = (PrincipalId) obj;
67  
68              if (getPrincipalId() == null) {
69                  return false;
70              }
71              return principalId.equals(w.getPrincipalId());
72          }
73  
74          return false;
75      }
76  
77      public int hashCode() {
78          return principalId == null ? 0 : principalId.hashCode();
79      }
80  
81      public String toString() {
82          if (principalId == null) {
83              return "principalId: null";
84          }
85          return "principalId: " + principalId;
86      }
87  
88  }