1 16 package net.sf.dozer.util.mapping.fieldmap; 17 18 import java.util.ArrayList ; 19 import java.util.List ; 20 import java.util.StringTokenizer ; 21 22 import net.sf.dozer.util.mapping.MappingException; 23 24 30 public class Hint implements Cloneable { 31 32 private String hintName; 33 private List hints; 34 35 public Class getHint() { 36 if (getHints().size() > 1) { 37 return null; 38 } else { 39 return (Class ) getHints().get(0); 40 } 41 } 42 43 public Class getHint(Class myClaz, List clazHints) { 44 List hints = getHints(); 45 int hintsSize = hints.size(); 46 if (hintsSize == 1) { 47 return getHint(); 48 } 49 if (clazHints.size() != hintsSize) { 51 throw new MappingException( 52 "When using multiple source and destination hints there must be exactly the same number of hints on the source and the destination."); 53 } 54 int count = 0; 55 String myClazName = myClaz.getName(); 56 int size = clazHints.size(); 57 for (int i = 0; i < size; i++) { 58 Class element = (Class ) clazHints.get(i); 59 if (element.getName().equals(myClazName)) { 60 return (Class ) hints.get(count++); 61 } 62 count++; 63 } 64 return myClaz; 65 } 66 67 public boolean hasMoreThanOneHint() { 68 return getHints().size() > 1 ? true : false; 69 } 70 71 public List getHints() { 72 if (hints == null) { 73 List list = new ArrayList (); 74 try { 75 StringTokenizer st = new StringTokenizer (this.hintName, ","); 76 while (st.hasMoreElements()) { 77 String theHintName = (String ) st.nextToken().trim(); 78 79 Class clazz = Thread.currentThread().getContextClassLoader().loadClass(theHintName); 80 list.add(clazz); 81 } 82 } catch (ClassNotFoundException e) { 83 throw new MappingException(e); 84 } 85 hints = list; 86 } 87 return hints; 88 } 89 90 public String getHintName() { 91 return hintName; 92 } 93 94 public void setHintName(String sourceHintName) { 95 this.hintName = sourceHintName; 96 } 97 98 } 99 | Popular Tags |