@Override public VersionedName getVersionedName() { if (!isNameResolved()) return null; return new VersionedName(getSymbolicName(), getSuppliedVersionString()); }
protected static Collection<CatalogBundle> resolveWherePossible(ManagementContext mgmt, Collection<CatalogBundle> libraryBundles) { Collection<CatalogBundle> libraryBundlesResolved = MutableSet.of(); for (CatalogBundle b: libraryBundles) { libraryBundlesResolved.add(CatalogBundleDto.resolve(mgmt, b).or(b)); } return libraryBundlesResolved; }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Object obj = context.convertAnother(context.currentObject(), context.getRequiredType()); if (CatalogItemLibraries.class.isAssignableFrom(context.getRequiredType())) { CatalogItemLibraries libs = (CatalogItemLibraries)obj; Collection<String> bundles = libs.getBundles(); Collection<CatalogBundle> libraries = new ArrayList<CatalogBundle>(bundles.size()); for (String url : bundles) { libraries.add(new CatalogBundleDto(null, null, url)); } return libraries; } else { return obj; } }
@Override public boolean isNamed() { return isNameResolved(); }
public static Maybe<CatalogBundle> resolve(ManagementContext mgmt, CatalogBundle b) { if (b.isNameResolved()) return Maybe.of(b); OsgiManager osgi = ((ManagementContextInternal)mgmt).getOsgiManager().orNull(); if (osgi==null) return Maybe.absent("No OSGi manager"); Maybe<Bundle> b2 = osgi.findBundle(b); if (b2.isAbsent()) return Maybe.absent("Nothing installed for "+b); return Maybe.of(new CatalogBundleDto(b2.get().getSymbolicName(), b2.get().getVersion().toString(), b.getUrl())); }
String version = stringValOrNull(entry, "version"); String url = stringValOrNull(entry, "url"); dto.add(new CatalogBundleDto(name, version, url)); } else if (object instanceof String) { String inlineRef = (String) object; dto.add(new CatalogBundleDto(name, version, url)); } else if (object instanceof OsgiBundleWithUrl) { dto.add(new CatalogBundleDto( ((OsgiBundleWithUrl)object).getSymbolicName(), ((OsgiBundleWithUrl)object).getSuppliedVersionString(), ((OsgiBundleWithUrl)object).getUrl() )); } else if (object instanceof VersionedName) { dto.add(new CatalogBundleDto( ((VersionedName)object).getSymbolicName(), ((VersionedName)object).getVersionString(), null )); } else { LOG.debug("Unexpected entry in libraries list neither string nor map: " + object);
libraryBundles.add(new CatalogBundleDto(containingBundle.getSymbolicName(), containingBundle.getSuppliedVersionString(), null));
protected Entity createSimpleEntity(String bundleUrl, Class<?> clazz) { @SuppressWarnings("unchecked") Class<? extends Entity> entityClass = (Class<? extends Entity>) clazz; EntitySpec<?> spec = EntitySpec.create(entityClass); Entity entity = mgmt.getEntityManager().createEntity(spec); CatalogEntityItemDto item = CatalogItemBuilder.newEntity(clazz.getName(), "1.0.0") .libraries(ImmutableList.<CatalogBundle>of(new CatalogBundleDto(null, null, bundleUrl))) .plan("{\"services\":[{\"type\": \"" + clazz.getName() + "\"}]}") .build(); mgmt.getCatalog().addItem(item); final EntityInternal entityInternal = (EntityInternal) entity; entityInternal.setCatalogItemIdAndSearchPath(item.getCatalogItemId(), item.getCatalogItemIdSearchPath()); return entity; }
CatalogEntityItemDto osgiEntity = CatalogItemBuilder.newEntity(TestEntity.class.getCanonicalName(), "Test Entity from OSGi") .libraries(ImmutableList.<CatalogBundle>of(new CatalogBundleDto(null, null, bundleUrl))) .build(); testEntitiesJavaCatalog.addEntry(osgiEntity);