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

📄 dialog.java

📁 jxta官方例程
💻 JAVA
字号:
/**  Copyright (c) 2001 Sun Microsystems, Inc.  All rights*  reserved.**  Redistribution and use in source and binary forms, with or without*  modification, are permitted provided that the following conditions*  are met:**  1. Redistributions of source code must retain the above copyright*  notice, this list of conditions and the following disclaimer.**  2. Redistributions in binary form must reproduce the above copyright*  notice, this list of conditions and the following discalimer in*  the documentation and/or other materials provided with the*  distribution.**  3. The end-user documentation included with the redistribution,*  if any, must include the following acknowledgment:*  "This product includes software developed by the*  Sun Microsystems, Inc. for Project JXTA."*  Alternately, this acknowledgment may appear in the software itself,*  if and wherever such third-party acknowledgments normally appear.**  4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA"*  must not be used to endorse or promote products derived from this*  software without prior written permission. For written*  permission, please contact Project JXTA at http://www.jxta.org.**  5. Products derived from this software may not be called "JXTA",*  nor may "JXTA" appear in their name, without prior written*  permission of Sun.**  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED*  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES*  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE*  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR*  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF*  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND*  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT*  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF*  SUCH DAMAGE.*  ====================================================================**  This software consists of voluntary contributions made by many*  individuals on behalf of Project JXTA.  For more*  information on Project JXTA, please see*  <http://www.jxta.org/>.**  This license is based on the BSD license adopted by the Apache Foundation.**  $Id: Dialog.java,v 1.23 2006/10/03 18:27:33 nano Exp $*/package net.jxta.myjxta.dialog;import net.jxta.myjxta.MyJXTA;import net.jxta.myjxta.View;import net.jxta.myjxta.misc.beam.BeamDialog;import net.jxta.myjxta.plugin.PluginPanel;import net.jxta.myjxta.util.Group;import net.jxta.pipe.PipeService;import net.jxta.protocol.PipeAdvertisement;import org.apache.log4j.Level;import org.apache.log4j.Logger;import java.util.HashMap;import java.util.List;/** * @author james todd [gonzo at jxta dot org] * @author mike mcangus [mcangus at jxta dot org] * @version $Id: Dialog.java,v 1.23 2006/10/03 18:27:33 nano Exp $ * @modified 2005-03-27 jamoore add vojxtaDialog to dialog types * @modified 2005-04-24 jamoore add vijxtaDialog to dialog types */public abstract class Dialog {    /**     * The tag prefix for all myxta2 Message tags     */    public static final String IMFREE = "Jxta:IMFree";    /**     * The Message tag that denotes the PeerGroup ID of the originator     * of a DialogMessage object     */    public static final String IMFREE_GROUP_ID = IMFREE + "GroupId";    /**     * The Message tag that denotes the PeerGroup name of the originator     * of a DialogMessage object     */    public static final String IMFREE_GROUP_NAME = IMFREE + "GrpName";    /**     * The Message tag that denotes the name of the originator     * of a DialogMessage object     */    public static final String IMFREE_ORIGINATOR_NAME = IMFREE + "SenderName";    /**     * The Message tag that denotes the actual message part     * of a DialogMessage object     */    public static final String IMFREE_MESSAGE = IMFREE + "Message";    /**     * The Message tag that denotes the legacy message part     * of a DialogMessage object     */    public static final String IMFREE_LEGACY_MESSAGE = IMFREE + "SenderMessage";    /**     * The  String that is prefixed to the peer name to indicate a     * PipeAdvertisment specific to myjxta     */    public static final String IMFREE_USER_NAME = IMFREE + "UserName";    /**     * The delimiter that indictates the end of a prefix specific to     * myjxta     */    public static final String IMFREE_DELIMITER = ".";    /**     * The Message tag that denotes the command part     * of a DialogMessage object     */    public static final String IMFREE_COMMAND = IMFREE + "Command";    public static String DIALOG_NAME = IMFREE_USER_NAME;    private Group group = null;    private PipeAdvertisement pipeAdvertisement = null;    private MyJXTA myjxta = null;    private static final Logger LOG = Logger.getLogger(Dialog.class);    public static final String GOODBYE_CMD = "GOODBYE";    private static HashMap<String, DialogNamer> dialogNamers = new HashMap<String, DialogNamer>();    public Dialog(Group group, PipeAdvertisement pa, MyJXTA myjxta) {        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("Begin Dialog(Group, PipeAdvertisement, MyJXTA) Constructor");        }        this.group = group;        this.pipeAdvertisement = pa;        this.myjxta = myjxta;        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("End   Dialog(Group, PipeAdvertisement, MyJXTA) Constructor");        }    }    public static String getDialogName() {        return null;    }    /**     * Normalize the name under which to search for a PipeAdvertisement     * for which to search for  if establishing a group chat     *     * @param c the Class to which to add the chat specific parameters to mark the     *          PipeAdvertisment we are looking for as belonging to myjxta     * @return the full name of the PipeAdvertisment label     * @modified 2005-04-24 jamoore added vijxta dialog support     */    // xxx: hackary    public static DialogNamer getDialogNamer(Class c) {        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("Begin getDialogNamer(Class)");        }        DialogNamer dn = null;        if (c == OneToOneCommandDialog.class) {            dn = new DialogNamer() {                public String getDialogName(String s) {                    return OneToOneCommandDialog.DIALOG_NAME +                            IMFREE_DELIMITER + s;                }            };        } else if (c == BeamDialog.class) {            dn = new DialogNamer() {                public String getDialogName(String s) {                    return BeamDialog.DIALOG_NAME +                            IMFREE_DELIMITER + s;                }            };        } else {            DialogNamer dialogNamer = dialogNamers.get(c.getName());            if (dialogNamer != null) {                return dialogNamer;            }        }        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("End   getDialogNamer(Class)");        }        return dn;    }    /**     * @return the current peer group name.     */    public abstract String getName();    /**     * Called if a new DialogMessage object was received.     *     * @param msg the DialogMessage object that was received     */    public abstract void receive(DialogMessage msg);    /**     * Dispatch a Message object to the intended receivers     *     * @param msg the Message object to send across an open pipe     */    public abstract void dispatch(String msg);    /**     * Send a DialogMessage object to its intended receivers.     * DialogMessage object with an empty message will not be send     *     * @param msg the DialogMessage object to send     */    public abstract void dispatch(DialogMessage msg);    /**     * @return the current <code>FilterChain</code> that process all inbound <code>DialogMessage</code>s.     */    public abstract FilterChain getInboundFilters();    /**     * Adds a <code>DialogFilter</code> to the current <code>FilterChain</code> that process all inbound     * <code>DialogMessage</code>s.     *     * @param filter TODO Describe this     */    public abstract void addInboundFilter(DialogFilter filter);    /**     * Removes a <code>DialogFilter</code> from the current <code>FilterChain</code> that process all inbound     * <code>DialogMessage</code>s.     *     * @param filterClass TODO Describe this     */    public abstract void removeInboundFilter(Class filterClass);    /**     * @return the current <code>FilterChain</code> that process all outbound <code>DialogMessage</code>s.     */    public abstract FilterChain getOutboundFilters();    /**     * Adds a <code>DialogFilter</code> to the current <code>FilterChain</code> that process all outbound     * <code>DialogMessage</code>s.     *     * @param filter TODO Describe this     */    public abstract void addOutboundFilter(DialogFilter filter);    /**     * Removes a <code>DialogFilter</code> from the current <code>FilterChain</code> that process all outbound     * <code>DialogMessage</code>s.     *     * @param filterClass TODO Describe this     */    public abstract void removeOutboundFilter(Class filterClass);    /**     * @return the current <code>List</code> of {@link DialogListener}s that process all inbound and outbound     *         <code>DialogMessage</code>s.     */    public abstract List getListeners();    /**     * Add a new DialogListener object     *     * @param l the new DialogListener object to add     */    public abstract void addListener(DialogListener l);    /**     * Remove a previously registered DialogListener object     *     * @param l the DialogListener  object to remove     */    public abstract void removeListener(DialogListener l);    public abstract void clear();    /**     * Remove all {@link DialogListener} objects from the {@link List} being maintained for this session.     */    public abstract void clearListeners();    public abstract void clearCache();    /**     * Return whether this  Dialog object is connected to a pipe     *     * @return true if we are connected to a pipe, false otherwise     */    public abstract boolean isConnected();    /**     * Get the DialogMessage object that is used as a template     * for all DialogMessage objects send via this Dialog object     *     * @return the DialogMessage object that is used as a template     */    public abstract DialogMessage getDialogMessage();    /**     * Close this dialog object, releasing all associated resources.     */    public abstract void close();    public Group getGroup() {        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("In getGroup()");        }        return this.group;    }    public PipeAdvertisement getPipeAdvertisement() {        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("In getPipeAdvertisement()");        }        return this.pipeAdvertisement;    }    public MyJXTA getMyJXTA() {        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("In getMyJXTA()");        }        return this.myjxta;    }    public boolean isSecure() {        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("In isSecure()");        }        return getPipeAdvertisement().getType().equals(PipeService.UnicastSecureType);    }    public boolean equals(Object o) {        if (o == null) {            return false;        }        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("Begin equals(Object)");        }        PipeAdvertisement pa = Dialog.class.isAssignableFrom(o.getClass()) ?                ((Dialog) o).getPipeAdvertisement() : null;        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("End   equals(Object)");            LOG.debug("returning " + (pa != null &&                    pa.getID().equals(getPipeAdvertisement().getID()) &&                    pa.getType().equals(getPipeAdvertisement().getType())));        }        return pa != null &&                pa.getID().equals(getPipeAdvertisement().getID()) &&                pa.getType().equals(getPipeAdvertisement().getType());    }    public int hashCode() {        return (pipeAdvertisement != null ? pipeAdvertisement.hashCode() : 0);    }    public static void registerDialogNamer(Class dialogClass, DialogNamer namer) {        dialogNamers.put(dialogClass.getName(), namer);    }    public static void removeDialogNamer(Class dialogClass) {        dialogNamers.remove(dialogClass.getName());    }    public abstract PluginPanel getDialogPanel(View p_myJXTAView);    //quick hack --> this DialogClass is "hot" (not a template)    public abstract void activate();}

⌨️ 快捷键说明

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