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 Transit cache configuration.
027     * 
028     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
029     * @version 1.1.0
030     */
031    public class CacheDirective extends AbstractDirective
032    {
033       /**
034        * Default cache path.
035        */
036        public static final String CACHE_PATH = "${dpml.data}/cache";
037        
038       /**
039        * Default system local repository path.
040        */
041        public static final String LOCAL_PATH = "file:${dpml.system}/local";
042        
043       /**
044        * Default layout strategy key.
045        */
046        public static final String CACHE_LAYOUT = "classic";
047        
048       /**
049        * Default layout strategy key.
050        */
051        public static final String LOCAL_LAYOUT = "modern";
052        
053       /**
054        * Empty layout array.
055        */
056        public static final LayoutDirective[] EMPTY_LAYOUTS = new LayoutDirective[0];
057        
058       /**
059        * Empty resource host array.
060        */
061        public static final HostDirective[] EMPTY_HOSTS = new HostDirective[0];
062            
063        private final String m_cache;
064        private final String m_cacheLayout;
065        private final String m_local;
066        private final String m_localLayout;
067        private final LayoutDirective[] m_layouts;
068        private final HostDirective[] m_hosts;
069        
070       /**
071        * Create a new CacheDirective.
072        */
073        public CacheDirective()
074        {
075            this( 
076              CACHE_PATH, CACHE_LAYOUT, LOCAL_PATH, LOCAL_LAYOUT, EMPTY_LAYOUTS, EMPTY_HOSTS );
077        }
078        
079       /**
080        * Create a new CacheDirective.
081        * @param cache the cache directory path
082        * @param cacheLayout the cache layout strategy
083        * @param local the local repository path
084        * @param localLayout the local repository layout strategy
085        * @param layouts an array of extended layout descriptors
086        * @param hosts an array of supplimentary host descriptors
087        * @exception NullPointerException if the cache, local, or layout argument is null
088        */
089        public CacheDirective( 
090          String cache, String cacheLayout, String local, String localLayout, 
091          LayoutDirective[] layouts, HostDirective[] hosts )
092          throws NullPointerException
093        {
094            if( null == cache )
095            {
096                throw new NullPointerException( "cache" );
097            }
098            if( null == cacheLayout )
099            {
100                throw new NullPointerException( "cacheLayout" );
101            }
102            if( null == local )
103            {
104                throw new NullPointerException( "local" );
105            }
106            if( null == localLayout )
107            {
108                throw new NullPointerException( "localLayout" );
109            }
110            
111            m_cache = cache;
112            m_cacheLayout = cacheLayout;
113            m_local = local;
114            m_localLayout = localLayout;
115            
116            if( null == layouts )
117            {
118                m_layouts = new LayoutDirective[0];
119            }
120            else
121            {
122                m_layouts = layouts;
123            }
124            
125            if( null == hosts )
126            {
127                m_hosts = new HostDirective[0];
128            }
129            else
130            {
131                m_hosts = hosts;
132            }
133        }
134        
135       /**
136        * Return the cache path.
137        *
138        * @return the cache path
139        */
140        public String getCache()
141        {
142            return m_cache;
143        }
144        
145       /**
146        * Return the cache layout id.
147        *
148        * @return the cache layout identifier
149        */
150        public String getCacheLayout()
151        {
152            return m_cacheLayout;
153        }
154        
155       /**
156        * Return the local repository path.
157        *
158        * @return the local repository path
159        */
160        public String getLocal()
161        {
162            return m_local;
163        }
164        
165       /**
166        * Return the local system repository layout id.
167        *
168        * @return the system layout identifier
169        */
170        public String getLocalLayout()
171        {
172            return m_localLayout;
173        }
174        
175       /**
176        * Return the supplimentary layout plugin configurations.
177        *
178        * @return the layout directives
179        */
180        public LayoutDirective[] getLayoutDirectives()
181        {
182            return m_layouts;
183        }
184        
185       /**
186        * Return the supplimentary layout plugin configurations.
187        *
188        * @return the host directives
189        */
190        public HostDirective[] getHostDirectives()
191        {
192            return m_hosts;
193        }
194        
195       /**
196        * Test if the supplied object is equal to this object.
197        * @param other the object to evaluate
198        * @return true if this object is equal to the supplied object
199        */
200        public boolean equals( Object other )
201        {
202            if( super.equals( other ) && ( other instanceof CacheDirective ) )
203            {
204                CacheDirective directive = (CacheDirective) other;
205                if( !equals( m_cache, directive.m_cache ) )
206                {
207                    return false;
208                }
209                else if( !equals( m_cacheLayout, directive.m_cacheLayout ) )
210                {
211                    return false;
212                }
213                else if( !equals( m_local, directive.m_local ) )
214                {
215                    return false;
216                }
217                else if( !equals( m_localLayout, directive.m_localLayout ) )
218                {
219                    return false;
220                }
221                else if( !Arrays.equals( m_layouts, directive.m_layouts ) )
222                {
223                    return false;
224                }
225                else
226                {
227                    return Arrays.equals( m_hosts, directive.m_hosts );
228                }
229            }
230            else
231            {
232                return false;
233            }
234        }
235    
236       /**
237        * Compute the instance hashcode value.
238        * @return the hashcode
239        */
240        public int hashCode()
241        {
242            int hash = super.hashCode();
243            hash ^= hashValue( m_cache );
244            hash ^= hashValue( m_cacheLayout );
245            hash ^= hashValue( m_local );
246            hash ^= hashValue( m_localLayout );
247            hash ^= hashArray( m_layouts );
248            hash ^= hashArray( m_hosts );
249            return hash;
250        }
251    }