|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
IdUtils.java | 60% | 52.9% | 50% | 54.8% |
|
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 | 8233 | public static String qualify(String moduleId, String id) |
32 | { | |
33 | 8233 | if (id.indexOf('.') > 0) |
34 | 4453 | return id; |
35 | ||
36 | 3780 | 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 | 65 | public static String qualifyList(String sourceModuleId, String list) |
44 | { | |
45 | 65 | if (HiveMind.isBlank(list) || list.equals("*")) |
46 | 61 | return list; |
47 | ||
48 | 4 | String[] items = StringUtils.split(list); |
49 | ||
50 | 4 | for (int i = 0; i < items.length; i++) |
51 | 7 | items[i] = qualify(sourceModuleId, items[i]); |
52 | ||
53 | 4 | return StringUtils.join(items, ','); |
54 | } | |
55 | ||
56 | /** | |
57 | * Removes the module name from a fully qualified id | |
58 | */ | |
59 | 0 | public static String stripModule(String id) |
60 | { | |
61 | 0 | int lastPoint = id.lastIndexOf('.'); |
62 | 0 | if (lastPoint > 0) |
63 | 0 | return id.substring(lastPoint + 1, id.length()); |
64 | ||
65 | 0 | return id; |
66 | } | |
67 | ||
68 | /** | |
69 | * Extracts the module name from a fully qualified id Returns null if id contains no module | |
70 | */ | |
71 | 0 | public static String extractModule(String id) |
72 | { | |
73 | 0 | int lastPoint = id.lastIndexOf('.'); |
74 | 0 | if (lastPoint > 0) |
75 | 0 | return id.substring(0, lastPoint); |
76 | ||
77 | 0 | return null; |
78 | } | |
79 | ||
80 | } |
|