1 4 package com.nightlabs.ipanema.transfer; 5 6 import java.io.Serializable ; 7 import java.util.Date ; 8 9 import com.nightlabs.ipanema.security.User; 10 11 21 public abstract class Transfer 22 implements Serializable 23 { 24 28 private String organisationID; 29 30 34 private String transferTypeID; 35 36 39 private long transferID; 40 41 private Transfer container; 42 43 private Anchor from; 44 private Anchor to; 45 46 public User initiator; 47 private Date timestamp; 48 49 protected Transfer() { } 50 51 60 public Transfer(TransferRegistry transferRegistry, String transferTypeID, Transfer container, User initiator, Anchor from, Anchor to) 61 { 62 this.organisationID = transferRegistry.getOrganisationID(); 63 this.transferTypeID = transferTypeID; 64 this.transferID = transferRegistry.createTransferID(this.organisationID, transferTypeID); 65 this.container = container; 66 if (initiator == null) 67 throw new NullPointerException ("initiator must not be null! Someone must be responsible!"); 68 this.initiator = initiator; 69 if (from == null) 70 throw new NullPointerException ("from must not be null! Nothing can come out of nirvana!"); 71 this.from = from; 72 if (to == null) 73 throw new NullPointerException ("to must not be null! Even nirvana must be known as Anchor!"); 74 this.to = to; 75 this.timestamp = new Date (); 76 transferRegistry.addTransfer(this); 77 } 78 79 public static String getPrimaryKey(String organisationID, String transferTypeID, long transferID) 80 { 81 return organisationID + '/' + transferTypeID + '/' + Long.toHexString(transferID); 82 } 83 84 public String getPrimaryKey() 85 { 86 return getPrimaryKey(organisationID, transferTypeID, transferID); 87 } 88 89 92 public String getOrganisationID() 93 { 94 return organisationID; 95 } 96 97 100 public long getTransferID() 101 { 102 return transferID; 103 } 104 105 114 public Transfer getContainer() 115 { 116 return container; 117 } 118 119 124 public User getInitiator() 125 { 126 return initiator; 127 } 128 131 public Anchor getFrom() 132 { 133 return from; 134 } 135 138 public Anchor getTo() 139 { 140 return to; 141 } 142 143 public static final int ANCHORTYPE_UNKNOWN = 0; 144 public static final int ANCHORTYPE_FROM = 1; 145 public static final int ANCHORTYPE_TO = 2; 146 public int getAnchorType(Anchor anchor) 147 { 148 if (anchor == null) 149 throw new NullPointerException ("anchor must not be null!"); 150 151 if (from.getPrimaryKey().equals(anchor.getPrimaryKey())) 152 return ANCHORTYPE_FROM; 153 154 if (to.getPrimaryKey().equals(anchor.getPrimaryKey())) 155 return ANCHORTYPE_TO; 156 157 return ANCHORTYPE_UNKNOWN; 158 } 159 160 165 public Date getTimestamp() 166 { 167 return timestamp; 168 } 169 170 } 171 | Popular Tags |