001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.core.bo.user;
017:
018: import java.io.Serializable;
019:
020: /**
021: * This class is to hold our users network ids and wrap them in a strongly typed object
022: *
023: *
024: */
025: public final class AuthenticationUserId implements UserId, Serializable {
026: private static final long serialVersionUID = 2540727071768501528L;
027:
028: public static final AuthenticationUserId NOT_FOUND = new AuthenticationUserId(
029: "not found");
030:
031: private String authenticationId;
032:
033: /**
034: * Constructor that takes in a string authenticationId
035: *
036: * @param authenticationId
037: */
038: public AuthenticationUserId(String authenticationId) {
039: setAuthenticationId(authenticationId);
040: }
041:
042: /**
043: * Empty constructor, available to support standard bean activity
044: *
045: */
046: public AuthenticationUserId() {
047: }
048:
049: /**
050: * getter which returns the string authenticationId
051: *
052: * @return
053: */
054: public String getAuthenticationId() {
055: return authenticationId;
056: }
057:
058: /**
059: * setter which takes the string authenticationId
060: *
061: * @param authenticationId
062: */
063: public void setAuthenticationId(String authenticationId) {
064: this .authenticationId = (authenticationId == null ? null
065: : authenticationId.trim());
066: }
067:
068: /**
069: * Returns true if this userId has an empty value. Empty userIds can't be used as keys in a Hash, among other things.
070: *
071: * @return true if this instance doesn't have a value
072: */
073: public boolean isEmpty() {
074: return (authenticationId == null || authenticationId.trim()
075: .length() == 0);
076: }
077:
078: /**
079: * override equals so that we can compare authenticationIds If you make this class non-final, you must rewrite equals to work
080: * for subclasses.
081: */
082: public boolean equals(Object obj) {
083: boolean isEqual = false;
084:
085: if (obj != null && (obj instanceof AuthenticationUserId)) {
086: AuthenticationUserId a = (AuthenticationUserId) obj;
087:
088: if (getAuthenticationId() == null) {
089: return false;
090: }
091:
092: return authenticationId.equals(a.authenticationId);
093: }
094:
095: return false;
096: }
097:
098: /**
099: * override hashCode because we overrode equals
100: */
101: public int hashCode() {
102: return authenticationId == null ? 0 : authenticationId
103: .hashCode();
104: }
105:
106: /**
107: * override toString so that it prints out the authenticationId String
108: */
109: public String toString() {
110: return authenticationId;
111: }
112: }
|