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 ConditionalVariableSet extends DataType { 33 34 36 39 private ArrayList list = new ArrayList (); 40 41 43 49 protected void addConditionalvariable(ConditionalVariable variable) { 50 51 if (isReference()) 52 throw noChildrenAllowed(); 53 list.add(variable); 54 55 } 56 57 62 protected void addConditionalvariableset(ConditionalVariableSet 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 ConditionalVariableSet 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 = (ConditionalVariableSet)o; 96 } else if (o.getClass().isInstance(this)) { 97 nestedSet = (ConditionalVariableSet)o; 98 } else if (o instanceof ConditionalVariable) { 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 |