ServerCheckImpl.jcs Sample

This topic inludes the source code for the ServerCheckImpl.jcs Sample.

Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/ExtensionDevKit/ControlDevKit/ControlFeatures/insertWizard/

Sample Source Code


01 package insertWizard; 
02 
03 import com.bea.control.*;
04 import weblogic.management.MBeanHome;
05 import weblogic.management.Helper;
06 import weblogic.management.WebLogicMBean;
07 import weblogic.management.WebLogicObjectName;
08 
09 /**
10  * The ServerCheck control illustrates how to connect a custom
11  * dialog box that will be used to collect attribute values
12  * when the control is added to a project. This control doesn't
13  * create a JCX file; its property annotations are specified
14  * at the control instance level, inside the control's container.
15  
16  * The ServerCheckWizard class provides the hooks needed by WebLogic 
17  * Workshop to show a dialog box, get and set attribute values, and
18  * so on. The ServerCheckWizardPanel provides the insert wizard's user
19  * interface components.
20  
21  * This control is designed to use a WebLogic Server MBean to
22  * return the server's domain name. The control's property
23  * attributes are the server's name and URL, as well as a user name
24  * and password to be used if needed.
25  
26  * @jcs:control-tags file="ServerCheck-tags.xml"
27  * @jcs:jc-jar label="ServerCheck"
28  *      insert-wizard-class="insertWizard.ide.ServerCheckWizard"
29  *      version="0.8" 
30  *      icon-16="/images/hello_16.gif" 
31  *      icon-32="/images/hello_32.gif"
32  *      palette-priority="6" 
33  *      group-name="Feature Sample Controls"
34  *      description="Illustrates custom insert wizard"
35  *      @editor-info:code-gen control-interface="true"
36  */
37 public class ServerCheckImpl implements ServerCheck, com.bea.control.ControlSource
38 
39     /**
40      * @common:context
41      */
42     com.bea.control.ControlContext context;
43 
44     /* 
45      * Variables to hold values specified by the control's user.
46      */
47     String m_serverURL = null;
48     String m_userName = null;
49     String m_password = null;
50     String m_serverName = null;
51     transient MBeanHome m_localMBean = null;
52 
53     /**
54      * The getDomainName method is the control's only operation.
55      * It uses an external class, MBeanUtil, to get the server's 
56      * domain name.
57      
58      * @common:operation
59      */
60     public String getDomainName ()
61     {
62         /* 
63          * The context.getControl attribute method retrieves values 
64          * specified in annotations on the control instance declaration.
65          * These annotations are written into the control's container.
66          */
67         m_userName = context.getControlAttribute("jc:server-data","user-name");
68         m_password = context.getControlAttribute("jc:server-data","password");
69         m_serverURL = context.getControlAttribute("jc:server-data","url");
70         m_serverName = context.getControlAttribute("jc:server-data","server-name");
71         
72         try {
73             m_localMBean = MBeanUtil.getMBean(m_userName, m_password, m_serverURL, m_serverName);
74         catch (IllegalArgumentException iae) {
75             context.getLogger("ServerCheck");
76             throw new ControlException("ServerCheck: Error getting the domain name.", iae);
77         }
78         String domainName = m_localMBean.getDomainName();
79         return domainName;
80     }
81