1 22 package org.jboss.deployment.scanner; 23 24 import java.util.Comparator ; 25 import java.net.URL ; 26 import org.jboss.deployment.DeploymentSorter; 27 import org.jboss.deployment.DefaultDeploymentSorter; 28 29 40 public class PrefixDeploymentSorter implements Comparator , DefaultDeploymentSorter 41 { 42 43 44 private DeploymentSorter sorter = new DeploymentSorter(); 45 46 public String [] getSuffixOrder() 47 { 48 return sorter.getSuffixOrder(); 49 } 50 51 public void setSuffixOrder(String [] suffixOrder) 52 { 53 sorter.setSuffixOrder(suffixOrder); 54 } 55 56 60 public int compare(Object o1, Object o2) { 61 int comp = getPrefixValue((URL )o1) - getPrefixValue((URL )o2); 62 63 return comp == 0 ? sorter.compare(o1, o2) : comp; 64 } 65 66 70 private int getPrefixValue(URL url) { 71 String path = url.getPath(); 72 int nameEnd = path.length() - 1; 73 if (nameEnd <= 0) { 74 return 0; 75 } 76 77 if (path.charAt(nameEnd) == '/') { 79 nameEnd--; 80 } 81 82 int nameStart = path.lastIndexOf('/', nameEnd) + 1; 84 85 int prefixEnd = nameStart; 87 while (prefixEnd <= nameEnd && Character.isDigit(path.charAt(prefixEnd))) { 88 prefixEnd++; 89 } 90 91 if (prefixEnd == nameStart) { 93 return -1; 94 } 95 96 while (nameStart < prefixEnd && path.charAt(nameStart) == '0') { 98 nameStart++; 99 } 100 101 return (nameStart == prefixEnd) ? 0 : Integer.parseInt(path.substring(nameStart, prefixEnd)); 102 } 103 } 104 | Popular Tags |