1 package org.apache.beehive.controls.runtime.generator; 2 19 20 import java.util.Collection ; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 24 import com.sun.mirror.declaration.FieldDeclaration; 25 import com.sun.mirror.declaration.TypeDeclaration; 26 import com.sun.mirror.declaration.TypeParameterDeclaration; 27 import com.sun.mirror.type.DeclaredType; 28 import com.sun.mirror.type.ReferenceType; 29 import com.sun.mirror.type.TypeMirror; 30 31 34 abstract public class AptEventField extends AptField 35 { 36 public AptEventField(FieldDeclaration fieldDecl) 37 { 38 super(fieldDecl); 39 } 40 41 46 abstract protected AptControlInterface initControlInterface(); 47 48 52 private void initTypeParameterBindings() 53 { 54 DeclaredType fieldType = (DeclaredType)_fieldDecl.getType(); 59 Iterator <TypeMirror> paramBoundIter = fieldType.getActualTypeArguments().iterator(); 60 61 TypeDeclaration intfDecl = (TypeDeclaration)_controlIntf.getTypeDeclaration(); 62 Iterator <TypeParameterDeclaration> paramDeclIter = 63 intfDecl.getFormalTypeParameters().iterator(); 64 65 StringBuffer sb = new StringBuffer (); 74 boolean isFirst = true; 75 while (paramBoundIter.hasNext()) 76 { 77 TypeMirror paramBound = paramBoundIter.next(); 78 TypeParameterDeclaration paramDecl = paramDeclIter.next(); 79 80 _typeBindingMap.put(paramDecl.getSimpleName(), paramBound); 84 85 if (isFirst) 86 { 87 sb.append("<"); 88 isFirst = false; 89 } 90 else 91 sb.append(", "); 92 sb.append(paramBound); 93 } 94 if (!isFirst) 95 sb.append(">"); 96 97 _boundParameterDecl = sb.toString(); 98 } 99 100 103 public AptControlInterface getControlInterface() 104 { 105 if (_controlIntf == null) 106 { 107 _controlIntf = initControlInterface(); 108 if (_controlIntf != null) 109 initTypeParameterBindings(); 110 } 111 return _controlIntf; 112 } 113 114 117 public EventAdaptor getEventAdaptor(AptEventSet eventSet) 118 { 119 return _eventAdaptors.get(eventSet); 120 } 121 122 125 public void addEventAdaptor(AptEventSet eventSet, EventAdaptor eventAdaptor) 126 { 127 assert !_eventAdaptors.containsKey(eventSet); 128 _eventAdaptors.put(eventSet, eventAdaptor); 129 } 130 131 134 public Collection <EventAdaptor> getEventAdaptors() 135 { 136 return _eventAdaptors.values(); 137 } 138 139 142 public String getBoundParameters() 143 { 144 return _boundParameterDecl; 145 } 146 147 150 public HashMap <String , TypeMirror> getTypeBindingMap() 151 { 152 return _typeBindingMap; 153 } 154 155 HashMap <AptEventSet, EventAdaptor> _eventAdaptors = 156 new HashMap <AptEventSet, EventAdaptor>(); 157 158 String _boundParameterDecl; 159 HashMap <String ,TypeMirror> _typeBindingMap = new HashMap <String ,TypeMirror>(); 160 private AptControlInterface _controlIntf; 161 } 162 | Popular Tags |