📄 configparams.java
字号:
s.appendChild(e); StructuredDocument asDoc = (StructuredDocument) anAdv.getDocument(adv.getMimeType()); StructuredDocumentUtils.copyElements(adv, s, asDoc, PARAM_TAG); } return true; } /** * Returns the number of times this object has been modified since it was * created. This permits the detection of local changes that require * refreshing some other data. * * @return int the current modification count. */ public int getModCount() { return modCount.get(); } /** * Increases the modification count of this instance. * * @return modification count */ protected synchronized int incModCount() { return modCount.incrementAndGet(); } /** * Puts a service parameter in the service parameters table * under the given key. The key is usually a ModuleClassID. This method * makes a clone of the given element into an independent document. * * @param key The key. * @param param The parameter document. */ public void putServiceParam(ID key, Element param) { incModCount(); params.remove(key); ads.remove(key); if (param == null) { return; } boolean isDisabled = false; if (param instanceof XMLElement) { Enumeration<XMLElement> isOff = param.getChildren("isOff"); isDisabled = isOff.hasMoreElements(); Advertisement adv = null; try { adv = AdvertisementFactory.newAdvertisement((XMLElement) param); } catch (RuntimeException ignored) { // ignored ; } if (null != adv) { setSvcConfigAdvertisement(key,adv, !isDisabled); return; } } StructuredDocument newDoc = StructuredDocumentUtils.copyAsDocument(param); if(isDisabled) { disabled.add(key); } else { disabled.remove(key); } params.put(key, newDoc); } /** * Puts an advertisement into the service parameters table under the given * key. The key is usually a {@code ModuleClassID}. This method makes a * clone of the advertisement. * * @param key The key. * @param adv The advertisement, a clone of which is stored or {@code null} * to forget this key. */ public void setSvcConfigAdvertisement(ID key, Advertisement adv) { setSvcConfigAdvertisement(key, adv, true); } /** * Puts an advertisement into the service parameters table under the given * key. The key is usually a {@code ModuleClassID}. This method makes a * clone of the advertisement. * * @param key The key. * @param adv The advertisement, a clone of which is stored or {@code null} * to forget this key. * @param enabled If true then the service is enabled or disabled if false. */ public void setSvcConfigAdvertisement(ID key, Advertisement adv, boolean enabled) { incModCount(); params.remove(key); ads.remove(key); if(enabled) { disabled.remove(key); } else { disabled.add(key); } if (null == adv) { return; } try { ads.put(key, adv.clone()); } catch (CloneNotSupportedException failed) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Unclonable Advertisements may not be used : " + adv.getClass().getName(), failed); } throw new IllegalArgumentException("Unclonable Advertisements may not be used : " + adv.getClass().getName()); } } /** * Gets an advertisement from the service parameters table under the given * key. The key is usually a {@code ModuleClassID}. This method makes a * clone of the advertisement. * * @param key The key. * @return If {@code true} then the service is enabled otherwise {@false} if * the service is disabled. */ public boolean isSvcEnabled(ID key) { return !disabled.contains(key); } /** * Gets an advertisement from the service parameters table under the given * key. The key is usually a {@code ModuleClassID}. This method makes a * clone of the advertisement. * * @param key The key. * @return The advertisement for the specified key otherwise {@code null}. */ public Advertisement getSvcConfigAdvertisement(ID key) { Advertisement adv = ads.get(key); if (null == adv) { if (params.containsKey(key)) { throw new IllegalStateException("Unable to return advertisement, params are not an advertisement."); } return null; } try { return adv.clone(); } catch (CloneNotSupportedException failed) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Unclonable Advertisements may not be used : " + adv.getClass().getName(), failed); } throw new IllegalArgumentException("Unclonable Advertisements may not be used : " + adv.getClass().getName()); } } /** * Returns the parameter element that matches the given key from the * service parameters table. The key is of a subclass of ID; usually a * ModuleClassID. * * @param key The key. * @return StructuredDocument The matching parameter document or null if * none matched. */ public StructuredDocument getServiceParam(ID key) { StructuredDocument param = params.get(key); if (param == null) { Advertisement ad = ads.get(key); if (null == ad) { return null; } return (XMLDocument) ad.getDocument(MimeMediaType.XMLUTF8); } StructuredDocument newDoc = StructuredDocumentUtils.copyAsDocument(param); if(disabled.contains(key)) { Enumeration<Element> isOffAlready = newDoc.getChildren("isOff"); if(!isOffAlready.hasMoreElements()) { newDoc.appendChild(newDoc.createElement("isOff", null)); } } return newDoc; } /** * Removes and returns the parameter element that matches the given key * from the service parameters table. The key is of a subclass of ID; * usually a ModuleClassID. * * @param key The key. * * @return The removed parameter element or {@code null} if not found. */ public StructuredDocument removeServiceParam(ID key) { StructuredDocument param = params.remove(key); if (param == null) { Advertisement ad = ads.remove(key); if (null == ad) { return null; } return (XMLDocument) ad.getDocument(MimeMediaType.XMLUTF8); } else { ads.remove(key); } incModCount(); // It sound silly to clone it, but remember that we could be sharing // this element with a clone of ours, so we have the duty to still // protect it. StructuredDocument newDoc = StructuredDocumentUtils.copyAsDocument(param); if(disabled.contains(key)) { newDoc.appendChild(newDoc.createElement("isOff", null)); disabled.remove(key); } return newDoc; } /** * Removes any parameters for the given key from the service parameters * table. * * @param key The key. */ public void removeSvcConfigAdvertisement(ID key) { incModCount(); params.remove(key); ads.remove(key); } /** * Returns the set of params held by this object. The parameters are not * copied and any changes to the Set are reflected in this object's version. * incModCount should be called as appropriate. * * @deprecated This method exposes the internal data structures of the * advertisement and will be removed in order to prevent unexpected * behaviour. */ @Deprecated public Set<Map.Entry<ID, StructuredDocument>> getServiceParamsEntrySet() { Map<ID, StructuredDocument> result = new HashMap<ID, StructuredDocument>(); result.putAll(params); for (Map.Entry<ID, Advertisement> anEntry : ads.entrySet()) { XMLDocument entryDoc = (XMLDocument) anEntry.getValue().getDocument(MimeMediaType.XMLUTF8); if(disabled.contains(anEntry.getKey())) { entryDoc.appendChild(entryDoc.createElement("isOff", null)); } result.put(anEntry.getKey(), entryDoc); } return Collections.unmodifiableSet(result.entrySet()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -