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.library.info;
020    
021    import java.util.Arrays;
022    import java.util.Properties;
023    
024    /**
025     * The LibraryDirective class describes a collection of modules together
026     * with information about type defintions.
027     *
028     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
029     * @version 1.2.0
030     */
031    public final class LibraryDirective extends AbstractDirective
032    {
033        private final ImportDirective[] m_imports;
034        private final ResourceDirective[] m_resources;
035        
036       /**
037        * Creation of a new library directive.
038        * @param imports module imports
039        * @param resources the set of declared resources
040        * @param properties library properties
041        */
042        public LibraryDirective(
043          ImportDirective[] imports, ResourceDirective[] resources, Properties properties )
044        {
045            super( properties );
046            
047            if( null == imports )
048            {
049                throw new NullPointerException( "imports" );
050            }
051            for( int i=0; i<imports.length; i++ )
052            {
053                if( null == imports[i] )
054                {
055                    throw new NullPointerException( "import" );
056                } 
057            }
058            if( null == resources )
059            {
060                throw new NullPointerException( "resources" );
061            }
062            for( int i=0; i<resources.length; i++ )
063            {
064                if( null == resources[i] )
065                {
066                    throw new NullPointerException( "resource" );
067                } 
068            }
069    
070            m_resources = resources;
071            m_imports = imports;
072        }
073        
074       /**
075        * Return the set of module imports.
076        * @return the module import array
077        */
078        public ImportDirective[] getImportDirectives()
079        {
080            return m_imports;
081        }
082        
083       /**
084        * Return the set of module directives.
085        * @return the resource directive array
086        */
087        public ResourceDirective[] getResourceDirectives()
088        {
089            return m_resources;
090        }
091        
092       /**
093        * Compare this object with another for equality.
094        * @param other the other object
095        * @return true if equal
096        */
097        public boolean equals( Object other )
098        {
099            if( super.equals( other ) && ( other instanceof LibraryDirective ) )
100            {
101                LibraryDirective object = (LibraryDirective) other;
102                if( !Arrays.equals( m_resources, object.m_resources ) )
103                {
104                    return false;
105                }
106                else
107                {
108                    return Arrays.equals( m_imports, object.m_imports );
109                }
110            }
111            else
112            {
113                return false;
114            }
115        }
116        
117       /**
118        * Compute the hashcode value.
119        * @return the hash value
120        */
121        public int hashCode()
122        {
123            int hash = super.hashCode();
124            hash ^= super.hashArray( m_resources );
125            hash ^= super.hashArray( m_imports );
126            return hash;
127        }
128    }