1 22 package org.jboss.deployment; 23 24 import java.net.URL ; 25 import java.util.Comparator ; 26 27 import org.jboss.util.NullArgumentException; 28 29 36 public class DeploymentSorter implements Comparator , DefaultDeploymentSorter 37 { 38 45 public static final String [] DEFAULT_SUFFIX_ORDER = { 46 ".deployer", "-deployer.xml", ".sar", "-service.xml", ".rar", "-ds.xml", 47 ".har", ".jar", ".war", ".wsr", ".ear", ".zip", ".bsh", ".last" 48 }; 49 50 protected String [] suffixOrder; 51 52 public DeploymentSorter(String [] suffixOrder) 53 { 54 if (suffixOrder == null) 55 throw new NullArgumentException("suffixOrder"); 56 57 this.suffixOrder = suffixOrder; 58 } 59 60 public DeploymentSorter() 61 { 62 this(DEFAULT_SUFFIX_ORDER); 63 } 64 65 public String [] getSuffixOrder() 66 { 67 return suffixOrder; 68 } 69 public void setSuffixOrder(String [] suffixOrder) 70 { 71 this.suffixOrder = suffixOrder; 72 } 73 74 80 public int compare(Object o1, Object o2) 81 { 82 URL u1 = (URL )o1; 83 URL u2 = (URL )o2; 84 int order = getExtensionIndex(u1) - getExtensionIndex(u2); 85 if (order != 0) 86 return order; 87 return u1.getFile().compareTo(u2.getFile()); 88 } 89 90 93 public int getExtensionIndex(URL url) 94 { 95 String path = url.getPath(); 96 if (path.endsWith("/")) 97 path = path.substring(0, path.length() - 1); 98 int i = 0; 99 for (; i < suffixOrder.length; i++) 100 { 101 if (path.endsWith(suffixOrder[i])) 102 break; 103 } 104 return i; 105 } 106 } 107 | Popular Tags |