1 28 29 package com.idaremedia.antx.feedback; 30 31 import java.util.Iterator ; 32 import java.util.Map ; 33 34 import org.apache.tools.ant.Project; 35 import org.apache.tools.ant.types.PropertySet; 36 import org.apache.tools.ant.types.Reference; 37 38 import com.idaremedia.antx.AntX; 39 import com.idaremedia.antx.AssertableProjectComponent; 40 import com.idaremedia.antx.ErrorSnapshot; 41 import com.idaremedia.antx.FixtureExaminer; 42 import com.idaremedia.antx.helpers.Strings; 43 import com.idaremedia.antx.parameters.FlexValueSupport; 44 import com.idaremedia.antx.print.DiagnosticsValue; 45 46 64 65 public class EmitInclude extends AssertableProjectComponent implements FlexValueSupport 66 { 67 70 public EmitInclude() 71 { 72 super(AntX.feedback+"include"); 73 } 74 75 78 protected final void setKey(String key) 79 { 80 m_itemName = key; 81 } 82 83 84 88 public final String getKey() 89 { 90 return m_itemName; 91 } 92 93 94 97 public void setProperty(String property) 98 { 99 require_(property!=null,"setProp- nonzro name"); 100 m_xstring.set(property); 101 m_xstring.setIsProperty(true); 102 setKey(property); 103 } 104 105 106 109 public void setReference(String refId) 110 { 111 require_(refId!=null,"setRefId- nonzro name"); 112 m_xstring.set(refId); 113 m_xstring.setIsReference(true); 114 setKey(refId); 115 } 116 117 118 121 public void setVariable(String variable) 122 { 123 require_(variable!=null,"setVar- nonzro name"); 124 m_xstring.set(variable); 125 m_xstring.setIsExported(true); 126 setKey(variable); 127 } 128 129 130 133 public final void setVar(String variable) 134 { 135 setVariable(variable); 136 } 137 138 139 144 public void setPropertySet(Reference r) 145 { 146 require_(r!=null,"setPropSet- nonzro ref"); 147 require_(r.getRefId()!=null,"setPropSet- nonzro refid"); 148 setKey(r.getRefId()); 149 m_Is = IS_PSET; } 151 152 153 156 public void setTaskdef(String taskName) 157 { 158 require_(taskName!=null,"setTaskdef- nonzro name"); 159 setKey(taskName); 160 m_Is = IS_TASK; } 162 163 164 167 public void setTypedef(String typeName) 168 { 169 require_(typeName!=null,"setTypedef- nonzro name"); 170 setKey(typeName); 171 m_Is = IS_TYPE; } 173 174 175 180 public void apply(ErrorSnapshot es) 181 { 182 require_(es!=null,"apply- nonzro snapshot"); 183 if (!putFlexString(es)) { 184 185 final Project P= getProject(); 186 final String item = getKey(); 187 Map mp; 188 189 if (isPropertySet()) { 190 es.addConfiguredPropertySet 191 ((PropertySet)FixtureExaminer.getReferencedObject 192 (P,null,item,PropertySet.class)); 193 } 194 else if (isTaskDef()) { 195 mp= P.getTaskDefinitions(); 196 if (Strings.ALL.equals(item)) { 197 putDefiners(es,mp,"TaskDef"); 198 } else { 199 putDefiner(es,item,(Class )mp.get(item),"TaskDef"); 200 } 201 202 } 203 else if (isTypeDef()) { 204 mp= P.getDataTypeDefinitions(); 205 if (Strings.ALL.equals(item)) { 206 putDefiners(es,mp,"TypeDef"); 207 } else { 208 putDefiner(es,item,(Class )mp.get(item),"TypeDef"); 209 } 210 } 211 } 212 } 213 214 215 218 private void putDefiner(ErrorSnapshot es, String key, Class c, String prefix) 219 { 220 if (c!=null) { 221 es.setProperty(prefix+"."+key,c.getName()); 222 } else { 223 es.setProperty(prefix+"."+key,null); 224 } 225 } 226 227 228 231 private void putDefiners(ErrorSnapshot es, Map mp, String prefix) 232 { 233 Iterator itr= mp.entrySet().iterator(); 234 while (itr.hasNext()) { 235 Map.Entry mE= (Map.Entry )itr.next(); 236 if (mE!=null) { 237 es.setProperty(prefix+"."+mE.getKey(),((Class )mE.getValue()).getName()); 238 } 239 } 240 } 241 242 243 248 private boolean putFlexString(ErrorSnapshot es) 249 { 250 if (!m_xstring.isUndefined()) { 251 es.setProperty(m_xstring.get(), m_xstring.getValue(getProject())); 252 return true; 253 } 254 return false; 255 } 256 257 258 261 protected final boolean isTaskDef() 262 { 263 return (m_Is&IS_TASK)==IS_TASK; 264 } 265 266 267 270 protected final boolean isTypeDef() 271 { 272 return (m_Is&IS_TYPE)==IS_TYPE; 273 } 274 275 276 280 protected final boolean isPropertySet() 281 { 282 return (m_Is&IS_PSET)==IS_PSET; 283 } 284 285 286 287 private static final int IS_NONE=0; 288 private static final int IS_TYPE=0x01; 289 private static final int IS_TASK=0x02; 290 private static final int IS_PSET=0x04; 291 292 private String m_itemName; 293 private int m_Is= IS_NONE; 294 private DiagnosticsValue m_xstring = new DiagnosticsValue(true);} 296 297 298 | Popular Tags |