1 18 19 package org.apache.activemq.filter; 20 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 import javax.jms.JMSException ; 25 26 import org.apache.activemq.command.ActiveMQDestination; 27 import org.apache.activemq.command.Message; 28 29 34 public class DestinationPath { 35 protected static final char SEPARATOR = '.'; 36 37 public static String [] getDestinationPaths(String subject) { 38 List list = new ArrayList (); 39 int previous = 0; 40 int lastIndex = subject.length() - 1; 41 while (true) { 42 int idx = subject.indexOf(SEPARATOR, previous); 43 if (idx < 0) { 44 list.add(subject.substring(previous, lastIndex + 1)); 45 break; 46 } 47 list.add(subject.substring(previous, idx)); 48 previous = idx + 1; 49 } 50 String [] answer = new String [list.size()]; 51 list.toArray(answer); 52 return answer; 53 } 54 55 public static String [] getDestinationPaths(Message message) throws JMSException { 56 return getDestinationPaths(message.getDestination()); 57 } 58 59 public static String [] getDestinationPaths(ActiveMQDestination destination) { 60 return getDestinationPaths(destination.getPhysicalName()); 61 } 62 63 69 public static String toString(String [] paths) { 70 StringBuffer buffer = new StringBuffer (); 71 for (int i = 0; i < paths.length; i++) { 72 if (i > 0) { 73 buffer.append(SEPARATOR); 74 } 75 String path = paths[i]; 76 if (path == null) { 77 buffer.append("*"); 78 } 79 else { 80 buffer.append(path); 81 } 82 } 83 return buffer.toString(); 84 } 85 } 86 | Popular Tags |