?? myjxta.java
字號:
/* * Copyright (c) 2001 Sun Microsystems, Inc. All rights * reserved. * * Redistribution and use in source and binary forms, with or withouta * 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: MyJXTA.java,v 1.109 2007/06/10 21:15:10 nano Exp $ */package net.jxta.myjxta;import net.jxta.endpoint.Message;import net.jxta.exception.PeerGroupException;import net.jxta.ext.config.ConversionException;import net.jxta.logging.Logging;import net.jxta.myjxta.dialog.*;import net.jxta.myjxta.plugin.DefaultMyJxtaPluginContainer;import net.jxta.myjxta.plugin.PluginContainer;import net.jxta.myjxta.plugin.PluginView;import net.jxta.myjxta.presence.PeerEntry;import net.jxta.myjxta.presence.PresenceController;import net.jxta.myjxta.search.SearchManager;import net.jxta.myjxta.search.SearchModifier;import net.jxta.myjxta.search.Searcher;import net.jxta.myjxta.share.IShareManager;import net.jxta.myjxta.share.IShareManagerProvider;import net.jxta.myjxta.util.*;import net.jxta.myjxta.util.configuration.MyJXTAConfigurator;import net.jxta.myjxta.util.configuration.NetworkManagerConfigurator;import net.jxta.myjxta.util.objectmodel.GroupNode;import net.jxta.myjxta.util.objectmodel.JxtaNode;import net.jxta.myjxta.util.objectmodel.MyJxtaObjectRepository;import net.jxta.myjxta.util.objectmodel.PeerNode;import net.jxta.myjxta.util.preferences.MyPreferenceManager;import net.jxta.peergroup.NetPeerGroupFactory;import net.jxta.peergroup.PeerGroup;import net.jxta.peergroup.PeerGroupID;import net.jxta.pipe.PipeService;import net.jxta.protocol.PeerGroupAdvertisement;import net.jxta.protocol.PipeAdvertisement;import net.jxta.rendezvous.RendezVousService;import net.jxta.rendezvous.RendezvousEvent;import net.jxta.rendezvous.RendezvousListener;import net.jxta.util.JxtaBiDiPipe;import javax.management.*;import java.io.File;import java.io.IOException;import java.lang.management.ManagementFactory;import java.net.URI;import java.net.URL;import java.util.*;import java.util.logging.Level;import java.util.logging.Logger;/** * @author james todd [gonzo at jxta dot org] * @version $Id: MyJXTA.java,v 1.109 2007/06/10 21:15:10 nano Exp $ */public final class MyJXTA implements GroupListener, RendezvousListener { public static final String GROUP_ID = "group.id"; public static final String GROUP_NAME = "group.name"; public static final String GROUP_DESCRIPTION = "group.description"; public static final String GROUP_AUTO_RENDEZVOUS_PERIOD = "group.autoRendezVousPeriod"; private static final ResourceBundle STRINGS = Resources.getStrings(); // not used right now --> commented out // private static final int CONFIGURATION_WAIT = 50; private static final Logger LOG = Logger.getLogger(MyJXTA.class.getName()); private final ArrayList<Group> joinedGroups = new ArrayList<Group>(); private String peerName = null; /** * there are some plugins (CMS) that needs a call to "System.exit(0)".... */ public final boolean m_needsSystemExitOnShutdown = false; /** * The UI to use to display the data */ private View view = null; /** * The PreferenceManager object to use */ private MyPreferenceManager myPreferenceManager = null; public MultipleInstanceUtil.AdministrationListener administrationListener = null; private PluginContainer m_pluginContainer; private ArrayList<String> administrationBuffer = null; public static final String NAME = Constants.getInstance().get( Constants.NAME); public static final String VERSION = NAME + " " + Constants.getInstance().get(Constants.VERSION) + " [" + Constants.getInstance().get(Constants.BUILD) + "]"; private RendezVousService rendezvousNPG; private final static Object networkConnectLock = new Object(); public static MyJXTA getTheInstance() { return g_theInstance; } private static MyJXTA g_theInstance; public static MyJXTA startMyJxta() { if (g_theInstance == null) { g_theInstance = new MyJXTA(); } return g_theInstance; } /** * Create a new instance of MyJxta and initializes it. This starts the * JXTA network if it was not already started */ private MyJXTA() { // only one Instance of MyJxta can be active inside the same working // directory if (!MultipleInstanceUtil.isOnlyInstance(this)) { destroy(); return; } g_theInstance = this; // only needed for the NetBean integration registerBeanStuff(); // initiate the Plugin / Module Container (will instantiate the plugins, // modules...) m_pluginContainer = new DefaultMyJxtaPluginContainer(this); // ViewFactory.setViewerClass(net.jxta.myjxta.ui.MyJXTALiteViewer.class); // initiate the view (right now only a single swing view is // implememented) this.view = ViewFactory.getView(this); //call the init methods of the plugins m_pluginContainer.init(); this.view.setVisible(true);// boolean isConfigured = configureMyJxta(); try { MyJXTAConfigurator c = new NetworkManagerConfigurator(this.view); //MyJXTAConfigurator c = new JxtaExtConfigurator(this.view); c.configurePlatform(); initialize(); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. view.showMessageDialog(e.getLocalizedMessage()); } } private void registerBeanStuff() { try { ManagementFactory.getPlatformMBeanServer().registerMBean( Status.getInstance(), new ObjectName(":type=net.jxta.myjxta")); } catch (MalformedObjectNameException mone) { mone.printStackTrace(); } catch (InstanceAlreadyExistsException iaee) { iaee.printStackTrace(); } catch (MBeanRegistrationException mbre) { mbre.printStackTrace(); } catch (NotCompliantMBeanException ncmbe) { ncmbe.printStackTrace(); } } public MyPreferenceManager getPreferenceManager() { return this.myPreferenceManager; } /** * Return the name of the peer * * @return the name of the peer */ public String getPeerName() { return this.peerName; } /** * Add a dialog that should be displayed in the UI * * @param dialog the dialog to display */ public void addDialog(Dialog dialog) { this.view.addDialog(dialog); } public void removeDialog(Dialog dialog) { this.view.removeDialog(dialog); } /** * Return the ShareManager instance used for file sharing * * @return the ShareManager instance used for file sharing */ public IShareManager getShareManager() { IShareManagerProvider iShareManagerProvider = getShareManagerProvider(); if (iShareManagerProvider == null) return null; //no provider (no plugin) --> no shareManager! return iShareManagerProvider.getShareManager(this, this.view.getGroup(), true); } private IShareManagerProvider getShareManagerProvider() { IShareManagerProvider shareManagerProvider = (IShareManagerProvider) getPluginContainer().getPlugin(IShareManagerProvider.class); if (shareManagerProvider == null) return null; else return shareManagerProvider; } /** * Part of group Lifecycle. Joins group. Starts group services and * associated resources. */ public void joinGroup(final Group group, boolean useAutoRdvMode, boolean discover) { final PeerGroup peerGroup = group.getPeerGroup(); setStatus(STRINGS.getString("status.group.join") + " " + peerGroup.getPeerGroupName()); this.view.setTitle(peerGroup.getPeerName() + "@" + peerGroup.getPeerGroupName()); setStatus(STRINGS.getString("status.group.display") + " " + peerGroup.getPeerGroupName()); String dialogName = Dialog.getDialogNamer(OneToOneCommandDialog.class) .getDialogName(peerGroup.getPeerName()); PipeAdvertisement pipeAdvertisment = PipeUtil.getAdv(peerGroup, dialogName, PipeService.UnicastType, null); // now lets add the different dialogs/pipe listeners if (group.isVisible()) { registerCommandDialogPipeListener(group); } // add the one Group Panel to the navigation tree if (group.isVisible()) { view.createGroupNavigation(group); } GroupNode groupNode = new GroupNode(group); if (group.getParentGroup() != null) { groupNode.setParent(new GroupNode(group.getParentGroup())); } else { groupNode.setParent(MyJxtaObjectRepository.getRoot()); } addJxtaNode(groupNode); PeerNode ownPeerNode = new PeerNode(new Peer(pipeAdvertisment), group); group.setOwnCommandId(pipeAdvertisment.getPipeID()); addJxtaNode(ownPeerNode, true); restore(group); if (discover) { discover(group);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -