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

📄 config.java

📁 jxme的一些相关程序,主要是手机上程序开发以及手机和计算机通信的一些程序资料,程序编译需要Ant支持
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*

 * 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 disclaimer 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 SUN MICROSYSTEMS 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: Config.java,v 1.2 2002/03/04 21:42:56 echtcherbina Exp $

 */



package net.jxta.impl.config;



import net.jxta.platform.*;

import net.jxta.document.*;

import net.jxta.endpoint.EndpointAddress;

import net.jxta.impl.endpoint.Address;



import java.util.Hashtable;

import java.util.Vector;

import java.util.Enumeration;

import java.io.Writer;

import java.io.InputStream;



// purely for the main() unit test

import java.io.FileWriter;

import java.io.File;

import java.io.FileInputStream;





/** Instances of Config class provides the interface for configuring a JXTA

    peer. Config provides:

     <li>an interface to write a configuration to XML (write())

     <li>an interface to read a configuration from XML (static read())

     <li>an interface to create default a configuration (static

         createDefaultConfig())

     <li>an interface to read configuration information

     <li>an interface to set configuration information

**/

public class Config {

    /** Hashtable of {service key (String), CodeDescriptor  } **/

    private Hashtable mServiceCodeDescriptors = new Hashtable();



    /** the descriptor of the initial class that is booted at startup **/

    private CodeDescriptor mInitialPlatform;



    /** the descriptor of the initial peergoup class that is booted at

        startup **/

    private CodeDescriptor mInitialApp;



    /** TCP Transport Configuration **/

    private TcpConfig mTcpConfig=null;



    /** Http Transport Configuration **/

    private HttpConfig mHttpConfig=null;



    /** Vector of EndpointAddress objects of rendezvous peers **/

    private Vector mRendezvousPeers = new Vector();



    /** Stores whether the peer is a router peer **/

    private boolean mIsRouter;



    /** Stores whether the peer is a rendezvous peer **/

    private boolean mIsRendezvous;



    /** Stores whether the peer should propagate messages **/

    private boolean mShouldPropagate;

    

    // Service keys for mServiceImpls and mServiceCodebases

    public static final String SERVICE_DISCOVERY = "DiscoveryService";

    public static final String SERVICE_MEMBERSHIP = "MembershipService";

    public static final String SERVICE_PIPE = "PipeService";

    public static final String SERVICE_PEERINFO = "PeerInfoService";

    public static final String SERVICE_RESOLVER = "ResolverService";



    /** Array of services.  This should be kept in sync with the list above--

    the config reader and writer use this array to streamline the

    reaading/writing process. **/

    private static final String[] SERVICE_KEYS = { SERVICE_DISCOVERY,

        SERVICE_MEMBERSHIP,

        SERVICE_PIPE,

        SERVICE_PEERINFO,

        SERVICE_RESOLVER};



    private static final String JXTA_CODEBASE =

        "http://www.jxta.org/download/jxta.jar";



    /** Creates a blank configuration.  Normally you will want to create a

	Config object by either reading a pre-existing XML document or

	by calling the static createDefaultConfig()

    **/

    public Config() {

    }



    

    /** Creates a default configuration instance.

    

    @throw RuntimeException A RuntimeException is thrown when there

    is a problem creating a default configuration object. This should

    never happen.

    **/

