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.net.URI;
022    import java.util.Arrays;
023    
024    import net.dpml.lang.AbstractDirective;
025    import net.dpml.lang.ValueDirective;
026    
027    /**
028     * The CodeBaseDirective is immutable datastructure used to 
029     * describe a codebase.
030     *
031     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
032     * @version 1.0.3
033     */
034    public class CodeBaseDirective extends AbstractDirective
035    {
036        private final URI m_codebase;
037        private final ValueDirective[] m_parameters;
038        
039       /**
040        * Creation of a new codebase descriptor.
041        * @param codebase the codebase uri 
042        * @param parameters an array of plugin parameter descriptors
043        */
044        public CodeBaseDirective( URI codebase, ValueDirective[] parameters )
045        {
046            if( null == codebase )
047            {
048                throw new NullPointerException( "codebase" );
049            }
050            m_codebase = codebase;
051            if( null == parameters )
052            {
053                throw new NullPointerException( "parameters" );
054            }
055            m_parameters = parameters;
056        }
057        
058       /**
059        * Return the codebase URI.
060        *
061        * @return the codebase uri
062        */
063        public URI getCodeBaseURI()
064        {
065            return m_codebase;
066        }
067        
068       /**
069        * Return the codebase URI as a string.
070        *
071        * @return the codebase uri specification
072        */
073        public String getCodeBaseURISpec()
074        {
075            return m_codebase.toASCIIString();
076        }
077        
078       /**
079        * Return the array of codebase parameter values.
080        *
081        * @return the parameter value array
082        */
083        public ValueDirective[] getValueDirectives()
084        {
085            return m_parameters;
086        }
087        
088       /**
089        * Test if the supplied object is equal to this object.
090        * @param other the object to evaluate
091        * @return true if this object is equal to the supplied object
092        */
093        public boolean equals( Object other )
094        {
095            if( super.equals( other ) && ( other instanceof CodeBaseDirective ) )
096            {
097                CodeBaseDirective directive = (CodeBaseDirective) other;
098                if( !Arrays.equals( m_parameters, directive.m_parameters ) )
099                {
100                    return false;
101                }
102                else
103                {
104                    return equals( m_codebase, directive.m_codebase );
105                }
106            }
107            else
108            {
109                return false;
110            }
111        }
112    
113       /**
114        * Compute the instance hashcode value.
115        * @return the hashcode
116        */
117        public int hashCode()
118        {
119            int hash = super.hashCode();
120            hash ^= hashValue( m_codebase );
121            hash ^= hashArray( m_parameters );
122            return hash;
123        }
124    
125    }