KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > util > IdUtils


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

15 package org.apache.hivemind.util;
16
17 import org.apache.hivemind.HiveMind;
18
19 /**
20  * A collection of utilities for handling qualified and unqualified ids.
21  *
22  * @author Howard Lewis Ship
23  */

24 public class IdUtils
25 {
26
27     /**
28      * Returns a fully qualfied id. If the id contains a '.', then it is returned unchanged.
29      * Otherwise, the module's id is prefixed (with a seperator '.') and returned;
30      */

31     public static String JavaDoc qualify(String JavaDoc moduleId, String JavaDoc id)
32     {
33         if (id.indexOf('.') > 0)
34             return id;
35
36         return moduleId + "." + id;
37     }
38
39     /**
40      * Qualifies a list of interceptor service ids provided for an interceptor contribution. The
41      * special value "*" is not qualified.
42      */

43     public static String JavaDoc qualifyList(String JavaDoc sourceModuleId, String JavaDoc list)
44     {
45         if (HiveMind.isBlank(list) || list.equals("*"))
46             return list;
47
48         String JavaDoc[] items = StringUtils.split(list);
49
50         for (int i = 0; i < items.length; i++)
51             items[i] = qualify(sourceModuleId, items[i]);
52
53         return StringUtils.join(items, ',');
54     }
55
56     /**
57      * Removes the module name from a fully qualified id
58      */

59     public static String JavaDoc stripModule(String JavaDoc id)
60     {
61         int lastPoint = id.lastIndexOf('.');
62         if (lastPoint > 0)
63             return id.substring(lastPoint + 1, id.length());
64
65         return id;
66     }
67
68     /**
69      * Extracts the module name from a fully qualified id Returns null if id contains no module
70      */

71     public static String JavaDoc extractModule(String JavaDoc id)
72     {
73         int lastPoint = id.lastIndexOf('.');
74         if (lastPoint > 0)
75             return id.substring(0, lastPoint);
76
77         return null;
78     }
79
80 }
81
Popular Tags