001    /*
002     * Copyright 2005 Stephen J. McConnell.
003     *
004     * Licensed  under the  Apache License,  Version 2.0  (the "License");
005     * you may not use  this file  except in  compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *   http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed  under the  License is distributed on an "AS IS" BASIS,
012     * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
013     * implied.
014     *
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package net.dpml.transit.info;
020    
021    import java.util.Arrays;
022    
023    import net.dpml.lang.AbstractDirective;
024    
025    /**
026     * Description of the proxy configuration of a Transit system.
027     * 
028     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
029     * @version 1.0.3
030     */
031    public class ProxyDirective extends AbstractDirective
032    {
033        private final String m_host;
034        private final String m_username;
035        private final char[] m_password;
036        private final String[] m_excludes;
037    
038       /**
039        * Create a new value descriptor using the default java.lang.String class as the base type.
040        * @param host the proxy host
041        * @param excludes an array of excluded hosts or null if no excludes
042        * @param username a possibly null username
043        * @param password a possibly null password
044        * @exception NullPointerException if the proxy host value is null
045        */
046        public ProxyDirective( String host, String[] excludes, String username, char[] password )
047          throws NullPointerException
048        {
049            if( null == host )
050            {
051                throw new NullPointerException( "host" );
052            }
053            
054            m_host = host;
055            m_excludes = resolveExcludes( excludes );
056            m_username = username;
057            m_password = password;
058        }
059        
060       /**
061        * Return the proxy host.
062        * @return the poxy host
063        */
064        public String getHost()
065        {
066            return m_host;
067        }
068    
069       /**
070        * Return the proxy exludes.
071        * @return the poxy excludes
072        */
073        public String[] getExcludes()
074        {
075            return m_excludes;
076        }
077    
078       /**
079        * Return the proxy username.
080        * @return the poxy username
081        */
082        public String getUsername()
083        {
084            return m_username;
085        }
086    
087       /**
088        * Return the proxy password.
089        * @return the poxy password
090        */
091        public char[] getPassword()
092        {
093            return m_password;
094        }
095    
096       /**
097        * Compare this instance with a supplied object for equality.
098        * @param other the other object
099        * @return true if the supplied instance is equal to this instance
100        */
101        public boolean equals( Object other )
102        {
103            if( super.equals( other ) && ( other instanceof ProxyDirective ) )
104            {
105                ProxyDirective directive = (ProxyDirective) other;
106                if( !equals( m_host, directive.m_host ) )
107                {
108                    return false;
109                }
110                else if( !Arrays.equals( m_excludes, directive.m_excludes ) )
111                {
112                    return false;
113                }
114                else if( !equals( m_username, directive.m_username ) )
115                {
116                    return false;
117                }
118                else
119                {
120                    if( null == m_password )
121                    {
122                        return null == directive.m_password;
123                    }
124                    else
125                    {
126                        if( null == directive.m_password )
127                        {
128                            return false;
129                        }
130                        else
131                        {
132                            return new String( m_password ).equals( new String( directive.m_password ) );
133                        }
134                    }
135                }
136            }
137            else
138            {
139                return false;
140            }
141        }
142        
143       /**
144        * Compute the instance hashcode value.
145        * @return the hashcode
146        */
147        public int hashCode()
148        {
149            int hash = 0;
150            hash ^= hashValue( m_host );
151            hash ^= hashArray( m_excludes );
152            if( null != m_password )
153            {
154                hash ^= hashValue( m_username );
155            }
156            if( null != m_password )
157            {
158                hash ^= new String( m_password ).hashCode();
159            }
160            return hash;
161        }
162    
163        private String[] resolveExcludes( String[] excludes )
164        {
165            if( null == excludes )
166            {
167                return new String[0];
168            }
169            else
170            {
171                return excludes;
172            }
173        }
174        
175    }