0

我试图在一个名为 Display.java 的类中理解以下代码:

    Map<String,Object> context = (Map<String,Object>) globalSession.get("cascadas.ace.context");
    if(context != null) {
      dresscode = (String) context.get("dresscode");
      hobby = (String) context.get("hobby");
    }
    if ((hobby == null) || (dresscode == null)) {
        SystemConfiguration.getInstance().getLog().warning("Advertisement display: dresscode and/or hobby not available, no image will be displayed.");
    }

正在发生的事情是有一个 GUI 窗口,允许您为着装要求和爱好选择单选按钮。但是不知何故,当我在程序文本中添加另一个虚拟单选按钮时(在与 Display.java 位于同一文件夹中的类中,称为 ContextSimulatorGUI ,它甚至不显示 GUI 窗口.. ,我在控制台中看到以下内容:

Advertisement display: dresscode and/or hobby not available, no image will be displayed."

关于globalSession变量..它是一个“会话”对象;在项目中有一个名为 的类Session,如下所示:

/* * ACE Autonomic Toolkit *(又名 CASCADAS ACE Toolkit)* * 由 CASCADAS 项目工作包 1 创建:* - 布达佩斯科技与经济大学 * - 弗劳恩霍夫研究所 FOKUS * - 意大利电信实验室 * - 卡塞尔大学 * - 卡塞尔大学摩德纳和雷焦艾米利亚 * * 更多信息请访问: * - http://acetoolkit.sourceforge.net

 *  - http://cascadas-project.org
 *
 * The authors would like to acknowledge the European Commission 
 * for funding the Integrated Project CASCADAS Component-ware for 
 * Autonomic, Situation-aware Communications, And Dynamically 
 * Adaptable Services (FET Proactive Initiative, IST-2004-2.3.4 
 * Situated and Autonomic Communications) within the 6th IST Framework 
 * Program. The authors also wish to thank other project Partners for 
 * the fruitful cooperation within the project.
 */

package cascadas.ace.session;

import java.io.Serializable;
import java.util.Map;

/**
 * Interface describing the session context.
 */
// TODO: use generics for type safety stuff?
public interface Session extends Serializable {

        /**
         * Returns the name of the SessionContext.
         *
         * @return the name
         */
        public String getName();


        /**
         * Removes the key-value pair from the session.
         * @param key param name
         */
        public void remove(String key);


        /**
         * Returns the current state.
         *
         * @return curretn state
         */
//        public State getState(); 


        /**
         * Sets the current state.
         *
         * @param s the state
         */
 //       public void setState(State s);


        /**
         * Returns the contract with the specified id.
         *
         * @param contract id
         * @return contract
         * @throws SessionContextNotFoundException if contract is not found
         */
//        public Contract getContract(String id) throws SessionNotFoundException; 


        /**
         * Adds a contract with the given id. Id must be unique.
         *
         * @param s the state
         */
//        public void addContract(String id, Contract c);


        /**
         * Returns all contracts.
         *
         * @return id-->contract map
         */
//        public Map<String,Contract> getAllContracts();


        /**
         * Puts a piece of data to the session context.
         * Overwrites existing data with teh same name.
         *
         * @param id name of the data
         * @param value value of the data
         */
        public void put( String id, Object value ) throws SessionException;


        /**
         * Puts an integer value into the session context.
         *
         * @param id name
         * @param value value
         */
        public void put ( String id, int        value );


        /**
         * Puts a double value into the session context.
         *
         * @param id name
         * @param value value
         */
        public void put ( String id, double     value );


        /**
         * Puts a float into the session context.
         *
         * @param id name
         * @param value value
         */
       public void put ( String id, float      value );


        /**
         * Puts a long value into the session context.
         *
         * @param id name
         * @param value value
         */
        public void put ( String id, long       value );


        /**
         * Puts a short value into the session context.
         *
         * @param id name
         * @param value value
         */
        public void put ( String id, short      value );


        /**
         * Puts a char into the session context.
         *
         * @param id name
         * @param value value
         */
        public void put ( String id, char       value );


        /**
         * Puts a boolean value into the session context.
         *
         * @param id name
         * @param value value
         */
        public void put ( String id, boolean    value );




        /**
         * Returns the matching data from the session context.
         *
         * @param id name of the data
         * @return the data as an Object or null if not found
         */
        public Object get (String id) ;


        /**
         * Returns the matching data from the session context.
         *
         * @param id name of the data
         * @throws cascadas.ace.reasoner.SessionContextException 
         *              if an error occurs
         * @return the data as an integer or 0 if not found
         */
        public int getInt ( String id) throws SessionException;


        /**
         * Returns the matching data from the session context.
         *
         * @param id name of the data
         * @throws cascadas.ace.reasoner.SessionContextException 
         *              if an error occurs
         * @return the data as a double
         */
        public double getDouble ( String id) throws SessionException;


        /**
         * Returns the matching data from the session context.
         *
         * @param id name of the data
         * @throws cascadas.ace.reasoner.SessionContextException 
         *              if an error occurs
         * @return the data as a float
         */
        public float getFloat ( String id) throws SessionException;


        /**
         * Returns the matching data from the session context.
         *
         * @param id name of the data
         * @throws cascadas.ace.reasoner.SessionContextException 
         *              if an error occurs
         * @return the data as a long
         */
        public long getLong ( String id) throws SessionException;


        /**
         * Returns the matching data from the session context.
         *
         * @param id name of the data
         * @throws cascadas.ace.reasoner.SessionContextException 
         *              if an error occurs
         * @return the data as a short
         */
        public short getShort ( String id) throws SessionException;


        /**
         * Returns the matching data from the session context.
         *
         * @param id name of the data
         * @throws cascadas.ace.reasoner.SessionContextException 
         *              if an error occurs
         * @return the data as a char
         */
        public char getChar ( String id) throws SessionException;


        /**
         * Returns the matching data from the session context.
         *
         * @param id name of the data
         * @throws cascadas.ace.reasoner.SessionContextException 
         *              if an error occurs
         * @return the data as a boolean
         */
        public boolean getBoolean ( String id) throws SessionException;


         /**
         * Returns the matching data from the session context.
         *
         * @param id name of the data
         * @throws cascadas.ace.reasoner.SessionContextException 
         *              if an error occurs
         * @return the data as a String
         */
        public String getString ( String id) throws SessionException;


        /**
         * Returns all data as a set.
         * @return all data in the session context
         */
        public Map<String,Object>  getAllData();

        /**
         * Sets the ace name (for debug messages).
         * @param aceName ace name
         */
        public void setAceName(String aceName);

}

..etc(顺便说一句,我知道源代码有点草率,但它是一些开源项目,而不是我的代码)。

所以总结一下,我主要想了解最上面的代码,最下面的东西是上下文。我希望这不会令人困惑 - 我感谢任何提示或建议。

4

0 回答 0