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

📄 link.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/link/Link.java,v $// $RCSfile: Link.java,v $// $Revision: 1.4.2.1 $// $Date: 2004/10/14 18:27:06 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.link;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.omGraphics.grid.*;import com.bbn.openmap.Layer;import com.bbn.openmap.util.Debug;import java.io.*;import java.net.Socket;/** * The Link object is the main mechanism for communications between a * LinkClient (most likely a LinkLayer) and a LinkServer. This class * should only be used directly by a server - clients should use the * ClientLink object. This object defines the communications that * either side can make. * <P> *  * The ClientLink adds some control methods that the client should * use. The client needs to make sure that several queries are not * sent to the server at the same time. The ClientLink contains a lock * that can be checked, and set. It is up to the client to manage the * lock. The ClientLink also provides the method to close the link * down, since it makes that decision. The server should remain * connected until the client is finished. The server can request to * be disconnected, however, and the ClientLink provides a method for * the client to check if that request has been made. */public class Link implements LinkConstants {    /** The apparent maximum size of a header. */    public final static int MAX_HEADER_LENGTH = 80;    /** For outgoing traffic. */    protected LinkOutputStream dos = null;    /** For incoming traffic. */    protected DataInputStream dis = null;    /** Used to read/create strings from off the input stream. */    protected char[] charArray = new char[MAX_HEADER_LENGTH];    /**     * Set for the client, by the server, to indicate whether the     * socket should be closed. By default, this will be false, Used     * when the server wants to run in a stateless mode, and doesn't     * care to maintain a connection with the client. It's included in     * the Link object because the server knows about it and sets it     * in the client.     */    protected boolean closeLink = false;    /**     * Used to retrieve any potential graphics queries that came in     * over the link.     */    protected LinkMapRequest mapRequest = null;    /**     * Used to retrieve any potential graphics responses that came in     * over the link.     */    protected LinkGraphicList graphicList = null;    /**     * Used to retrieve any potential gesture queries that came in     * over the link.     */    protected LinkActionRequest actionRequest = null;    /**     * Used to retrieve any potential gesture responses that came in     * over the link.     */    protected LinkActionList actionList = null;    /**     * Used to retrieve any potential GUI queries that came in over     * the link.     */    protected LinkGUIRequest guiRequest = null;    /**     * Used to retrieve any potential GUI responses that came in over     * the link.     */    protected LinkGUIList guiList = null;    /** The socket used for the link. Kept for convenience. */    protected Socket socket = null;    /**     * The lock. This should only be changed within a syhchronized     * block of code, synchronized on the link object.!! Otherwise,     * race conditions can result.     */    protected boolean locked = false;    /**     * Flag to control whether this side of the link will adhere to     * shutdown commands issued from other side of the link. False by     * default.     */    protected boolean obeyCommandToExit = false;    /**     * Open up a link over a socket.     *      * @param socket the socket to open the Link on.     * @throws IOException     */    public Link(Socket socket) throws IOException {        this.socket = socket;        InputStream is = socket.getInputStream();        BufferedInputStream bis = new BufferedInputStream(is);        this.dis = new DataInputStream(bis);        OutputStream os = socket.getOutputStream();        BufferedOutputStream bos = new BufferedOutputStream(os);        this.dos = new LinkOutputStream(bos);    }    /**     * Should be called by the server and/or client to release     * resources when the link is through being used.     */    public void cleanUp() {        try {            this.dis.close();            this.dos.close();        } catch (IOException ioe) {        }        this.dis = null;        this.dos = null;    }    /**     * The method to call at the beginning of a request or response.     * It writes the header given to the link. This header is expected     * on the other side of the link.     *      * @param messageHeader Header string, defined in the Link object,     *        that describes the tranmission.     * @throws IOException     */    public void start(String messageHeader) throws IOException {        dos.write(messageHeader.getBytes());    }    /**     * The method that needs to be called at the end of a     * request/response or section. This places the END_TOTAL symbol     * on the link to let the other side know that the transmission is     * done, and it also flushes the output stream buffer.     *      * @param endType use END_SECTION if you want to add more types of     *        responses. Use END_TOTAL at the end of the total     *        transmission.     * @throws IOException     */    public void end(String endType) throws IOException {        dos.write(endType.getBytes());        if (endType == END_TOTAL) {            dos.flush();        }    }    /**     * Called to begin reading the information coming off the link.     * Since the information can be coming in different sections, this     * method figures out how to read the different sections and get     * ready for requests on what was read. After the link is read,     * you can then request the link to find out what was sent back -     * for graphics, GUI components, or actions. When this method is     * called, the link resets the objects that are returned by     * getGraphics(), getGUI and getActions(). These methods are meant     * to be used after read() to find out what was returned.     *      * @throws IOException     */    public void readAndParse() throws IOException {        readAndParse(null, null);    }    /**     * Called to begin reading the information coming off the link.     *      * @param proj a projection for graphics     * @param generator an OMGridGenerator that knows how to render     *        grid objects.     * @throws IOException     */    public void readAndParse(Projection proj, OMGridGenerator generator)            throws IOException {        readAndParse(proj, generator, null);    }    /**     * Called to begin reading the information coming off the link.     *      * @param proj pass in a projection if you are expecting graphics     *        to arrive, and they will be projected as they come off     *        the link.     * @param generator an OMGridGenerator that knows how to render     *        grid objects.     * @param layer a layer that is interested in gesture reactions.     * @throws IOException     */    public void readAndParse(Projection proj, OMGridGenerator generator,                             Layer layer) throws IOException {        // Reset everything //        // Keep this here, so if there is more than one graphics        // section, then all the graphics get added to one list.        LinkOMGraphicList graphics = new LinkOMGraphicList();        graphicList = null;        mapRequest = null;        actionRequest = null;        actionList = null;        guiRequest = null;        guiList = null;        closeLink = false;        String delimiter = null;        if (Debug.debugging("link")) {            System.out.println("Link|readAndParse: listening to link:");            System.out.println((proj == null ? " without " : " with ")                    + "a projection and");            System.out.println((layer == null ? " without " : " with ")                    + "a layer");        }        while (true) {            delimiter = readDelimiter(true);            if (Debug.debugging("link")) {                System.out.println("Link:reading section: " + delimiter);            }

⌨️ 快捷键说明

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