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

📄 itinerary.java

📁 移动Agent编程工具Naplet
💻 JAVA
字号:

/* 
 * @<#>Itinerary.java version 0.0.1, 1/1/2000
 *
 * THIS PROGRAM IS FREE SOFTWARE; YOU CAN DISTRIBUTE IT AND/OR
 * MODIFY IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE 
 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION.
 *
 * THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
 * BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE 
 * GNU GENERAL PUBLIC LICENSE FOR MORE DETAILS.
 *
 * Copyright (c) 2000 Wayne State University. All Rights Reserved.
 */

package naplet.itinerary;

/**
 * The <code>Itinerary</code> class defines a base of itineraries that
 * are to be associated with naplets. 
 *
 * @version 0.0.1, 1/1/2000
 * @author C. Xu
 */

import java.util.Stack;
import java.rmi.RemoteException;
import naplet.*;

public class Itinerary implements java.io.Serializable, Cloneable {
	/**
	 * Current route (itinerary) the naplet is on
	 */
	private ItineraryPattern current;

	/**
	 * Routes the naplet has been on. The are maintained in a stack due to
	 * recursive nature of itinerary patterns.
	 */
	private Stack routeStack;

	/**
	 * Constructs an empty Itinerary. It is instantiated by 
	 * <code>setRoute</code> and <code>pushRoute</code> methods.
	 */
	public Itinerary() {
		routeStack = new Stack();
		current = null;
	}

	/**
	 * Clone an <code>Itinerary</code> object. 
	 */

	// Stack.clone() returns a shallow copy ??
	public synchronized Object clone() {
		try {
			Itinerary itin = (Itinerary)super.clone();
			itin.current = (ItineraryPattern) current.clone();
			itin.routeStack = (Stack) routeStack.clone(); 
			return itin;

		} catch (CloneNotSupportedException e) {
			throw new NapletInternalError("Itinerary clone error");
		}
	}

    protected void pushRoute( ItineraryPattern itin ) {
        routeStack.push( itin );
    }

    protected ItineraryPattern popRoute() {
		if (routeStack.empty())
			return null;
		else
        	return (ItineraryPattern) routeStack.pop();
    }

	/**
	 * Peek the route at the top of stack
	 * This is a protected method. 
	 * To be accessible to NapletServer for debugging, it needs to be made as 
	 * a public method. 
	 */
    protected ItineraryPattern peekRoute() {
		if (routeStack.empty())
			return null;
		else
        	return (ItineraryPattern) routeStack.peek();
    }

	/**
	 * Obtain the current itinerary pattern. 
	 */
    	public ItineraryPattern getRoute() {
        	return current; 
    	}

	/**
	 * Set route to be a user-defined itinerary
	 * @param itin User-defined naplet itinerary
	 */
	public final void setRoute( ItineraryPattern itin ) {
		current = itin;
	}

	/**
	 * Make the naplet travel along this itinerary.
	 * @param nap The naplet to be migrated
	 */
	public final void travel( Naplet nap) throws NapletMigrateException {
		if (current==null)
			throw new NapletMigrateException("Empty itinerary");
		else {
			try {
				current.go( nap);
				nap = null;
			} catch (java.rmi.RemoteException re) {
				throw new NapletMigrateException(re.getMessage()); 
			}
		}
	}
}

⌨️ 快捷键说明

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