View Javadoc

    1   /*
    2    * All Rights Reserved.
    3    * Copyright (C) 1999-2005 Tsukuba Bunko.
    4    *
    5    * Licensed under the BSD License ("the License"); you may not use
    6    * this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    *       http://www.tsukuba-bunko.org/licenses/LICENSE.txt
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   * $Id: NextSceneMapping.java,v 1.2 2005/07/23 18:56:03 ppoi Exp $
    18   */
    19  package tsukuba_bunko.peko.scenario;
    20
    21  import	java.io.Serializable;
    22
    23  import	java.util.Iterator;
    24  import	java.util.List;
    25  import	java.util.Map;
    26
    27  import	tsukuba_bunko.peko.Logger;
    28
    29
    30  /***
    31   * @author	${Author}$
    32   * @version	${Revision}$
    33   */
    34  public class NextSceneMapping	implements Serializable	{
    35
    36  	/***
    37  	 * serial version UID
    38  	 */
    39  	private static final long	serialVersionUID	= -3896489854104011813L;
    40
    41  	/***
    42  	 * 評価の順番
    43  	 */
    44  	private List	_conditionList = new java.util.ArrayList();
    45
    46  	/***
    47  	 * シーン遷移先表
    48  	 */
    49  	private Map	_nextScenes = new java.util.HashMap();
    50
    51
    52  	/***
    53  	 * <code>NextSceneMapping</code> のインスタンスを生成します。
    54  	 */
    55  	public NextSceneMapping()
    56  	{
    57  	}
    58
    59
    60  	public void addNextSceneMapping( String condition, String nextScene )
    61  	{
    62  		if( _conditionList.contains(condition) )	{
    63  			Logger.warn( MessageIDs.SCN0010W, new Object[]{condition, _nextScenes.get(condition), nextScene} );
    64  		}
    65  		else	{
    66  			_conditionList.add( condition );
    67  			_nextScenes.put( condition, nextScene );
    68  		}
    69  	}
    70
    71  	public void setDefaultSceneMapping( String nextScene )
    72  	{
    73  		setDefaultSceneMapping( nextScene, true );
    74  	}
    75
    76  	public void setDefaultSceneMapping( String nextScene, boolean warn )
    77  	{
    78  		if( _nextScenes.containsKey(null) && warn )	{
    79  			Logger.warn( MessageIDs.SCN0010W, new Object[]{"_default_", _nextScenes.get(null), nextScene} );
    80  		}
    81  		else	{
    82  			_nextScenes.put( null, nextScene );
    83  		}
    84  	}
    85
    86  	public String getNextScene( SceneContext context )
    87  	{
    88  		Iterator	itr = _conditionList.iterator();
    89  		String	condition = null;
    90  		while( itr.hasNext() )	{
    91  			condition = (String)itr.next();
    92  			if( PSMLUtil.isEvaluatable(condition, context) )	{
    93  				return (String)_nextScenes.get( condition );
    94  			}
    95  		}
    96  		return (String)_nextScenes.get( null );
    97  	}
    98  }