1 24 39 40 package org.datashare; 41 42 import org.datashare.objects.DataShareConnectionDescriptor; 43 import org.datashare.objects.DefaultObjectInfo; 44 import org.datashare.objects.RegistrationInfo; 45 import java.util.Date ; 46 import java.net.InetAddress ; 47 48 49 56 public class ClientInfo extends DefaultObjectInfo implements PersistDataCallbackInterface 57 { 58 61 protected String clientKey = null; 62 63 66 protected InetAddress hostMachine; 67 68 71 protected DataShareConnectionDescriptor clientCommandStatusConnectionDescriptor = null; 72 73 76 protected UserInfo userInfo = null; 77 78 81 protected boolean admin = false; 82 83 86 protected boolean seeAllTreeObjects = false; 87 88 91 protected int clientMode; 92 93 96 boolean saveData = false; 97 98 101 String userSuppliedInfo = ""; 102 103 107 private ClientInfo() 108 { 109 originalType = CLIENTTYPE; 110 } 111 112 116 public ClientInfo(DataShareConnectionDescriptor commandStatusConnectionDescriptor, 117 UserInfo userInfo, 118 boolean saveData) 119 { 120 this(); name = userInfo.getUserName(); 122 clientKey = userInfo.uniqueName; 123 clientCommandStatusConnectionDescriptor = commandStatusConnectionDescriptor; 124 this.userInfo = userInfo; 125 this.admin = userInfo.admin; 126 this.saveData = saveData; 127 this.clientMode = userInfo.getClientMode(); 128 this.userSuppliedInfo = userInfo.getOtherInfo(); 129 hostMachine = commandStatusConnectionDescriptor.clientIP; 130 this.clientClass = userInfo.getClientClass(); 131 toString = clientKey; 132 if(userInfo != null) 133 { 134 try{ 135 clientRealName = userInfo.firstName + " " + userInfo.lastName; 136 imageURL = userInfo.imageURL; 137 } 138 catch(Exception e) 139 { 140 e.printStackTrace(); 141 } 142 } 143 } 144 145 148 public void 149 updateCommandStatusConnectionDescriptor(DataShareConnectionDescriptor newDescriptor) 150 { 151 clientCommandStatusConnectionDescriptor = newDescriptor; 152 hostMachine = clientCommandStatusConnectionDescriptor.clientIP; 153 } 154 155 160 public InetAddress 161 getHostMachine() 162 { 163 return hostMachine; 164 } 165 166 171 public String 172 getType() 173 { 174 return CLIENTTYPE; 175 } 176 177 182 public String 183 getInfo() 184 { 185 if(this.infoString == null) 186 { 187 String adminString = ""; 189 String userInfoString = ""; 190 String realName = ""; 191 if(!clientRealName.equals(" ")) realName = clientRealName; 193 194 if(admin) 195 adminString = "<tr><td>Privileges</td><td>This client has admin privileges</td></tr>"; 196 if(userInfo != null) 197 { 198 try{ 199 userInfoString = 200 ((!userInfo.primaryEmail.equals("")) ? "<tr><td>Email address</td><td>" + userInfo.primaryEmail + "</td></tr>" : "" ) + 201 ((!userInfo.primaryPhone.equals("")) ? "<tr><td>Phone</td><td>" + userInfo.primaryPhone + "</td></tr>" : ""); 202 } 203 catch(Exception e) 204 { 205 e.printStackTrace(); 206 } 207 } 208 else 209 { 210 if(this.saveData) userInfoString = "<tr><td colspan=2>This client has no account on this server</td></tr>"; 212 } 213 214 215 infoString = ""; 216 if (realName.trim().length() >0 )infoString = "<tr><td>Real name</td><td>"+realName +"</td></tr>"; 217 218 infoString += userInfoString + 219 "<tr><td>User's Name</td><td>" + this.name + "</td></tr>" + 220 "<tr><td>Unique Name</td><td>" + this.clientKey + "</td></tr>" + 221 "<tr><td>Client's IP address</td><td>" + hostMachine.getHostAddress() + " (server perspective)</td></tr>" + 222 "<tr><td>Client's Machine</td><td>" + hostMachine.getHostName() + " (server perspective)</td></tr>" + 223 "<tr><td>Connected</td><td>" + this.getDate().toString() + "</td></tr>" + 225 "<tr><td>Running mode</td><td>" + RegistrationInfo.clientModes[clientMode] + "</td></tr>" + 226 adminString + userSuppliedInfo; 227 } 228 return infoString; 229 } 230 231 238 public String 239 getKeyValue() 240 { 241 return clientKey; } 243 244 public boolean 245 getSeeAllTreeObjects() 246 { 247 return this.seeAllTreeObjects; 248 } 249 250 public void 251 setSeeAllTreeObjects(boolean seeAllTreeObjects) 252 { 253 this.seeAllTreeObjects = seeAllTreeObjects; 254 } 255 256 262 public void 263 setDatabaseID(String ak) 264 { 265 SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG, 266 SessionUtilities.getLoggingInterface().DATABASE, 267 "setDatabaseID(): Table Key for " + this.getKeyValue() + " has value of " + ak); 268 databaseID = ak; 269 waitingForKey = false; 270 keyHasBeenReturned = true; 271 } 272 273 279 public String 280 getDatabaseID() 281 { 282 String thisKey = null; 283 if(saveData) 284 { 285 if(databaseID != null) 286 thisKey = databaseID; 287 else 288 thisKey = retrieveEJB(); 289 } 290 return thisKey; 291 } 292 293 296 public boolean 297 getAdmin() 298 { 299 return this.admin; 300 } 301 302 303 } 304 | Popular Tags |