1 7 package fr.jayasoft.ivy.event; 8 9 import java.util.HashMap ; 10 import java.util.Map ; 11 12 import fr.jayasoft.ivy.Ivy; 13 import fr.jayasoft.ivy.ModuleDescriptor; 14 import fr.jayasoft.ivy.ModuleId; 15 import fr.jayasoft.ivy.ModuleRevisionId; 16 import fr.jayasoft.ivy.util.StringUtils; 17 18 41 public class IvyEvent { 42 private Ivy _source; 43 private String _name; 44 private Map _attributes = new HashMap (); 45 46 protected IvyEvent(Ivy source, String name) { 47 _source = source; 48 _name = name; 49 } 50 51 56 protected void addAttribute(String key, String value) { 57 _attributes.put(key, value); 58 } 59 protected void addMDAttributes(ModuleDescriptor md) { 60 addMridAttributes(md.getResolvedModuleRevisionId()); 61 } 62 63 protected void addMridAttributes(ModuleRevisionId mrid) { 64 addModuleIdAttributes(mrid.getModuleId()); 65 addAttribute("revision", mrid.getRevision()); 66 addAttributes(mrid.getExtraAttributes()); 67 } 68 69 protected void addModuleIdAttributes(ModuleId moduleId) { 70 addAttribute("organisation", moduleId.getOrganisation()); 71 addAttribute("module", moduleId.getName()); 72 } 73 74 protected void addConfsAttribute(String [] confs) { 75 addAttribute("conf", StringUtils.join(confs, ", ")); 76 } 77 78 protected void addAttributes(Map attributes) { 79 _attributes.putAll(attributes); 80 } 81 82 83 public Ivy getSource() { 84 return _source; 85 } 86 87 public String getName() { 88 return _name; 89 } 90 91 95 public Map getAttributes() { 96 return new HashMap (_attributes); 97 } 98 99 public String toString() { 100 return getName()+" "+getAttributes(); 101 } 102 103 public boolean equals(Object obj) { 104 if (! (obj instanceof IvyEvent)) { 105 return false; 106 } 107 IvyEvent e = (IvyEvent) obj; 108 109 return getSource().equals(e.getSource()) 110 && getName().equals(e.getName()) 111 && _attributes.equals(e._attributes); 112 } 113 114 public int hashCode() { 115 int hash = 37; 116 hash = 13 * hash + getSource().hashCode(); 117 hash = 13 * hash + getName().hashCode(); 118 hash = 13 * hash + _attributes.hashCode(); 119 return hash; 120 } 121 } 122 | Popular Tags |