1 15 package org.apache.hivemind; 16 17 import java.util.Collection ; 18 19 import org.apache.hivemind.impl.LocationImpl; 20 import org.apache.hivemind.util.ClasspathResource; 21 22 27 public final class HiveMind 28 { 29 32 public static final String THREAD_EVENT_NOTIFIER_SERVICE = "hivemind.ThreadEventNotifier"; 33 34 39 40 public static final String THREAD_LOCALE_SERVICE = "hivemind.ThreadLocale"; 41 42 47 48 public static final String INTERFACE_SYNTHESIZER_SERVICE = "hivemind.InterfaceSynthesizer"; 49 50 55 56 public static final String AUTOWIRING_SERVICE = "hivemind.Autowiring"; 57 58 64 65 public static final Object INTROSPECTOR_MUTEX = new Object (); 66 67 private HiveMind() 68 { 69 } 71 72 public static ApplicationRuntimeException createRegistryShutdownException() 73 { 74 return new ApplicationRuntimeException(HiveMindMessages.registryShutdown()); 75 } 76 77 81 82 public static Location findLocation(Object [] locations) 83 { 84 for (int i = 0; i < locations.length; i++) 85 { 86 Object location = locations[i]; 87 88 Location result = getLocation(location); 89 90 if (result != null) 91 return result; 92 93 } 94 95 return null; 96 } 97 98 104 public static Location getLocation(Object object) 105 { 106 if (object == null) 107 return null; 108 109 if (object instanceof Location) 110 return (Location) object; 111 112 if (object instanceof Locatable) 113 { 114 Locatable locatable = (Locatable) object; 115 116 return locatable.getLocation(); 117 } 118 119 return null; 120 } 121 122 126 public static String getLocationString(Object object) 127 { 128 Location l = getLocation(object); 129 130 if (l != null) 131 return l.toString(); 132 133 return HiveMindMessages.unknownLocation(); 134 } 135 136 public static Location getClassLocation(Class theClass, ClassResolver classResolver) 137 { 138 String path = "/" + theClass.getName().replace('.', '/'); 139 140 Resource r = new ClasspathResource(classResolver, path); 141 142 return new LocationImpl(r); 143 } 144 145 151 public static boolean isBlank(String string) 152 { 153 if (string == null || string.length() == 0) 154 return true; 155 156 if (string.trim().length() == 0) 157 return true; 158 159 return false; 160 } 161 162 165 public static boolean isNonBlank(String string) 166 { 167 return !isBlank(string); 168 } 169 170 178 public static void setLocation(Object holder, Location location) 179 { 180 if (holder != null && holder instanceof LocationHolder) 181 { 182 LocationHolder lh = (LocationHolder) holder; 183 184 lh.setLocation(location); 185 } 186 } 187 188 191 public static boolean isEmpty(Collection c) 192 { 193 return c == null || c.isEmpty(); 194 } 195 } | Popular Tags |