⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complextype.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="433" href="#433">433</a> <em>     * Obtain the value of a specific attribute that is valid for a specific</em><a name="434" href="#434">434</a> <em>     * CrawlerSettings object.&lt;p></em><a name="435" href="#435">435</a> <em>     * </em><a name="436" href="#436">436</a> <em>     * This method will first try to get a settings object from the supplied</em><a name="437" href="#437">437</a> <em>     * context, then try to look up the attribute from this settings object. If</em><a name="438" href="#438">438</a> <em>     * it is not found it will traverse the settings up to the order and as a</em><a name="439" href="#439">439</a> <em>     * last resort deliver the default value.</em><a name="440" href="#440">440</a> <em>     * </em><a name="441" href="#441">441</a> <em>     * @param context the object to get the settings from.</em><a name="442" href="#442">442</a> <em>     * @param name the name of the attribute to be retrieved.</em><a name="443" href="#443">443</a> <em>     * @return The value of the attribute retrieved.</em><a name="444" href="#444">444</a> <em>     * @see CrawlerSettings</em><a name="445" href="#445">445</a> <em>     * @throws AttributeNotFoundException</em><a name="446" href="#446">446</a> <em>     */</em><a name="447" href="#447">447</a>     <strong>public</strong> Object getAttribute(Object context, String name)<a name="448" href="#448">448</a>         throws AttributeNotFoundException {<a name="449" href="#449">449</a>         Context ctxt = getSettingsFromObject(context);<a name="450" href="#450">450</a> <a name="451" href="#451">451</a>         <em class="comment">// If settings is not set, return the default value</em><a name="452" href="#452">452</a>         <strong>if</strong> (ctxt.settings == <strong>null</strong>) {<a name="453" href="#453">453</a>             <strong>try</strong> {<a name="454" href="#454">454</a>                 <strong>return</strong> ((Type) definitionMap.get(name)).getDefaultValue();<a name="455" href="#455">455</a>             } <strong>catch</strong> (NullPointerException e) {<a name="456" href="#456">456</a>                 <strong>throw</strong> <strong>new</strong> AttributeNotFoundException(<a name="457" href="#457">457</a>                         <span class="string">"Could not find attribute: "</span> + name);<a name="458" href="#458">458</a>             }<a name="459" href="#459">459</a>         }<a name="460" href="#460">460</a> <a name="461" href="#461">461</a>         <strong>return</strong> getDataContainerRecursive(ctxt, name).get(name);<a name="462" href="#462">462</a>     }<a name="463" href="#463">463</a> <a name="464" href="#464">464</a>     <em>/**<em>*</em></em><a name="465" href="#465">465</a> <em>     * Obtain the value of a specific attribute that is valid for a specific</em><a name="466" href="#466">466</a> <em>     * CrawlerSettings object.</em><a name="467" href="#467">467</a> <em>     * &lt;p></em><a name="468" href="#468">468</a> <em>     * </em><a name="469" href="#469">469</a> <em>     * This method will first try to get a settings object from the supplied</em><a name="470" href="#470">470</a> <em>     * context, then try to look up the attribute from this settings object. If</em><a name="471" href="#471">471</a> <em>     * it is not found it will traverse the settings up to the order and as a</em><a name="472" href="#472">472</a> <em>     * last resort deliver the default value.</em><a name="473" href="#473">473</a> <em>     * &lt;p></em><a name="474" href="#474">474</a> <em>     * </em><a name="475" href="#475">475</a> <em>     * The only difference from the {@link #getAttribute(Object, String)}is</em><a name="476" href="#476">476</a> <em>     * that this method doesn't throw any checked exceptions. If an undefined</em><a name="477" href="#477">477</a> <em>     * attribute is requested from a ComplexType, it is concidered a bug and a</em><a name="478" href="#478">478</a> <em>     * runtime exception is thrown instead.</em><a name="479" href="#479">479</a> <em>     * </em><a name="480" href="#480">480</a> <em>     * @param context the object to get the settings from.</em><a name="481" href="#481">481</a> <em>     * @param name the name of the attribute to be retrieved.</em><a name="482" href="#482">482</a> <em>     * @return The value of the attribute retrieved.</em><a name="483" href="#483">483</a> <em>     * @see #getAttribute(Object, String)</em><a name="484" href="#484">484</a> <em>     * @see CrawlerSettings</em><a name="485" href="#485">485</a> <em>     * @throws IllegalArgumentException</em><a name="486" href="#486">486</a> <em>     */</em><a name="487" href="#487">487</a>     <strong>public</strong> Object getUncheckedAttribute(Object context, String name) {<a name="488" href="#488">488</a>         <strong>try</strong> {<a name="489" href="#489">489</a>             <strong>return</strong> getAttribute(context, name);<a name="490" href="#490">490</a>         } <strong>catch</strong> (AttributeNotFoundException e) {<a name="491" href="#491">491</a>             <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"Was passed '"</span> + name +<a name="492" href="#492">492</a>                 <span class="string">"' and got this exception: "</span> + e);<a name="493" href="#493">493</a>         }<a name="494" href="#494">494</a>     }<a name="495" href="#495">495</a> <a name="496" href="#496">496</a>     <em>/**<em>* Obtain the value of a specific attribute that is valid for a</em></em><a name="497" href="#497">497</a> <em>     * specific CrawlerSettings object.</em><a name="498" href="#498">498</a> <em>     *</em><a name="499" href="#499">499</a> <em>     * This method will try to get the attribute from the supplied host</em><a name="500" href="#500">500</a> <em>     * settings object. If it is not found it will return &lt;code>null&lt;/code></em><a name="501" href="#501">501</a> <em>     * and not try to investigate the hierarchy of settings.</em><a name="502" href="#502">502</a> <em>     *</em><a name="503" href="#503">503</a> <em>     * @param settings the CrawlerSettings object to search for this attribute.</em><a name="504" href="#504">504</a> <em>     * @param name the name of the attribute to be retrieved.</em><a name="505" href="#505">505</a> <em>     * @return The value of the attribute retrieved or null if its not set.</em><a name="506" href="#506">506</a> <em>     * @see CrawlerSettings</em><a name="507" href="#507">507</a> <em>     * @throws AttributeNotFoundException is thrown if the attribute doesn't</em><a name="508" href="#508">508</a> <em>     *         exist.</em><a name="509" href="#509">509</a> <em>     */</em><a name="510" href="#510">510</a>     <strong>public</strong> Object getLocalAttribute(<a href="../../../../org/archive/crawler/settings/CrawlerSettings.html">CrawlerSettings</a> settings, String name)<a name="511" href="#511">511</a>             throws AttributeNotFoundException {<a name="512" href="#512">512</a> <a name="513" href="#513">513</a>         settings = settings == <strong>null</strong> ? globalSettings() : settings;<a name="514" href="#514">514</a> <a name="515" href="#515">515</a>         <a href="../../../../org/archive/crawler/settings/DataContainer.html">DataContainer</a> data = settings.getData(<strong>this</strong>);<a name="516" href="#516">516</a>         <strong>if</strong> (data != <strong>null</strong> &amp;&amp; data.containsKey(name)) {<a name="517" href="#517">517</a>             <em class="comment">// Attribute was found return it.</em><a name="518" href="#518">518</a>             <strong>return</strong> data.get(name);<a name="519" href="#519">519</a>         }<a name="520" href="#520">520</a>         <em class="comment">// Try to find the attribute, will throw an exception if not found.</em><a name="521" href="#521">521</a>         Context context = <strong>new</strong> Context(settings, <strong>null</strong>);<a name="522" href="#522">522</a>         getDataContainerRecursive(context, name);<a name="523" href="#523">523</a>         <strong>return</strong> <strong>null</strong>;<a name="524" href="#524">524</a>     }<a name="525" href="#525">525</a> <a name="526" href="#526">526</a>     <em>/**<em>* Set the value of a specific attribute of the ComplexType.</em></em><a name="527" href="#527">527</a> <em>     *</em><a name="528" href="#528">528</a> <em>     * This method sets the specific attribute for the order file.</em><a name="529" href="#529">529</a> <em>     *</em><a name="530" href="#530">530</a> <em>     * @param attribute The identification of the attribute to be set and the</em><a name="531" href="#531">531</a> <em>     *                  value it is to be set to.</em><a name="532" href="#532">532</a> <em>     * @throws AttributeNotFoundException is thrown if there is no attribute</em><a name="533" href="#533">533</a> <em>     *         with this name.</em><a name="534" href="#534">534</a> <em>     * @throws InvalidAttributeValueException is thrown if the attribute is of</em><a name="535" href="#535">535</a> <em>     *         wrong type and cannot be converted to the right type.</em><a name="536" href="#536">536</a> <em>     * @throws MBeanException this is to conform to the MBean specification, but</em><a name="537" href="#537">537</a> <em>     *         this exception is never thrown, though this might change in the</em><a name="538" href="#538">538</a> <em>     *         future.</em><a name="539" href="#539">539</a> <em>     * @throws ReflectionException this is to conform to the MBean specification, but</em><a name="540" href="#540">540</a> <em>     *         this exception is never thrown, though this might change in the</em><a name="541" href="#541">541</a> <em>     *         future.</em><a name="542" href="#542">542</a> <em>     * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)</em><a name="543" href="#543">543</a> <em>     */</em><a name="544" href="#544">544</a>     <strong>public</strong> <strong>synchronized</strong> <strong>final</strong> <strong>void</strong> setAttribute(Attribute attribute)<a name="545" href="#545">545</a>         throws<a name="546" href="#546">546</a>             AttributeNotFoundException,<a name="547" href="#547">547</a>             InvalidAttributeValueException,<a name="548" href="#548">548</a>             MBeanException,<a name="549" href="#549">549</a>             ReflectionException {<a name="550" href="#550">550</a>         setAttribute(settingsHandler.getSettingsObject(<strong>null</strong>), attribute);<a name="551" href="#551">551</a>     }<a name="552" href="#552">552</a> <a name="553" href="#553">553</a>     <em>/**<em>* Set the value of a specific attribute of the ComplexType.</em></em><a name="554" href="#554">554</a> <em>     *</em><a name="555" href="#555">555</a> <em>     * This method is an extension to the Dynamic MBean specification so that</em><a name="556" href="#556">556</a> <em>     * it is possible to set the value for a CrawlerSettings object other than</em><a name="557" href="#557">557</a> <em>     * the settings object representing the order.</em><a name="558" href="#558">558</a> <em>     *</em><a name="559" href="#559">559</a> <em>     * @param settings the settings object for which this attributes value is valid</em><a name="560" href="#560">560</a> <em>     * @param attribute The identification of the attribute to be set and the</em><a name="561" href="#561">561</a> <em>     *                  value it is to be set to.</em><a name="562" href="#562">562</a> <em>     * @throws AttributeNotFoundException is thrown if there is no attribute</em><a name="563" href="#563">563</a> <em>     *         with this name.</em><a name="564" href="#564">564</a> <em>     * @throws InvalidAttributeValueException is thrown if the attribute is of</em><a name="565" href="#565">565</a> <em>     *         wrong type and cannot be converted to the right type.</em><a name="566" href="#566">566</a> <em>     * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)</em><a name="567" href="#567">567</a> <em>     */</em><a name="568" href="#568">568</a>     <strong>public</strong> <strong>synchronized</strong> <strong>final</strong> <strong>void</strong> setAttribute(<a href="../../../../org/archive/crawler/settings/CrawlerSettings.html">CrawlerSettings</a> settings,<a name="569" href="#569">569</a>             Attribute attribute) throws InvalidAttributeValueException,<a name="570" href="#570">570</a>             AttributeNotFoundException {<a name="571" href="#571">571</a> <a name="572" href="#572">572</a>         <strong>if</strong>(settings==<strong>null</strong>){<a name="573" href="#573">573</a>             settings = globalSettings();<a name="574" href="#574">574</a>         }<a name="575" href="#575">575</a> <a name="576" href="#576">576</a>         <a href="../../../../org/archive/crawler/settings/DataContainer.html">DataContainer</a> data = getOrCreateDataContainer(settings);<a name="577" href="#577">577</a>         Object value = attribute.getValue();<a name="578" href="#578">578</a> <a name="579" href="#579">579</a>         <a href="../../../../org/archive/crawler/settings/ModuleAttributeInfo.html">ModuleAttributeInfo</a> attrInfo = (ModuleAttributeInfo) getAttributeInfo(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -