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

📄 statemachine.java

📁 《Java网络程序设计.rar》包括三个网络程序的源代码。
💻 JAVA
字号:
/**/package org.impact.stars.control.ejb;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.ejb.SessionContext;import java.util.Collection;import java.util.HashMap;import org.impact.stars.util.Debug;import org.impact.stars.control.event.StarsEvent;import org.impact.stars.control.exceptions.StarsEventException;/** * This class is a Universal front back end of an application * which ties all EJB components together dynamically at runtime. * * This class should not be updated to handle various event types. * This class will use ActionControllers to handle events that require * processing beyond the scope of this class. * * A second option to event handling is to do so in the XML descriptor * itself. * * State may be stored in the attributeMap * Configuration of this file is via an XML descriptor. * */public class StateMachine implements java.io.Serializable {    private UserControllerBean usercejb;    private ModelUpdateManager mum;    private HashMap orderTable;    private HashMap attributeMap;    private HashMap controllerMap;    private SessionContext sc;    public StateMachine(UserControllerBean usercejb, SessionContext sc) {        this.usercejb = usercejb;        this.sc = sc;        this.mum = new ModelUpdateManager();        attributeMap = new HashMap();        controllerMap = new HashMap();    }    public Collection handleEvent(StarsEvent ese) throws StarsEventException{        String eventName = ese.getEventName();        Debug.println("StateMachine: received event name= " + eventName);               if (eventName != null) {            Debug.println("StateMachine: processingEvent= " + eventName);            String controllerName = getControllerName(eventName);            Debug.println("StateMachine: process controller class = " + controllerName);            StateController controller = null;            try {                 if (controllerMap.get(eventName) != null) {                     Debug.println("Controller exists");                                         controller = (StateController)controllerMap.get(eventName);                 } else {                     controller = (StateController)Class.forName(controllerName).newInstance();                     Debug.println("StateMachine: loading Controller");                     /*                     ConceptController conceptController=(ConceptController)Class.forName(controllerName).newInstance();                     Debug.println("Casting conceptController");                     controller = (StateController)conceptController;                     controller = (StateController)Class.forName("org.impact.stars.control.ejb.ConceptController").newInstance();*/                     controllerMap.put(eventName, controller);             }            } catch (Exception ex) {                Debug.println("StateMachine: error loading " + controllerName + "Exception :" + ex);            }            if (controller != null) {                                    Debug.println("StateMachine: loaded controller " + controllerName);                controller.init(this);                Debug.println("StateMachine: initialzied " + controllerName);                // do the magic                controller.doStart();                controller.perform(ese);                controller.doEnd();                Debug.println("StateMachine: sucessfully processed :" + eventName);            }            else            {                Debug.println("StateMachine: no controller found");            }        }        return (mum.getUpdatedModels(ese));    }    private String getControllerName(String eventName) {        // do the lookup        Debug.println("StateMachine: looking up:" + eventName + "<");        try {                    InitialContext ic = new InitialContext();                    return  (String)ic.lookup(eventName);        } catch (javax.naming.NamingException ex) {                   Debug.println("Controller caught: " + ex);                    // ignore.. we are working around it below.        }        return null;    }    public void setAttribute(String key, Object value) {        attributeMap.put(key, value);    }    public Object getAttribute(String key) {        return attributeMap.get(key);    }    public UserControllerBean getUserControllerBean() {        return usercejb;    }    public SessionContext getSessionContext() {        return sc;    }}

⌨️ 快捷键说明

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