001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/trunk/sakai/admin-tools/su/src/java/org/sakaiproject/tool/su/SuTool.java $
003: * $Id: SuTool.java 5970 2006-02-15 03:07:19Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.authz.impl;
021:
022: import org.sakaiproject.authz.api.Member;
023: import org.sakaiproject.authz.api.Role;
024: import org.sakaiproject.user.api.User;
025: import org.sakaiproject.user.api.UserNotDefinedException;
026: import org.sakaiproject.user.cover.UserDirectoryService;
027:
028: /**
029: * <p>
030: * BaseMember is an implementation of the AuthzGroup API Member.
031: * </p>
032: */
033: public class BaseMember implements Member {
034: /** A fixed class serian number. */
035: private static final long serialVersionUID = 1L;
036:
037: protected Role role = null;
038:
039: protected boolean provided = false;
040:
041: protected boolean active = true;
042:
043: protected String userId = null;
044:
045: public BaseMember(Role role, boolean active, boolean provided,
046: String userId) {
047: this .role = role;
048: this .active = active;
049: this .provided = provided;
050: this .userId = userId;
051: }
052:
053: /**
054: * {@inheritDoc}
055: */
056: public Role getRole() {
057: return role;
058: }
059:
060: /**
061: * {@inheritDoc}
062: */
063: public String getUserId() {
064: return userId;
065: }
066:
067: /**
068: * @inheritDoc
069: */
070: public String getUserEid() {
071: try {
072: return UserDirectoryService.getUserEid(userId);
073: } catch (UserNotDefinedException e) {
074: return userId;
075: }
076: }
077:
078: /**
079: * @inheritDoc
080: */
081: public String getUserDisplayId() {
082: try {
083: User user = UserDirectoryService.getUser(userId);
084: return user.getDisplayId();
085: } catch (UserNotDefinedException e) {
086: return userId;
087: }
088: }
089:
090: /**
091: * {@inheritDoc}
092: */
093: public boolean isProvided() {
094: return provided;
095: }
096:
097: /**
098: * {@inheritDoc}
099: */
100: public boolean isActive() {
101: return active;
102: }
103:
104: /**
105: * {@inheritDoc}
106: */
107: public void setActive(boolean active) {
108: this .active = active;
109: }
110:
111: /**
112: * {@inheritDoc}
113: */
114: public int compareTo(Object obj) {
115: if (!(obj instanceof Member))
116: throw new ClassCastException();
117:
118: // if the object are the same, say so
119: if (obj == this )
120: return 0;
121:
122: // compare by comparing the user id
123: int compare = getUserId().compareTo(((Member) obj).getUserId());
124:
125: return compare;
126: }
127: }
|