1 16 package org.outerj.daisy.repository.commonimpl.user; 17 18 import java.util.Date ; 19 import java.util.GregorianCalendar ; 20 21 import org.outerj.daisy.repository.user.Role; 22 import org.outerj.daisy.repository.commonimpl.AuthenticatedUser; 23 import org.outerj.daisy.repository.RepositoryException; 24 import org.outerx.daisy.x10.RoleDocument; 25 26 33 public class RoleImpl implements Role { 34 private long id=-1; 35 private String name; 36 private String description; 37 private long lastModifier; 38 private Date lastModified; 39 private long updateCount = 0; 40 private AuthenticatedUser requestingUser; 41 private UserManagementStrategy userManagementStrategy; 42 private IntimateAccess intimateAccess = new IntimateAccess(); 43 private boolean readOnly = false; 44 private static final String READ_ONLY_MESSAGE = "This Role object is read-only."; 45 46 50 public RoleImpl(UserManagementStrategy userManagementStrategy, String roleName, AuthenticatedUser requestingUser) { 51 this.userManagementStrategy = userManagementStrategy; 52 name = roleName; 53 this.requestingUser = requestingUser; 54 } 55 56 public String getName() { 57 return name; 58 } 59 60 public void setName(String roleName) { 61 if (readOnly) 62 throw new RuntimeException (READ_ONLY_MESSAGE); 63 64 name = roleName; 65 } 66 67 public String getDescription() { 68 return description; 69 } 70 71 public void setDescription(String description) { 72 if (readOnly) 73 throw new RuntimeException (READ_ONLY_MESSAGE); 74 75 this.description = description; 76 } 77 78 public long getId() { 79 return id; 80 } 81 82 85 86 public void save() throws RepositoryException { 87 if (readOnly) 88 throw new RuntimeException (READ_ONLY_MESSAGE); 89 90 userManagementStrategy.store(this); 91 } 92 93 96 97 public RoleDocument getXml() { 98 RoleDocument roleDocument = RoleDocument.Factory.newInstance(); 99 RoleDocument.Role roleXml = roleDocument.addNewRole(); 100 101 roleXml.setDescription(description); 102 roleXml.setName(name); 103 roleXml.setUpdateCount(updateCount); 104 105 if (id!=-1) { 106 roleXml.setId(id); 107 GregorianCalendar lastModifiedCalendar = new GregorianCalendar (); 108 lastModifiedCalendar.setTime(lastModified); 109 110 roleXml.setLastModified(lastModifiedCalendar); 111 roleXml.setLastModifier(lastModifier); 112 } 113 return roleDocument; 114 } 115 116 122 public RoleImpl.IntimateAccess getIntimateAccess(UserManagementStrategy strategy) { 123 if (this.userManagementStrategy == strategy) 124 return intimateAccess; 125 else 126 return null; 127 } 128 129 public Date getLastModified() { 130 return lastModified; 131 } 132 133 public long getLastModifier() { 134 return lastModifier; 135 } 136 137 public long getUpdateCount() { 138 return updateCount; 139 } 140 141 144 public void makeReadOnly() { 145 this.readOnly = true; 146 } 147 148 public class IntimateAccess { 149 private IntimateAccess() { 150 } 151 152 public void setLastModified(Date lastModDate) { 153 if (readOnly) 154 throw new RuntimeException (READ_ONLY_MESSAGE); 155 156 lastModified = lastModDate; 157 } 158 public void setLastModifier(long lastMod) { 159 if (readOnly) 160 throw new RuntimeException (READ_ONLY_MESSAGE); 161 162 lastModifier = lastMod; 163 } 164 public AuthenticatedUser getCurrentUser() { 165 if (readOnly) 166 throw new RuntimeException (READ_ONLY_MESSAGE); 167 168 return requestingUser; 169 } 170 171 public void setId(long id) { 172 if (readOnly) 173 throw new RuntimeException (READ_ONLY_MESSAGE); 174 175 RoleImpl.this.id = id; 176 } 177 178 public void saved(long id, String roleName, String roleDescription, long updateCount) { 179 if (readOnly) 180 throw new RuntimeException (READ_ONLY_MESSAGE); 181 182 RoleImpl.this.id = id; 183 name = roleName; 184 description = roleDescription; 185 RoleImpl.this.updateCount = updateCount; 186 } 187 188 } 189 } 190 | Popular Tags |