1 36 package org.ungoverned.oscar; 37 38 import java.util.*; 39 40 import org.osgi.framework.*; 41 import org.ungoverned.moduleloader.Module; 42 43 class BundleInfo 44 { 45 private BundleArchive m_archive = null; 46 private Module[] m_modules = null; 47 private int m_state = 0; 48 private BundleActivator m_activator = null; 49 private BundleContext m_context = null; 50 private boolean m_removalPending = false; 53 private List m_svcRegList = null; 56 private Map m_svcUsageMap = null; 59 60 protected BundleInfo(BundleArchive archive, Module module) 61 throws Exception 62 { 63 m_archive = archive; 64 m_modules = (module == null) ? new Module[0] : new Module[] { module }; 65 66 m_state = Bundle.INSTALLED; 67 m_removalPending = false; 68 m_activator = null; 69 m_context = null; 70 71 m_svcRegList = new ArrayList(); 72 m_svcUsageMap = new HashMap(); 73 } 74 75 79 public BundleArchive getArchive() 80 { 81 return m_archive; 82 } 83 84 96 public Module[] getModules() 97 { 98 return m_modules; 99 } 100 101 107 public boolean hasModule(Module module) 108 { 109 for (int i = 0; i < m_modules.length; i++) 110 { 111 if (m_modules[i] == module) 112 { 113 return true; 114 } 115 } 116 return false; 117 } 118 119 124 public Module getCurrentModule() 125 { 126 return m_modules[m_modules.length - 1]; 127 } 128 129 134 public void addModule(Module module) 135 { 136 Module[] dest = new Module[m_modules.length + 1]; 137 System.arraycopy(m_modules, 0, dest, 0, m_modules.length); 138 dest[m_modules.length] = module; 139 m_modules = dest; 140 } 141 142 public long getBundleId() 143 { 144 return m_archive.getId(); 145 } 146 147 public String getLocation() 148 { 149 try 150 { 151 return m_archive.getLocation(); 152 } 153 catch (Exception ex) 154 { 155 Oscar.error("Unable to read location.", ex); 156 return null; 157 } 158 } 159 160 public int getStartLevel(int defaultLevel) 161 { 162 try 163 { 164 return m_archive.getStartLevel(); 165 } 166 catch (Exception ex) 167 { 168 Oscar.error("Unable to read start level.", ex); 169 return defaultLevel; 170 } 171 } 172 173 public void setStartLevel(int i) 174 { 175 try 176 { 177 m_archive.setStartLevel(i); 178 } 179 catch (Exception ex) 180 { 181 Oscar.error("Error writing to bundle archive.", ex); 182 } 183 } 184 185 public Map getCurrentHeader() 186 { 187 try 188 { 189 return m_archive.getManifestHeader(m_archive.getRevisionCount() - 1); 192 } 193 catch (Exception ex) 194 { 195 return null; 196 } 197 } 198 199 public int getState() 200 { 201 return m_state; 202 } 203 204 public void setState(int i) 205 { 206 m_state = i; 207 } 208 209 public int getPersistentState() 210 { 211 try 212 { 213 return m_archive.getPersistentState(); 214 } 215 catch (Exception ex) 216 { 217 Oscar.error("Error reading bundle archive.", ex); 218 return Bundle.INSTALLED; 219 } 220 } 221 222 public void setPersistentStateInactive() 223 { 224 try 225 { 226 m_archive.setPersistentState(Bundle.INSTALLED); 227 } 228 catch (Exception ex) 229 { 230 Oscar.error("Error writing to bundle archive.", ex); 231 } 232 } 233 234 public void setPersistentStateActive() 235 { 236 try 237 { 238 m_archive.setPersistentState(Bundle.ACTIVE); 239 } 240 catch (Exception ex) 241 { 242 Oscar.error("Error writing to bundle archive.", ex); 243 } 244 } 245 246 public void setPersistentStateUninstalled() 247 { 248 try 249 { 250 m_archive.setPersistentState(Bundle.UNINSTALLED); 251 } 252 catch (Exception ex) 253 { 254 Oscar.error("Error writing to bundle archive.", ex); 255 } 256 } 257 258 public BundleContext getContext() 259 { 260 return m_context; 261 } 262 263 public void setContext(BundleContext context) 264 { 265 m_context = context; 266 } 267 268 public BundleActivator getActivator() 269 { 270 return m_activator; 271 } 272 273 public void setActivator(BundleActivator activator) 274 { 275 m_activator = activator; 276 } 277 278 public boolean isRemovalPending() 279 { 280 return m_removalPending; 281 } 282 283 public void setRemovalPending() 284 { 285 m_removalPending = true; 286 } 287 288 public int getServiceRegistrationCount() 289 { 290 return m_svcRegList.size(); 291 } 292 293 public ServiceRegistrationImpl getServiceRegistration(int i) 294 { 295 try 296 { 297 return (ServiceRegistrationImpl) m_svcRegList.get(i); 298 } 299 catch (IndexOutOfBoundsException exc) 300 { 301 } 303 return null; 304 } 305 306 public void addServiceRegistration(ServiceRegistrationImpl reg) 307 { 308 m_svcRegList.add(reg); 309 } 310 311 public void removeServiceRegistration(ServiceRegistrationImpl reg) 312 { 313 m_svcRegList.remove(reg); 314 } 315 316 public Iterator getServiceUsageCounters() 319 { 320 return m_svcUsageMap.keySet().iterator(); 321 } 322 323 public UsageCounter getServiceUsageCounter(ServiceReference ref) 324 { 325 return (UsageCounter) m_svcUsageMap.get(ref); 326 } 327 328 public void putServiceUsageCounter(ServiceReference ref, UsageCounter usage) 329 { 330 m_svcUsageMap.put(ref, usage); 331 } 332 333 public void removeServiceUsageCounter(ServiceReference ref) 334 { 335 m_svcUsageMap.remove(ref); 336 } 337 338 343 protected static long getBundleIdFromModuleId(String id) 344 { 345 try 346 { 347 String bundleId = (id.indexOf('.') >= 0) 348 ? id.substring(0, id.indexOf('.')) : id; 349 return Long.parseLong(bundleId); 350 } 351 catch (NumberFormatException ex) 352 { 353 return -1; 354 } 355 } 356 357 362 protected static int getModuleRevisionFromModuleId(String id) 363 { 364 try 365 { 366 String rev = (id.indexOf('.') >= 0) 367 ? id.substring(id.indexOf('.') + 1) : id; 368 return Integer.parseInt(rev); 369 } 370 catch (NumberFormatException ex) 371 { 372 return -1; 373 } 374 } 375 376 static class UsageCounter 377 { 378 public int m_count = 0; 379 public Object m_svcObj = null; 380 public Object [] m_svcObjArray = null; 381 } 382 } | Popular Tags |