public static ModuleImplAdvertisement buildPeerGroupImplAdvertisement( PeerGroup parent, ModuleSpecID newGroupModuleSpecID, String newDescription, Map newServices, Map newApps, Map newProtos) throws Exception { // illegal types will cause an IllegalArgumentException typeCheckKeys(newServices); typeCheckValues(newServices); typeCheckKeys(newApps); typeCheckValues(newApps); typeCheckKeys(newProtos); typeCheckValues(newProtos); // get a copy of parent's general purpose advert as a template ModuleImplAdvertisement implAdv = parent.getAllPurposePeerGroupImplAdvertisement(); implAdv.setDescription(newDescription); implAdv.setModuleSpecID(newGroupModuleSpecID); // extract embedded ad for standard modules TextElement paramElement = (TextElement) implAdv.getParam(); StdPeerGroupParamAdv paramAdv = new StdPeerGroupParamAdv(paramElement); // alter services Map services = paramAdv.getServices(); typeCheckKeys(services); // mergeTables will override old services with new if base classes are the same services = mergeTables(services, newServices); paramAdv.setServices(services); // alter apps Map apps = paramAdv.getApps(); typeCheckKeys(apps); apps = mergeTables(apps, newApps); paramAdv.setApps(newApps); // alter protos Map protos = paramAdv.getProtos(); typeCheckKeys(protos); apps = mergeTables(protos, newProtos); paramAdv.setProtos(newProtos); paramElement = (TextElement) paramAdv.getDocument(MimeMediaType.XMLUTF8); implAdv.setParam(paramElement); return implAdv; }
/** * Compat's (compatibility statements) serve to narrow the search for a ModuleImplAdvertisement. * Basically you want something compatible with your group's implementation. Use this form for * compatibilty with the current StdPeerGroup. * * @return -- boilerplate compat for StdPeerGroup */ public static XMLDocument buildCompat() { try { PeerGroup wpg = PeerGroup.globalRegistry.lookupInstance(PeerGroupID.worldPeerGroupID); ModuleImplAdvertisement implAdv = wpg.getAllPurposePeerGroupImplAdvertisement(); wpg.unref(); XMLDocument compat = (XMLDocument) implAdv.getCompat(); return compat; } catch (Exception e) { // but if it doesn't work default to what was current on Feb 22 2006. return buildCompat("JDK1.4.1", "V2.0 Ref Impl"); } }