    public static Config createDefaultConfig() {

        try {

            Config conf = new Config();



            conf.setServiceImplDescriptor( SERVICE_DISCOVERY, 

                new CodeDescriptor( "net.jxta.impl.discovery.DiscoveryService",

                                    JXTA_CODEBASE ) );



            conf.setServiceImplDescriptor( SERVICE_PIPE, 

                new CodeDescriptor( "net.jxta.impl.pipe.PipeService",

                                    JXTA_CODEBASE ));



            conf.setServiceImplDescriptor( SERVICE_PEERINFO, 

                new CodeDescriptor( "net.jxta.impl.peer.PeerInfoService",

                                    JXTA_CODEBASE));



            conf.setServiceImplDescriptor( SERVICE_RESOLVER, 

                new CodeDescriptor( "net.jxta.impl.resolver.ResolverService",

                                    JXTA_CODEBASE));



            conf.setServiceImplDescriptor( SERVICE_MEMBERSHIP, 

                new CodeDescriptor( "net.jxta.impl.membership.NullMembershipService",

                                    JXTA_CODEBASE ) );



            conf.setRendezvous( false );



            // XXX: We should probably not do this in the code at all.

            // if we distribute JXTA with hardcoded rendezvous, they should

            // go into a jxtaconfig.xml that we distribute rather than

            // here.

            conf.addRendezvousPeer( new Address( "tcp://129.144.36.190:6001" ) );

            conf.addRendezvousPeer( new Address( "tcp://jxta.dioxine.net:6001" ) );

            conf.addRendezvousPeer( new Address( "http://jxta.dioxine.net:6002" ) );

            

            conf.setShouldPropagate( false );



            conf.setTcpConfig( TcpConfig.createDefaultConfig() );



            conf.setHttpConfig( HttpConfig.createDefaultConfig() );



            conf.setInitialPlatform( new CodeDescriptor(

                "net.jxta.impl.peergroup.StartNetPeerGroup", JXTA_CODEBASE ) );



            conf.setInitialApp( new CodeDescriptor (

                "net.jxta.impl.shell.bin.Shell.Shell", JXTA_CODEBASE ) );



            return conf;

        } catch ( ConfigurationException e ) {

            throw new RuntimeException( "Fatal error with default config" );

        }

    }



    /** Given a service key, returns the descriptor of the implementation class.

    See the set of SERVICE_ constants above. **/

    public CodeDescriptor getServiceImplDescriptor( String aServiceKey ) {

        return(CodeDescriptor) mServiceCodeDescriptors.get( aServiceKey );

    }



    /** Correlates a service with a code descriptor. **/

    public void setServiceImplDescriptor(

        String aServiceKey,

        CodeDescriptor aDescriptor ) throws ConfigurationException {



        try {

            mServiceCodeDescriptors.put( aServiceKey, aDescriptor );

        } catch ( NullPointerException e ) {

            throw new ConfigurationException( "Null service key provided", e );

        }

    }





    /** Tells whether the peer is a rendezvous peer **/

    public boolean isRendezvous() { 

        return mIsRendezvous;

    }



    /** Sets whether the peer is a rendezvous peer **/

    public void setRendezvous( boolean aIsRendezvous ) {

        mIsRendezvous = aIsRendezvous;

    }



    /** Tells whether the peer is a router peer **/

    public boolean isRouter() {

        return mIsRouter;



    }



    /** Sets whether the peer is a rendezvous peer **/

    public void setRouter( boolean aIsRouter ) {

        mIsRouter = aIsRouter;

    }





    /** Gets the contained TCP Transport configuration **/

    public TcpConfig getTcpConfig() {

        return mTcpConfig;

    }



    /** Sets the contained TCP Transport configuration **/

    public void setTcpConfig( TcpConfig aConfig ) {

        mTcpConfig = aConfig;

    }





    /** Gets the contained Http Transport configuration **/

    public HttpConfig getHttpConfig() {

        return mHttpConfig;

    }



    /** Sets the contained Http Transport configuration **/

    public void setHttpConfig( HttpConfig aConfig ) {

        mHttpConfig = aConfig;

    }





    /** Returns the descriptor of the initial class that is booted at

        startup **/

    public CodeDescriptor getInitialPlatform() {

        return mInitialPlatform;

    }



    /** Sets the classname of the initial class that is booted at startup **/

    public void setInitialPlatform( CodeDescriptor aInitialPlatform ) {

        mInitialPlatform = aInitialPlatform;

    }





    /** Returns the classname of the initial class that is booted at startup **/

    public CodeDescriptor getInitialApp() {

        return mInitialApp;

    }

⌨️ 快捷键说明

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