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

📄 httpconfig.java

📁 jxme的一些相关程序,主要是手机上程序开发以及手机和计算机通信的一些程序资料,程序编译需要Ant支持
💻 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 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: HttpConfig.java,v 1.2 2002/03/04 21:42:56 echtcherbina Exp $

 */



package net.jxta.impl.config;



import net.jxta.document.*;

import net.jxta.endpoint.EndpointAddress;

import net.jxta.impl.endpoint.Address;

import java.io.IOException;

import java.util.Enumeration;



/**

 * Sub-configuration for HTTP-specific settings. Instances of this class

 * are normally contained within a Config instance.

 *

**/

public class HttpConfig {

    

    /** The default TCP server port **/

    private static final int DEFAULT_PORT = 6002;



    private static final String DEFAULT_IMPL =

        "net.jxta.impl.endpoint.http.HttpTransport";

    

    /** The implementation classname to be used for the HTTP transport. **/

    private String mImplClassname;



    /** The port on which the HTTP server is to run **/

    private EndpointAddress mServerAddress;



    /** The hostname of the router that the local peer is using. Null if not

    using a router. **/

    private EndpointAddress mRouterAddress;



    /** The hostname of the HTTP proxy that the local peer is using. Null if

        not using a proxy server. **/

    private EndpointAddress mProxyAddress;



    /** Stores whether to use the HTTP proxy information or not **/

    private boolean mUseProxy;



    /** tells whether to use the public address **/

    private boolean mUsePublicAddress;



    /** The address I want to expose publicly. **/

    private EndpointAddress mPublicAddress;



    /** XXX what is this???  not implemented cause I don't know what it is. **/

    private String mPeerID;



    // XML tag names

    private static final String KEY_SERVER = "Server";

    private static final String KEY_PROXY = "ProxyServer";

    private static final String KEY_USE_PROXY = "UseProxyServer";

    private static final String KEY_ROUTER = "Router";

    private static final String KEY_IMPL = "Impl";



    /** Creates a default config instance.  The default is such that there

    is no proxy used, no router used, and that the peer is not a rendezvous

    server. **/

    public static HttpConfig createDefaultConfig() {

        HttpConfig conf = new HttpConfig();

        conf.setImplClassname( DEFAULT_IMPL );

        conf.setServerAddress( new Address( "http://localhost:" + DEFAULT_PORT ) );

        return conf;

    }



    /** Creates a new HttpConfig instance given a parent "Http" element **/

    public static HttpConfig newFromXML( TextElement parent ) {

        Enumeration enum = parent.getChildren();

        if ( enum == null ) return null;

        HttpConfig conf = new HttpConfig();

        while ( enum.hasMoreElements() ) {

            TextElement e = (TextElement) enum.nextElement();

            String elname = e.getName();



            if ( elname.equals( KEY_IMPL ) )

                conf.mImplClassname = e.getTextValue();

            else if ( elname.equals( KEY_SERVER ) )

                conf.mServerAddress = new Address( e.getTextValue() );

            else if ( elname.equals( KEY_ROUTER ) )

                conf.mRouterAddress = new Address( e.getTextValue() );

            else if ( elname.equals( KEY_PROXY ) )

                conf.mProxyAddress = new Address( e.getTextValue() );

            else if ( elname.equals( KEY_USE_PROXY ) )

                conf.mUseProxy = Boolean.valueOf( e.getTextValue() ).booleanValue();

            else if ( elname.equals( ConfigConstants.KEY_PUBLICADDR ) )

                conf.mPublicAddress = new Address( e.getTextValue() );

            else if ( elname.equals( ConfigConstants.KEY_USE_PUBLICADDR ) )

                conf.mUsePublicAddress = Boolean.valueOf( e.getTextValue() ).booleanValue();

        }



        return conf;

    }



    /** Writes self to doc. **/

    public void writeToXML( StructuredTextDocument doc ) { 

        Element parent = doc.createElement( ConfigConstants.KEY_HTTP_TRANSPORT );

        doc.appendChild( parent );



        ConfigUtil.writeAddress( doc, parent, mServerAddress, KEY_SERVER );

        ConfigUtil.writeAddress( doc, parent, mRouterAddress, KEY_ROUTER );

        ConfigUtil.writeAddress( doc, parent, mProxyAddress, KEY_PROXY );

        parent.appendChild( doc.createElement( KEY_USE_PROXY, String.valueOf( mUseProxy ) ) );

        ConfigUtil.writeAddress( doc, parent, mPublicAddress, ConfigConstants.KEY_PUBLICADDR );

        

        parent.appendChild( doc.createElement(

            ConfigConstants.KEY_USE_PUBLICADDR,

            String.valueOf( mUsePublicAddress ) ) );



        Element e = doc.createElement( KEY_IMPL, mImplClassname );

        parent.appendChild( e );

    }





    /** Gets the port on which the HTTP server will listen. **/

    public EndpointAddress getServerAddress() {

        return mServerAddress;

    }



    /** Sets the port on which the HTTP server will listen. **/

    public void setServerAddress( EndpointAddress aAddress ) {

        mServerAddress = aAddress;

    }



    /** Returns the implementation classname for the transport. **/

    public String getImplClassname() {

        return mImplClassname;

    }



    /** Sets the implementation classname for the transport. **/

    public void setImplClassname( String aImplClassname ) {

        mImplClassname = aImplClassname;

    }



    /** Gets the hostname of the router that the peer is using. **/ 

    public EndpointAddress getRouterAddress() {

        return mRouterAddress;

    }



    /** Sets the hostname of the router that the peer is using. **/ 

    public void setRouterAddress( EndpointAddress aRouterAddress ) {

        mRouterAddress = aRouterAddress;

    }



    /** Gets the hostadress of the proxy server that the peer is using. Returns

    null if I am not using a proxy server **/

    public EndpointAddress getProxyAddress() {

        return mProxyAddress;

    }



    /** Sets the hostname of the proxy that the peer is using **/

    public void setProxyAddress( EndpointAddress aProxyAddress ) {

        mProxyAddress = aProxyAddress;

    }



    /** Returns whether to use the defined proxy server **/

    public boolean getUseProxy() {

        return mUseProxy;

    }



    /** Sets whether to use the defined proxy server **/

    public void setUseProxy( boolean aUseProxy ) {

        mUseProxy = aUseProxy;

    }



    /** Gets the public address to expose for HTTP-based communications **/

    public EndpointAddress getPublicAddress() {

        return mPublicAddress;

    }



    /** Sets the public address to expose for HTTP-based communications **/

    public void setPublicAddress( EndpointAddress aPublicAddress ) {

        mPublicAddress = aPublicAddress;

    }



    /** Tells whether to use the specified public address **/

    public boolean getUsePublicAddress() {

        return mUsePublicAddress;

    }



    /** Sets whether to use the specified public address **/

    public void setUsePublicAddress( boolean aUsePublicAddress ) {

        mUsePublicAddress = aUsePublicAddress;

    }

}

⌨️ 快捷键说明

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