在这个java项目源代码中检查Map变量

时间:2012-10-21 14:35:56

标签: java eclipse debugging

我正在尝试在名为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  *(a.k.a CASCADAS ACE工具包)  *  *由CASCADAS项目工作包1创建:  * - 布达佩斯技术经济大学  * - Fraunhofer Institut 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);

}

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

总而言之,我主要想要理解最顶层的代码,底层的东西就是上下文。我希望这不会令人困惑 - 我感谢任何提示或建议。

0 个答案:

没有答案
相关问题