001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.hivemind.util; 016 017 import org.apache.hivemind.HiveMind; 018 019 /** 020 * A collection of utilities for handling qualified and unqualified ids. 021 * 022 * @author Howard Lewis Ship 023 */ 024 public class IdUtils 025 { 026 027 /** 028 * Returns a fully qualfied id. If the id contains a '.', then it 029 * is returned unchanged. Otherwise, the module's id is prefixed (with a 030 * seperator '.') and returned; 031 */ 032 public static String qualify(String moduleId, String id) 033 { 034 if (id.indexOf('.') > 0) 035 return id; 036 037 return moduleId + "." + id; 038 } 039 040 /** 041 * Qualifies a list of interceptor service ids provided for an interceptor 042 * contribution. The special value "*" is not qualified. 043 */ 044 public static String qualifyList(String sourceModuleId, String list) 045 { 046 if (HiveMind.isBlank(list) || list.equals("*")) 047 return list; 048 049 String[] items = StringUtils.split(list); 050 051 for (int i = 0; i < items.length; i++) 052 items[i] = qualify(sourceModuleId, items[i]); 053 054 return StringUtils.join(items, ','); 055 } 056 057 /** 058 * Removes the module name from a fully qualified id 059 */ 060 public static String stripModule(String id) 061 { 062 int lastPoint = id.lastIndexOf('.'); 063 if (lastPoint > 0) 064 return id.substring(lastPoint + 1, id.length()); 065 else return id; 066 } 067 068 /** 069 * Extracts the module name from a fully qualified id 070 * Returns null if id contains no module 071 */ 072 public static String extractModule(String id) 073 { 074 int lastPoint = id.lastIndexOf('.'); 075 if (lastPoint > 0) 076 return id.substring(0, lastPoint); 077 else return null; 078 } 079 080 }