1 16 17 package org.apache.commons.launcher.types; 18 19 import java.util.ArrayList ; 20 import java.util.Stack ; 21 import org.apache.commons.launcher.Launcher; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.types.DataType; 24 import org.apache.tools.ant.types.Reference; 25 26 32 public class ConditionalArgumentSet extends DataType { 33 34 36 39 private ArrayList list = new ArrayList (); 40 41 43 49 protected void addConditionalargument(ConditionalArgument argument) { 50 51 if (isReference()) 52 throw noChildrenAllowed(); 53 list.add(argument); 54 55 } 56 57 62 protected void addConditionalargumentset(ConditionalArgumentSet set) { 63 64 if (isReference()) 65 throw noChildrenAllowed(); 66 list.add(set); 67 68 } 69 70 75 public ArrayList getList() { 76 77 if (!checked) { 79 Stack stk = new Stack (); 80 stk.push(this); 81 dieOnCircularReference(stk, project); 82 } 83 84 ArrayList mergedList = new ArrayList (list.size()); 87 for (int i = 0; i < list.size(); i++) { 88 Object o = list.get(i); 89 ConditionalArgumentSet nestedSet = null; 90 if (o instanceof Reference) { 91 o = ((Reference)o).getReferencedObject(project); 92 if (!o.getClass().isInstance(this)) 94 throw new BuildException(Launcher.getLocalizedString("cannot.reference", this.getClass().getName())); 95 nestedSet = (ConditionalArgumentSet)o; 96 } else if (o.getClass().isInstance(this)) { 97 nestedSet = (ConditionalArgumentSet)o; 98 } else if (o instanceof ConditionalArgument) { 99 mergedList.add(o); 100 } else { 101 throw new BuildException(Launcher.getLocalizedString("cannot.nest", this.getClass().getName())); 102 } 103 if (nestedSet != null) 104 mergedList.addAll(nestedSet.getList()); 105 } 106 107 return mergedList; 108 109 } 110 111 119 public void setRefid(Reference r) throws BuildException { 120 121 if (!list.isEmpty()) 122 throw tooManyAttributes(); 123 list.add(r); 124 super.setRefid(r); 125 126 } 127 128 } 129 | Popular Tags |