📄 objectmbean.html
字号:
<a name="396" href="#396">396</a> <strong class="jxr_keyword">throws</strong> ListenerNotFoundException {<a name="397" href="#397">397</a> }<a name="398" href="#398">398</a> <a name="399" href="#399">399</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> load() <strong class="jxr_keyword">throws</strong> InstanceNotFoundException, MBeanException,<a name="400" href="#400">400</a> RuntimeOperationsException {<a name="401" href="#401">401</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> RuntimeOperationsException(<strong class="jxr_keyword">new</strong> UnsupportedOperationException());<a name="402" href="#402">402</a> }<a name="403" href="#403">403</a> <a name="404" href="#404">404</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> store() <strong class="jxr_keyword">throws</strong> InstanceNotFoundException, MBeanException,<a name="405" href="#405">405</a> RuntimeOperationsException {<a name="406" href="#406">406</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> RuntimeOperationsException(<strong class="jxr_keyword">new</strong> UnsupportedOperationException());<a name="407" href="#407">407</a> }<a name="408" href="#408">408</a> <a name="409" href="#409">409</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> ObjectName preRegister(MBeanServer server, ObjectName name)<a name="410" href="#410">410</a> <strong class="jxr_keyword">throws</strong> Exception {<a name="411" href="#411">411</a> <strong class="jxr_keyword">this</strong>.server = server;<a name="412" href="#412">412</a> <strong class="jxr_keyword">this</strong>.name = name;<a name="413" href="#413">413</a> <strong class="jxr_keyword">return</strong> name;<a name="414" href="#414">414</a> }<a name="415" href="#415">415</a> <a name="416" href="#416">416</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">void</strong> postRegister(Boolean registrationDone) {<a name="417" href="#417">417</a> <strong class="jxr_keyword">if</strong> (registrationDone) {<a name="418" href="#418">418</a> sources.put(name, source);<a name="419" href="#419">419</a> }<a name="420" href="#420">420</a> }<a name="421" href="#421">421</a> <a name="422" href="#422">422</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">void</strong> preDeregister() <strong class="jxr_keyword">throws</strong> Exception {<a name="423" href="#423">423</a> }<a name="424" href="#424">424</a> <a name="425" href="#425">425</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">void</strong> postDeregister() {<a name="426" href="#426">426</a> sources.remove(name);<a name="427" href="#427">427</a> <strong class="jxr_keyword">this</strong>.server = <strong class="jxr_keyword">null</strong>;<a name="428" href="#428">428</a> <strong class="jxr_keyword">this</strong>.name = <strong class="jxr_keyword">null</strong>;<a name="429" href="#429">429</a> }<a name="430" href="#430">430</a> <a name="431" href="#431">431</a> <strong class="jxr_keyword">private</strong> MBeanInfo createModelMBeanInfo(T source) {<a name="432" href="#432">432</a> String className = source.getClass().getName();<a name="433" href="#433">433</a> String description = <span class="jxr_string">""</span>;<a name="434" href="#434">434</a> <a name="435" href="#435">435</a> ModelMBeanConstructorInfo[] constructors = <strong class="jxr_keyword">new</strong> ModelMBeanConstructorInfo[0];<a name="436" href="#436">436</a> ModelMBeanNotificationInfo[] notifications = <strong class="jxr_keyword">new</strong> ModelMBeanNotificationInfo[0];<a name="437" href="#437">437</a> <a name="438" href="#438">438</a> List<ModelMBeanAttributeInfo> attributes = <strong class="jxr_keyword">new</strong> ArrayList<ModelMBeanAttributeInfo>();<a name="439" href="#439">439</a> List<ModelMBeanOperationInfo> operations = <strong class="jxr_keyword">new</strong> ArrayList<ModelMBeanOperationInfo>();<a name="440" href="#440">440</a> <a name="441" href="#441">441</a> addAttributes(attributes, source);<a name="442" href="#442">442</a> addExtraAttributes(attributes);<a name="443" href="#443">443</a> <a name="444" href="#444">444</a> addOperations(operations, source);<a name="445" href="#445">445</a> addExtraOperations(operations);<a name="446" href="#446">446</a> operations.add(<strong class="jxr_keyword">new</strong> ModelMBeanOperationInfo(<a name="447" href="#447">447</a> <span class="jxr_string">"unregisterMBean"</span>, <span class="jxr_string">"unregisterMBean"</span>,<a name="448" href="#448">448</a> <strong class="jxr_keyword">new</strong> MBeanParameterInfo[0], <strong class="jxr_keyword">void</strong>.<strong class="jxr_keyword">class</strong>.getName(), <a name="449" href="#449">449</a> ModelMBeanOperationInfo.ACTION));<a name="450" href="#450">450</a> <a name="451" href="#451">451</a> <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> ModelMBeanInfoSupport(<a name="452" href="#452">452</a> className, description,<a name="453" href="#453">453</a> attributes.toArray(<strong class="jxr_keyword">new</strong> ModelMBeanAttributeInfo[attributes.size()]),<a name="454" href="#454">454</a> constructors,<a name="455" href="#455">455</a> operations.toArray(<strong class="jxr_keyword">new</strong> ModelMBeanOperationInfo[operations.size()]),<a name="456" href="#456">456</a> notifications);<a name="457" href="#457">457</a> }<a name="458" href="#458">458</a> <a name="459" href="#459">459</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> addAttributes(<a name="460" href="#460">460</a> List<ModelMBeanAttributeInfo> attributes, Object object) {<a name="461" href="#461">461</a> addAttributes(attributes, object, object.getClass(), <span class="jxr_string">""</span>);<a name="462" href="#462">462</a> }<a name="463" href="#463">463</a> <a name="464" href="#464">464</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> addAttributes(<a name="465" href="#465">465</a> List<ModelMBeanAttributeInfo> attributes,<a name="466" href="#466">466</a> Object object, Class<?> type, String prefix) {<a name="467" href="#467">467</a> <a name="468" href="#468">468</a> PropertyDescriptor[] pdescs;<a name="469" href="#469">469</a> <strong class="jxr_keyword">try</strong> {<a name="470" href="#470">470</a> pdescs = Introspector.getBeanInfo(type).getPropertyDescriptors();<a name="471" href="#471">471</a> } <strong class="jxr_keyword">catch</strong> (IntrospectionException e) {<a name="472" href="#472">472</a> <strong class="jxr_keyword">return</strong>;<a name="473" href="#473">473</a> }<a name="474" href="#474">474</a> <a name="475" href="#475">475</a> <strong class="jxr_keyword">for</strong> (PropertyDescriptor pdesc: pdescs) {<a name="476" href="#476">476</a> <em class="jxr_comment">// Ignore a write-only property.</em><a name="477" href="#477">477</a> <strong class="jxr_keyword">if</strong> (pdesc.getReadMethod() == <strong class="jxr_keyword">null</strong>) {<a name="478" href="#478">478</a> <strong class="jxr_keyword">continue</strong>;<a name="479" href="#479">479</a> }<a name="480" href="#480">480</a> <a name="481" href="#481">481</a> <em class="jxr_comment">// Ignore unmanageable property.</em><a name="482" href="#482">482</a> String attrName = pdesc.getName();<a name="483" href="#483">483</a> Class<?> attrType = pdesc.getPropertyType();<a name="484" href="#484">484</a> <strong class="jxr_keyword">if</strong> (attrName.equals(<span class="jxr_string">"class"</span>)) {<a name="485" href="#485">485</a> <strong class="jxr_keyword">continue</strong>;<a name="486" href="#486">486</a> }<a name="487" href="#487">487</a> <strong class="jxr_keyword">if</strong> (!isReadable(type, attrName)) {<a name="488" href="#488">488</a> <strong class="jxr_keyword">continue</strong>;<a name="489" href="#489">489</a> }<a name="490" href="#490">490</a> <a name="491" href="#491">491</a> <em class="jxr_comment">// Expand if possible.</em><a name="492" href="#492">492</a> <strong class="jxr_keyword">if</strong> (isExpandable(type, attrName)) {<a name="493" href="#493">493</a> expandAttribute(attributes, object, prefix, pdesc);<a name="494" href="#494">494</a> <strong class="jxr_keyword">continue</strong>;<a name="495" href="#495">495</a> }<a name="496" href="#496">496</a> <a name="497" href="#497">497</a> <em class="jxr_comment">// Ordinary property.</em><a name="498" href="#498">498</a> String fqan = prefix + attrName;<a name="499" href="#499">499</a> <strong class="jxr_keyword">boolean</strong> writable = isWritable(type, pdesc);<a name="500" href="#500">500</a> attributes.add(<strong class="jxr_keyword">new</strong> ModelMBeanAttributeInfo(<a name="501" href="#501">501</a> fqan, convertType(<a name="502" href="#502">502</a> object.getClass(), attrName, attrType, writable).getName(),<a name="503" href="#503">503</a> pdesc.getShortDescription(), <strong class="jxr_keyword">true</strong>, writable, false));<a name="504" href="#504">504</a> <a name="505" href="#505">505</a> propertyDescriptors.put(fqan, pdesc);<a name="506" href="#506">506</a> }<a name="507" href="#507">507</a> }<a name="508" href="#508">508</a> <a name="509" href="#509">509</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">boolean</strong> isWritable(Class<?> type, PropertyDescriptor pdesc) {<a name="510" href="#510">510</a> <strong class="jxr_keyword">if</strong> (type == <strong class="jxr_keyword">null</strong>) {<a name="511" href="#511">511</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> NullPointerException(<span class="jxr_string">"type"</span>);<a name="512" href="#512">512</a> }<a name="513" href="#513">513</a> <strong class="jxr_keyword">if</strong> (pdesc == <strong class="jxr_keyword">null</strong>) {<a name="514" href="#514">514</a> <strong class="jxr_keyword">return</strong> false;<a name="515" href="#515">515</a> }<a name="516" href="#516">516</a> String attrName = pdesc.getName();<a name="517" href="#517">517</a> Class<?> attrType = pdesc.getPropertyType();<a name="518" href="#518">518</a> <strong class="jxr_keyword">boolean</strong> writable = pdesc.getWriteMethod() != <strong class="jxr_keyword">null</strong> || isWritable(type, attrName);<a name="519" href="#519">519</a> <strong class="jxr_keyword">if</strong> (getPropertyEditor(type, attrName, attrType) == <strong class="jxr_keyword">null</strong>) {<a name="520" href="#520">520</a> writable = false;<a name="521" href="#521">521</a> }<a name="522" href="#522">522</a> <strong class="jxr_keyword">return</strong> writable;<a name="523" href="#523">523</a> }<a name="524" href="#524">524</a> <a name="525" href="#525">525</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> expandAttribute(<a name="526" href="#526">526</a> List<ModelMBeanAttributeInfo> attributes,<a name="527" href="#527">527</a> Object object, String prefix, PropertyDescriptor pdesc) {<a name="528" href="#528">528</a> Object property;<a name="529" href="#529">529</a> String attrName = pdesc.getName();<a name="530" href="#530">530</a> <strong class="jxr_keyword">try</strong> {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -