Constructor Template

From C3LearningLabs

Start - System Objects - Constructor - Finalize - Data Fields - UILayout - xmlCom - Server Client Configuration - GameLoop - TopPanelUI - ConfigGlobalData - Message - Manager

The constructor template contain the methods that construct and initialise the class.


Main Code

Insert the code after the system objects code block.

// ============================================================================================
// =                                       Constructor                                        =
// ============================================================================================    
    
/**
 * Constructor
 */
public Xxx(){
    /*LOG*/ System.out.println("Xxx.XxxBegin");
    /*LOG*/ System.out.println("Xxx.XxxEnd");
}
    
/**
 * Initialize object.
 * Should be called after all system objects are set.
 */
public void doInit(){
    /*LOG*/ systemObjects_Env.getTraceLog().finer("Begin");
    /*LOG*/ systemObjects_Env.getTraceLog().finer("End");
}



Optional Code

Special doInit_() methods that can be needed.

    

/**
 * Update the session objects for all objects in the storage..
 */
public void doInit_UpdateSessionObjects(){
    for (int i=0; i<unitVector.size(); i++) {
        ((UnitData) unitVector.elementAt(i)).systemObjects_SetEnv(systemObjects_Env);
        ((UnitData) unitVector.elementAt(i)).systemObjects_SetManagers(systemObjects_Mgrs);
        ((UnitData) unitVector.elementAt(i)).systemObjects_SetSessionData(systemObjects_SessionData);
    }
}

/**
 * Initialise object when SessionData created.
 * Should be called after SessionData are created, but not all data ready.
 */
public void doInit_SessionDataCreated(){
    /*LOG*/ systemData_Env.getTraceLog().finer("Begin");
    /*LOG*/ systemData_Env.getTraceLog().finer("End");
}

/**
 * Initialise objectwith SessionData ready.
 * Should be called after all objects in SessionData are set.
 */
public void doInit_SessionDataReady(){
    /*LOG*/ systemData_Env.getTraceLog().finer("Begin");
    /*LOG*/ systemData_Env.getTraceLog().finer("End");
}

/**
 * Initialise object when ModuleData ready.
 * Should be called after ModuleData are created and ready.
 */
public void doInit_ModuleDataReady(){
    /*LOG*/ systemData_Env.getTraceLog().finer("Begin");
    /*LOG*/ systemData_Env.getTraceLog().finer("End");
}


/**
 * Initialise object when MapData ready.
 * Should be called after MapData are created and ready.
 */
public void doInit_MapDataReady(){
    /*LOG*/ systemData_Env.getTraceLog().finer("Begin");
    /*LOG*/ systemData_Env.getTraceLog().finer("End");
}

/**
 * Initialise object when User Interface ready.
 * Should be called after User Interface are created and ready.
 */
public void doInit_UIReady(){
    /*LOG*/ systemData_Env.getTraceLog().finer("Begin");
    /*LOG*/ systemData_Env.getTraceLog().finer("End");
}

/**
 * Initialise object when ZoneData ready.
 * Should be called after ZoneData are created and ready.
 */
public void doInit_ZoneDataReady(){
    /*LOG*/ systemData_Env.getTraceLog().finer("Begin");
    /*LOG*/ systemData_Env.getTraceLog().finer("End");
}

External code

Manager.java

Update the manager c3systems.global.env.Manager.java with the calls to the constructor methods.
These methods should set the needed objects, do the construction and the initialization of the object.

Example code

     
// -------------
// SystemLoadMgr
// -------------

/**
 * SystemLoad objects is used to logging and display the system Load parameters.
 */
private c3systems.tools.logging.systemLoad.SystemLoadMgr systemLoadMgr = null;

/**
 * Get method for systemLoadMgr.
 * @returns systemLoadMgr that is used to mange the system systemLoad parameters.
 */    
public c3systems.tools.logging.systemLoad.SystemLoadMgr getSystemLoadMgr(){
    return systemLoadMgr;
}    

/**
 * Creates systemLoadMgr.
 * @param isServer True if the instance is the C3Fire server.
 */    
public void createSystemLoadMgr(boolean isServer){
    //LOG// System.out.println("Managers.createSystemLoadMgr");
    env.processTextInsertTextAddSystemState("Create SystemLoad Mgr\n\r");
    systemLoadMgr = new c3systems.tools.logging.systemLoad.SystemLoadMgr();
    systemLoadMgr.systemData_SetEnv(env);
    systemLoadMgr.systemData_SetManagers(this);        
    systemLoadMgr.doInit(isServer);  
} 

/**
 * Update SystemLoadMgr with SessionData Ready. <BR>
 * Should be called after SessionData are crested and ready.
 * @param sessionData SessionData containing all data connected to the current session.
 */    
public void updateSystemLoadMgrWithSessionDataReady(c3systems.global.sessionData.SessionData sessionData){
    //LOG// System.out.println("Managers.updateSystemLoadMgrWithSessionDataReady Begin");
    //LOG// System.out.println("Managers.updateSystemLoadMgrWithSessionDataReady (ui2DMgr == null) "+ (ui2DMgr == null));
    //LOG// System.out.println("Managers.updateSystemLoadMgrWithSessionDataReady (systemLoadMgr == null) "+ (systemLoadMgr == null));
    if (systemLoadMgr != null){
        env.processTextInsertTextAddSystemState("Update SystemLoad Manager With Session Data\n\r");            
        systemLoadMgr.systemData_SetSessionData(sessionData);
        // systemLoadMgr.setConnection(env.);
        systemLoadMgr.systemData_SetRoleIDNr(sessionData.getRoleIDNr());
        systemLoadMgr.doInit_SessionDataReady();  
    }
    //LOG// System.out.println("Managers.updateSystemLoadMgrWithSessionDataReady End");
}   

/**
 * Update SystemLoadMgr with Connections. <BR>
 * Should be called after all connections are crested.
 */    
public void updateSystemLoadMgrWithConnections(
    c3systems.global.clientData.ClientDataStorage clientDataStorage, 
    c3systems.global.clientData.ClientDataStorage xmlClientDataStorage, 
    c3systems.global.manager.ManagerDataStorage managerDataStorage, 
    c3systems.global.observer.ObserverDataStorage observerDataStorage){

    if (systemLoadMgr != null){
        systemLoadMgr.systemData_SetClientDataStorage(clientDataStorage);
        systemLoadMgr.systemData_SetManagerDataStorage(managerDataStorage);
        systemLoadMgr.systemData_SetObserverDataStorage(observerDataStorage);
        systemLoadMgr.systemData_SetXmlClientDataStorage(xmlClientDataStorage); 
    }
}

/**
 * Parse SystemLoad configuration Data for server. <BR>
 * @param ht hash table containing SystemLoad Data Configuration for the Server.
 */
public void parseSystemLoadDataConfigurationServer(java.util.Hashtable ht, c3systems.tools.config.configCheck.ConfigCheckInterface configCheckOutput) {
    systemLoadMgr.config_ParseConfigurationServer(ht, configCheckOutput);
}

/**
 * Parse SystemLoad configuration Data for client. <BR>
 * @param ht hash table containing SystemLoad Data Configuration for the Client.
 */
public void parseSystemLoadDataConfigurationClient(java.util.Hashtable ht, c3systems.tools.config.configCheck.ConfigCheckInterface configCheckOutput) {
    systemLoadMgr.config_ParseConfigurationClient(ht, configCheckOutput);
}