1 4 package com.nightlabs.ipanema.transfer; 5 6 import java.io.Serializable ; 7 import java.util.HashMap ; 8 import java.util.Map ; 9 10 import javax.jdo.JDOHelper; 11 12 28 public abstract class Anchor 29 implements Serializable 30 { 31 35 private String organisationID; 36 37 41 private String anchorID; 42 43 58 protected Map transfers = new HashMap (); 59 60 protected Anchor() { } 61 62 public Anchor(String organisationID, String anchorID) 63 { 64 this.organisationID = organisationID; 65 this.anchorID = anchorID; 66 } 67 68 public static String getPrimaryKey(String organisationID, String anchorID) 69 { 70 return organisationID + '/' + anchorID; 71 } 72 73 public String getPrimaryKey() 74 { 75 return getPrimaryKey(organisationID, anchorID); 76 } 77 78 81 public String getOrganisationID() 82 { 83 return organisationID; 84 } 85 88 public String getAnchorID() 89 { 90 return anchorID; 91 } 92 93 99 public void bookTransfer(Transfer transfer) 100 { 101 if (transfer == null) 102 throw new NullPointerException ("transfer must not be null!"); 103 104 if (!JDOHelper.isPersistent(this)) 105 throw new IllegalStateException ("This instance of Anchor is not persistent. Non persistent instances can not book transfers!!"); 106 107 String pk = transfer.getPrimaryKey(); 108 if (transfers.containsKey(pk)) 109 throw new DuplicateTransferException("Transfer \""+pk+"\" has already been booked!"); 110 111 if (transfer.getAnchorType(this) == Transfer.ANCHORTYPE_UNKNOWN) 112 throw new AnchorMismatchException("This Anchor \""+this.getPrimaryKey()+"\" is not a side of the transfer \""+transfer.getPrimaryKey()+"\"!"); 113 114 internalBookTransfer(transfer); 115 116 transfers.put(pk,transfer); 117 } 118 119 protected abstract void internalBookTransfer(Transfer transfer); 120 } 121 | Popular Tags |