1 package net.sf.invicta.type; 2 3 import java.util.Iterator ; 4 5 import net.sf.invicta.InvictaConstants; 6 import net.sf.invicta.api.Target; 7 8 11 public class TargetTemplate extends TargetImpl { 12 13 public final static String MODE_REPLACE = "replace"; 14 public final static String MODE_RENAME = "rename"; 15 public final static String MODE_ADD_BEFORE = "addBefore"; 16 public final static String MODE_ADD_AFTER = "addAfter"; 17 public final static String MODE_ADD_BEFORE_ALL = "addBeforeAll"; 18 public final static String MODE_ADD_AFTER_ALL = "addAfterAll"; 19 20 21 protected String mode; 22 protected String templateString; 23 24 27 public TargetTemplate() { 28 super(); 29 } 30 31 34 public TargetTemplate(TargetTemplate other) { 35 super((Target)other); 36 this.mode = other.getMode(); 37 this.templateString = other.getTemplateString(); 38 } 39 40 44 public String getMode() { 45 return mode; 46 } 47 48 49 53 public void setMode(String mode) { 54 this.mode = mode; 55 } 56 57 61 public String getTemplateString() { 62 return templateString; 63 } 64 65 69 public void setTemplateString(String templateString) { 70 this.templateString = templateString; 71 } 72 73 76 public boolean equals(TargetTemplate other) { 77 return equals(other, false); 78 } 79 80 83 public boolean equals(TargetTemplate other, boolean compareDepends) { 84 85 if (compareDepends) { 86 87 if (this.dependsList.size() != other.getDependsList().size()) 89 return false; 90 91 Iterator otherIter = other.getDependsList().iterator(); 93 for (Iterator thisIter = this.dependsList.iterator(); thisIter.hasNext();) { 94 String thisDepend = (String ) thisIter.next(); 95 String otherDepend = (String ) otherIter.next(); 96 if (!thisDepend.equals(otherDepend)) 97 return false; 98 } 99 } 100 101 return equals(this.name, other.getName()) && 103 equals(this.mode, other.getMode()) && 104 equals(this.templateString, other.getTemplateString()) && 105 equals(this.ifString, other.getIf()) && 106 equals(this.unlessString, other.getUnless()); 107 } 108 109 110 113 public String getAntTemplateString() { 114 String targetTemplateString; 115 String targetName = InvictaConstants.COMPONENT_NAME_TEMPLATE + 116 InvictaConstants.TARGET_DELIMITER + 117 this.name; 118 119 targetTemplateString = 121 "<!--================================================ \n" + 122 "= Target: " + targetName + " \n" + 123 "================================================ --> \n"; 124 125 targetTemplateString += "<target name=\"" + targetName + "\" "; 127 128 if (this.ifString != null) 130 targetTemplateString += "if=\"" + this.ifString + "\" "; 131 if (this.unlessString != null) 132 targetTemplateString += "unless=\"" + this.unlessString + "\" "; 133 if (this.description != null) 134 targetTemplateString += "description=\"" + this.description + "\" "; 135 136 if (this.dependsList.size() > 0) 138 targetTemplateString += "depends=\"" + getAntTargetDependString() + "\" "; 139 140 targetTemplateString += ">\n"; 141 142 targetTemplateString += this.templateString; 144 145 targetTemplateString += "\n</target> \n \n "; 147 148 return targetTemplateString; 149 } 150 151 154 protected String getAntTargetDependString() { 155 String dependString = ""; 156 for (Iterator dependIter = this.dependsList.iterator(); dependIter.hasNext();) { 158 String oneDepend = (String ) dependIter.next(); 159 160 if (isAbsoluteDepend(oneDepend)) 162 dependString += oneDepend; 163 164 else 166 dependString += InvictaConstants.COMPONENT_NAME_TEMPLATE + 167 InvictaConstants.TARGET_DELIMITER + 168 oneDepend; 169 170 if (dependIter.hasNext()) 172 dependString += InvictaConstants.DEPEND_LIST_DELIMITER; 173 } 174 175 return dependString; 176 } 177 178 181 protected boolean isAbsoluteDepend(String dependStr) { 182 return dependStr.startsWith(InvictaConstants.TARGET_DEPENDENCY_SPECIAL_PREFIX); 183 } 184 185 188 protected boolean equals(Object o1, Object o2) { 189 if ((o1 == null) && (o2 == null)) 190 return true; 191 if ((o1 == null) || (o2 == null)) 192 return false; 193 return o1.equals(o2); 194 } 195 196 } 197 | Popular Tags |