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

📄 endpointaddress.java

📁 jxta_src_2.41b jxta 2.41b 最新版源码 from www.jxta.org
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            protocolAddress.equalsIgnoreCase(likeMe.protocolAddress) &&            ((service != null) ? ((likeMe.service != null) && service.equals(likeMe.service)) : (likeMe.service == null)) &&            ((serviceParam != null) ? ((likeMe.serviceParam != null) && serviceParam.equals(likeMe.serviceParam)) : (likeMe.serviceParam == null));                        return result;        }                return false;    }        /**     * {@inheritDoc}     **/    public synchronized int hashCode() {        if( modcount != modAtLastHashCalc ) {            if( (null == protocol) || (null == protocolAddress) ) {                throw new IllegalStateException( "Corrupt EndpointAddress, protocol or address is null" );            }                        cachedHashCode = protocol.toLowerCase().hashCode();            cachedHashCode += protocolAddress.hashCode() * 5741;   // a prime            cachedHashCode += ((service != null) ? service.hashCode() : 1) * 7177; // a prime            cachedHashCode += ((serviceParam != null) ? serviceParam.hashCode() : 1) * 6733; // a prime                        cachedHashCode = (0 == cachedHashCode) ? 1 : cachedHashCode;            modAtLastHashCalc = modcount;        }                return cachedHashCode;    }        /**     * {@inheritDoc}     **/    public synchronized String toString() {        String result;                if( (modcount == modAtLastStringCalc) && (null != cachedToString) ) {            result = (String) cachedToString.get();                        if (null != result)                return result;        }                if( (null == protocol) || (null == protocolAddress) ) {            throw new IllegalStateException( "Corrupt EndpointAddress, protocol or address is null" );        }                StringBuffer newResult = new StringBuffer( protocol.length() + protocolAddress.length() + 64 );                newResult.append( protocol );                if( hierarchical ) {            newResult.append( "://" );        } else {            newResult.append( ':' );        }                newResult.append( protocolAddress );                if( null != service ) {            if( hierarchical ) {                newResult.append( '/' );            } else {                newResult.append( '#' );            }            newResult.append( service );                        if( null != serviceParam ) {                newResult.append( '/' );                newResult.append( serviceParam );            }        }                result = newResult.toString();                cachedToString = new SoftReference( result );        modAtLastStringCalc = modcount;                return result;    }        /**     *  Return a URI which represents the endpoint address.      *     *  @return a URI which represents the endpoint address.     **/    public URI toURI() {        return URI.create( toString() );    }        /**     * Get a byte array containing a UTF-8 representation of the address.     *     *  @deprecated There isn't really ever a good reason to use this since it     *  has to assume the character encoding. Switch your code to use:     *  <tt>byte bytes[] = address.toString().getBytes("UTF-8");</tt>      *     * @return a byte array containing the bytes of a UTF-8 representation of the endpoint     * address.     **/    public byte[] getBytes() {        try {            return toString().getBytes( "UTF-8" );        } catch(UnsupportedEncodingException ex ) {            // UTF-8 is built in to all jdk            RuntimeException failure = new UnsupportedOperationException( "Could not get UTF-8 encoding");            failure.initCause( ex );                        throw failure;        }    }        /**     * Return a String that contains the name of the protocol     * contained in the EndpointAddress     *     * @return a String containing the protocol name     **/    public String getProtocolName() {        return protocol;    }        /**     * Return a String that contains the protocol address contained     * in the EndpointAddress     *     * @return a String containing the protocol address     **/    public String getProtocolAddress() {        return protocolAddress;    }        /**     * Return a String that contains the service name contained in     * the EndpointAddress     *     * @return a String containing the service name     **/    public String getServiceName() {        return service;    }        /**     * Return a String that contains the service parameter contained     * in the EndpointAddress     *     * @return a String containing the protocol name     **/    public String getServiceParameter() {        return serviceParam;    }        /**     * Set the protocol name.     *     *  @deprecated EndpointAddress works better if it is immutable.     *     * @param name String containing the name of the protocol     **/    public synchronized void setProtocolName(String name) {        if( (null == name) || (0 == name.length()) ) {            throw new IllegalArgumentException( "name must be non-null and contain at least one character" );        }                if( -1 != name.indexOf( "/" ) ) {            throw new IllegalArgumentException( "name may not contain '/' character" );        }                int colonAt = name.indexOf( ':' );                if( -1 == colonAt ) {            hierarchical = true;        }        else {            if( !"urn".equalsIgnoreCase( name.substring( 0, colonAt ) ) ) {                throw new IllegalArgumentException( "Only urn may contain colon" );            }                        if( colonAt == (name.length() - 1) ) {                throw new IllegalArgumentException( "empty urn namespace!" );            }                        hierarchical = false;        }                protocol = name;        modcount++;        cachedToString = null;    }        /**     * Set the protocol address.     *     *  @deprecated EndpointAddress works better if it is immutable.     *     * @param address String containing the peer address.     **/    public synchronized void setProtocolAddress(String address) {        if( (null == address) || (0 == address.length()) ) {            throw new IllegalArgumentException( "address must be non-null and contain at least one character" );        }                if( -1 != address.indexOf( "/" ) ) {            throw new IllegalArgumentException( "address may not contain '/' character" );        }                protocolAddress = address;        modcount++;        cachedToString = null;    }        /**     * Set the service name.     *     *  @deprecated EndpointAddress works better if it is immutable.     *     * @param name String containing the name of the destination service     **/    public synchronized void setServiceName(String name) {        if( null == name ) {            service = null;            modcount++;            return;        }                if( -1 != name.indexOf( "/" ) ) {            throw new IllegalArgumentException( "service name may not contain '/' character" );        }                service = name;        modcount++;        cachedToString = null;    }        /**     * Set the service parameter     *     *  @deprecated EndpointAddress works better if it is immutable.     *     * @param param String containing the service parameter     **/    public synchronized void setServiceParameter(String param) {        if( null == param ) {            serviceParam = null;            modcount++;            return;        }                serviceParam = param;        modcount++;        cachedToString = null;    }        /**     * parse any EndpointAddress from a URI     *     * @param addr endpoint address to parse     **/    private void parseURI( String addr ) {        int index = addr.indexOf("://");        if (index == -1) {            parseURN( addr );        } else {            parseURL( addr );        }    }        /**     * parse an EndpointAddress from a URN     *     * @param addr endpoint address to parse     **/    private void parseURN( String addr ) {        int protocolEnd = addr.indexOf( ':' );                if( -1 == protocolEnd ) {            if (LOG.isEnabledFor(Level.DEBUG)) {                LOG.debug( "Address is not a valid URI: " + addr );            }            throw new IllegalArgumentException( "Address is not a valid URI: " + addr );        }                if( !"urn".equalsIgnoreCase( addr.substring( 0, protocolEnd ) ) ) {            if (LOG.isEnabledFor(Level.DEBUG)) {                LOG.debug( "Address is unrecognized URI form: " + addr );            }            throw new IllegalArgumentException( "Address is unrecognized URI form: " + addr );        }                if( (addr.length() - 1) == protocolEnd ) {            if (LOG.isEnabledFor(Level.DEBUG)) {                LOG.debug( "Address URN does not have a namespace: " + addr );            }            throw new IllegalArgumentException( "Address URN does not have a namespace: " + addr );        }                // gather the namespace as well.        int namespaceEnd = addr.indexOf( ':', protocolEnd + 1 );                if( -1 == namespaceEnd ) {            if (LOG.isEnabledFor(Level.DEBUG)) {                LOG.debug( "Address URN does not have a namespace: " + addr );            }            throw new IllegalArgumentException( "Address URN does not have a namespace: " + addr );        }                setProtocolName( addr.substring( 0, namespaceEnd ) );                if( (addr.length() - 1) == namespaceEnd ) {            if (LOG.isEnabledFor(Level.DEBUG)) {                LOG.debug( "Address URN does not have a NSS portion: " + addr );            }            throw new IllegalArgumentException( "Address URN does not have a NSS portion: " + addr );        }                // check for service and param        int nssEnd = addr.indexOf( '#', namespaceEnd + 1 );                if( -1 == nssEnd )            setProtocolAddress( addr.substring(namespaceEnd + 1) );        else {            setProtocolAddress( addr.substring( namespaceEnd + 1, nssEnd ) );                        int serviceEnd = addr.indexOf( '/', nssEnd + 1 );                        if( -1 == serviceEnd ) {                setServiceName( addr.substring(nssEnd + 1) );            } else {                setServiceName( addr.substring( nssEnd + 1, serviceEnd ) );                                setServiceParameter( addr.substring(serviceEnd + 1) );            }        }    }        /**     * parse and EndpointAddress from a URL     *     * @param addr endpoint address to parse     **/    private void parseURL(String addr) {        String remainder = null;                int index = addr.indexOf("://");        if (index == -1) {            if (LOG.isEnabledFor(Level.DEBUG))                LOG.debug( "Address is not in absolute form: " + addr );            throw new IllegalArgumentException( "Address is not in absolute form: " + addr );        }                if( 0 == index ) {            if (LOG.isEnabledFor(Level.DEBUG))                LOG.debug( "Protocol is missing: " + addr );            throw new IllegalArgumentException( "Protocol is missing: " + addr );        }                try {            setProtocolName( addr.substring(0, index) );            remainder = addr.substring(index + 3);        } catch (Exception e) {            if (LOG.isEnabledFor(Level.DEBUG)) {                LOG.debug( "Protocol address is missing: " + addr );            }            throw new IllegalArgumentException( "Protocol address is missing: " + addr );        }        index = remainder.indexOf("/");        if (index == -1) {            setProtocolAddress( remainder );            return;        }                setProtocolAddress( remainder.substring(0, index) );                remainder = remainder.substring(index + 1);                index = remainder.indexOf("/");        if (index == -1) {            setServiceName( remainder );            return;        }                setServiceName( remainder.substring(0, index) );                remainder = remainder.substring(index + 1);                setServiceParameter( remainder );    }}

⌨️ 快捷键说明

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