1 package net.sourceforge.rpgee.messaging.network; 2 3 import net.sourceforge.rpgee.Categorized; 4 import net.sourceforge.rpgee.Named; 5 import net.sourceforge.rpgee.utility.BaseIdentified; 6 7 /** 8 * This class allows us to pass in ip, name, and various other data and get a Cookie that has all of that and a unique number as 9 * well. 10 * 11 * @author Mykel 12 * 13 * @param <G> 14 */ 15 public class CookieFactory<G> extends BaseIdentified implements Categorized<String>, Named { 16 private IdentifierFactory idFactory; 17 private String name = null; 18 19 public CookieFactory(IdentifierFactory _fact) { 20 if (_fact == null) 21 throw new RuntimeException("Identity factory is null!"); 22 idFactory = _fact; 23 } 24 public final Cookie<G> getCookie(String _ip, String _name, G _addl) { 25 return new CookieImpl(idFactory.getIdentifier(), _ip, _name, _addl); 26 } 27 28 public String getCategory() { 29 return this.getClass().getCanonicalName(); 30 } 31 32 public String getDescription() { 33 G type = null; 34 return this.getClass().getCanonicalName() + "<" + type.getClass().getCanonicalName() + ">"; 35 } 36 37 public String getName() { 38 if (name != null) 39 return name; 40 return this.getCategory() + "." + this.getId(); 41 } 42 43 public void setName(String name) { 44 this.name = name; 45 } 46 47 private class CookieImpl implements Cookie<G> { 48 private G additionalData; 49 private String ip; 50 private Long id; 51 private String name; 52 53 public CookieImpl(Long _idx, String _ip, String _name, G _addl) { 54 ip = _ip; 55 name = _name; 56 id = _idx; 57 additionalData = _addl; 58 } 59 60 public Long getId() { 61 return id; 62 } 63 64 public String getIdAsString() { 65 return id + ""; 66 } 67 68 public String getIp() { 69 return ip; 70 } 71 72 public String getName() { 73 return name; 74 } 75 76 public G getAdditionalData() { 77 return additionalData; 78 } 79 80 } 81 82 }