FileDocCategorySizeDatePackage
MBeanManufacturer.javaAPI DocGlassfish v2 API9066Fri May 04 22:33:54 BST 2007com.sun.enterprise.admin.server.core.jmx.storage

MBeanManufacturer

public class MBeanManufacturer extends Object
A class to construct proper type of MBean from its object name. This class gives the instances of mbeans that would be registered as given object names.

Fields Summary
private ObjectName
mObjectName
private Object
mConfigBean
private com.sun.enterprise.admin.AdminContext
mAdminContext
private static final Logger
_logger
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
public MBeanManufacturer(ObjectName oName, Object configBean)

	

          
    
        if (oName == null || configBean == null)
        {
			String msg = localStrings.getString( "admin.server.core.jmx.storage.null_object_name_or_config_bean" );
            throw new IllegalArgumentException( msg );
        }
        mObjectName = oName;
        mConfigBean = configBean;
    
Methods Summary
private com.sun.enterprise.admin.server.core.mbean.config.ManagedAdminServerInstancecreateAdminServerInstance()

        return new ManagedAdminServerInstance();
    
private java.lang.ObjectcreateGenericConfigMBean(javax.management.ObjectName objectName)

        ConfigMBeanNamingInfo mbeanInfo = new ConfigMBeanNamingInfo(objectName);
        mbeanInfo.setAdminContext(mAdminContext);
        return mbeanInfo.constructConfigMBean();
    
public java.lang.ObjectcreateMBeanInstance()
Returns an instance of proper MBean. This is required, when somebody wants to create the MBean for the first time in MBean Repository. The necessary parameters for MBean construction are derived from the configBean passed during consruction of this class.\

return
instance of proper MBean corresponding to ObjectName. ObjectName is passed during the construction of this class. May not be null.

        Object mbeanInstance = null;
        String instanceName = ApplicationServer.getServerContext().getInstanceName();
        
        //8.0 first 
        if(mConfigBean instanceof MBeanRegistryEntry)
        {
            ConfigContext configContext;
            try
            {
                if (mAdminContext != null) {
                    configContext = mAdminContext.getAdminConfigContext();
                } else {
                    InstanceEnvironment instanceEnvironment = new InstanceEnvironment(instanceName);
                    //String fileUrl  = instanceEnvironment.getConfigFilePath();
                    /*Everything should be set in the backup file*/
                    String fileUrl  = instanceEnvironment.getBackupConfigFilePath();
                    configContext   = ConfigFactory.createConfigContext(fileUrl);
                }
                return ((MBeanRegistryEntry)mConfigBean).instantiateMBean(mObjectName,null, configContext);
            }
            catch(Exception e)
            {
                return null;
            }
        }
        String type         = ObjectNameHelper.getType(mObjectName);
        //String instanceName = ObjectNameHelper.getServerInstanceName(mObjectName);
        Level logLevel = Level.SEVERE;

        try
        {
            if (type.equals(ObjectNames.kController))
            {
                mbeanInstance = new ServerController(mAdminContext);
            }
            else if (type.equals(ObjectNames.kGenericConfigurator))
            {
                mbeanInstance = new GenericConfigurator();
            }
            else if (type.equals(ObjectNames.kServerInstance))
            {
                mbeanInstance = createServerInstanceMBean(instanceName);
/* *************** **
                if (instanceName.equals(ServerManager.ADMINSERVER_ID))
                {
                    mbeanInstance = createAdminServerInstance();
                }
                else
                {
                    mbeanInstance = createServerInstanceMBean(instanceName);
                }
** *************** */
            }
            else 
            {
                logLevel = Level.FINE;
                mbeanInstance = createGenericConfigMBean(mObjectName);
            }
        }
        catch(Exception e)
        {
            _logger.log(logLevel, "mbean.config.admin.create_mbean_instance_failed",  e );
        }
        
        return ( mbeanInstance );
    
private com.sun.enterprise.admin.server.core.mbean.config.ManagedServerInstancecreateServerInstanceMBean(java.lang.String instanceName)

        Server server = (Server)mConfigBean;
//patch for ms1
ConfigContext ctx = server.getConfigContext();
Config          config  = (Config) ConfigBeansFactory.getConfigBeanByXPath(ctx, ServerXPathHelper.XPATH_CONFIG);
        HttpService https = config.getHttpService();
        
        HttpListener[] hlArray = https.getHttpListener();
        //check not needed since there should always be atleast 1 httplistener
        //if you don't find one, use first one.
        HttpListener ls = hlArray[0];  
        //default is the first one that is enabled.
        for(int i = 0;i<hlArray.length;i++) {
            if(hlArray[i].isEnabled()) {
                ls = hlArray[i];
                break;
            }
        }
        String port = new PropertyResolver(ctx, instanceName).
                resolve(ls.getPort());
        int intPort = Integer.parseInt (port);
        HostAndPort hp = new HostAndPort("localhost", intPort);
        return new ManagedServerInstance(instanceName, hp, false, mAdminContext);
    
public voidsetAdminContext(com.sun.enterprise.admin.AdminContext ctx)

        mAdminContext = ctx;