1 package org.apache.beehive.controls.runtime.generator; 2 19 20 import java.util.HashMap ; 21 22 import com.sun.mirror.type.TypeMirror; 23 import com.sun.mirror.declaration.TypeParameterDeclaration; 24 25 29 public class EventAdaptor 30 { 31 34 public EventAdaptor(AptEventField eventField, AptEventSet eventSet) 35 { 36 _eventField = eventField; 37 _eventSet = eventSet; 38 _className = initClassName(); 39 } 40 41 44 private String initClassName() 45 { 46 StringBuffer sb = new StringBuffer (); 47 String fieldName = _eventField.getName(); 48 String setName = _eventSet.getClassName(); 49 sb.append(Character.toUpperCase(fieldName.charAt(0))); 50 if (fieldName.length() > 1) 51 sb.append(fieldName.substring(1)); 52 sb.append(setName.substring(setName.lastIndexOf('.') + 1)); 53 sb.append("EventAdaptor"); 54 return sb.toString(); 55 } 56 57 60 public String getClassName() 61 { 62 return _className; 63 } 64 65 69 public String getFormalClassName() 70 { 71 StringBuffer sb = new StringBuffer (_className); 72 sb.append(_eventSet.getFormalTypeParameters()); 73 return sb.toString(); 74 } 75 76 79 public AptEventField getEventField() { return _eventField; } 80 81 84 public AptEventSet getEventSet() { return _eventSet; } 85 86 89 public void addHandler(AptEvent event, AptMethod eventHandler) 90 { 91 assert event.getEventSet() == _eventSet; 92 _handlerMap.put(event, eventHandler); 93 } 94 95 98 public boolean hasHandler(AptEvent event) 99 { 100 return _handlerMap.containsKey(event); 101 } 102 103 106 public AptMethod getHandler(AptEvent event) 107 { 108 return _handlerMap.get(event); 109 } 110 111 116 public String getEventSetBinding() 117 { 118 HashMap <String ,TypeMirror> typeBinding = _eventField.getTypeBindingMap(); 120 121 StringBuffer sb = new StringBuffer (); 122 boolean isFirst = true; 123 for (TypeParameterDeclaration tpd : 124 _eventSet.getDeclaration().getFormalTypeParameters()) 125 { 126 if (isFirst) 127 { 128 sb.append("<"); 129 isFirst = false; 130 } 131 else 132 sb.append(", "); 133 134 String typeName = tpd.getSimpleName(); 138 if (typeBinding.containsKey(typeName)) 139 sb.append(typeBinding.get(tpd.getSimpleName())); 140 else 141 sb.append("java.lang.Object"); 142 } 143 if (!isFirst) 144 sb.append(">"); 145 146 return sb.toString(); 147 } 148 149 private String _className; 150 private AptEventField _eventField; 151 private AptEventSet _eventSet; 152 private HashMap <AptEvent, AptMethod> _handlerMap = new HashMap <AptEvent,AptMethod>(); 153 } 154 | Popular Tags |