Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/hivemind/util/IdUtils.java


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
29       * is returned unchanged.  Otherwise, the module's id is prefixed (with a 
30       * seperator '.') and returned;
31       */
32      public static String qualify(String moduleId, String id)
33      {
34          if (id.indexOf('.') > 0)
35              return id;
36  
37          return moduleId + "." + id;
38      }
39  
40      /**
41       * Qualifies a list of interceptor service ids provided for an interceptor
42       * contribution.  The special value "*" is not qualified.
43       */
44      public static String qualifyList(String sourceModuleId, String list)
45      {
46          if (HiveMind.isBlank(list) || list.equals("*"))
47              return list;
48  
49          String[] items = StringUtils.split(list);
50  
51          for (int i = 0; i < items.length; i++)
52              items[i] = qualify(sourceModuleId, items[i]);
53  
54          return StringUtils.join(items, ',');
55      }
56      
57      /**
58       * Removes the module name from a fully qualified id
59       */
60      public static String stripModule(String id)
61      {
62          int lastPoint = id.lastIndexOf('.');
63          if (lastPoint > 0)
64              return id.substring(lastPoint + 1, id.length());
65          else return id;
66      }
67  
68      /**
69       * Extracts the module name from a fully qualified id
70       * Returns null if id contains no module
71       */
72      public static String extractModule(String id)
73      {
74          int lastPoint = id.lastIndexOf('.');
75          if (lastPoint > 0)
76              return id.substring(0, lastPoint);
77          else return null;
78      }
79  
80  }