001 /**
002 * Copyright 2005-2014 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.api.identity;
017
018 import org.kuali.rice.kew.api.user.UserId;
019
020 /**
021 * The primary ID of a Principal in KIM
022 *
023 * @author Kuali Rice Team (rice.collab@kuali.org)
024 *
025 */
026 public class PrincipalId implements UserId {
027 private static final long serialVersionUID = -5551723348738932404L;
028
029 private String principalId;
030
031 public PrincipalId() { }
032
033 public PrincipalId(String principalId) {
034 setPrincipalId(principalId);
035 }
036
037 public String getPrincipalId() {
038 return this.principalId;
039 }
040
041 public void setPrincipalId(String principalId) {
042 this.principalId = (principalId == null ? null : principalId.trim());
043 }
044
045 @Override
046 public String getId() {
047 return getPrincipalId();
048 }
049
050
051 /**
052 * Returns true if this userId has an empty value. Empty userIds can't be used as keys in a Hash, among other things.
053 *
054 * @return true if this instance doesn't have a value
055 */
056 @Override
057 public boolean isEmpty() {
058 return (principalId == null || principalId.trim().length() == 0);
059 }
060
061 /**
062 * If you make this class non-final, you must rewrite equals to work for subclasses.
063 */
064 public boolean equals(Object obj) {
065 if (obj != null && (obj instanceof PrincipalId)) {
066 PrincipalId w = (PrincipalId) obj;
067
068 if (getPrincipalId() == null) {
069 return false;
070 }
071 return principalId.equals(w.getPrincipalId());
072 }
073
074 return false;
075 }
076
077 public int hashCode() {
078 return principalId == null ? 0 : principalId.hashCode();
079 }
080
081 public String toString() {
082 if (principalId == null) {
083 return "principalId: null";
084 }
085 return "principalId: " + principalId;
086 }
087
088 }