KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > filter > DestinationPath


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.activemq.filter;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23
24 import javax.jms.JMSException JavaDoc;
25
26 import org.apache.activemq.command.ActiveMQDestination;
27 import org.apache.activemq.command.Message;
28
29 /**
30  * Helper class for decomposing a Destination into a number of paths
31  *
32  * @version $Revision: 1.3 $
33  */

34 public class DestinationPath {
35     protected static final char SEPARATOR = '.';
36
37     public static String JavaDoc[] getDestinationPaths(String JavaDoc subject) {
38         List JavaDoc list = new ArrayList JavaDoc();
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 JavaDoc[] answer = new String JavaDoc[list.size()];
51         list.toArray(answer);
52         return answer;
53     }
54
55     public static String JavaDoc[] getDestinationPaths(Message message) throws JMSException JavaDoc {
56         return getDestinationPaths(message.getDestination());
57     }
58
59     public static String JavaDoc[] getDestinationPaths(ActiveMQDestination destination) {
60         return getDestinationPaths(destination.getPhysicalName());
61     }
62
63     /**
64      * Converts the paths to a single String seperated by dots.
65      *
66      * @param paths
67      * @return
68      */

69     public static String JavaDoc toString(String JavaDoc[] paths) {
70         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
71         for (int i = 0; i < paths.length; i++) {
72             if (i > 0) {
73                 buffer.append(SEPARATOR);
74             }
75             String JavaDoc 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