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 net.dpml.library.Resource;
022    import net.dpml.library.ResourceNotFoundException;
023    
024    /**
025     * Simple value filter.
026     *
027     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
028     * @version 1.1.2
029     */
030    public class SimpleFilterDirective extends FilterDirective
031    {
032        private final String m_value;
033        
034       /**
035        * Creation of a new anonymous resource directive.
036        * @param token the filter token
037        * @param value the substitution value
038        */
039        public SimpleFilterDirective( String token, String value )
040        {
041            super( token );
042            m_value = value;
043        }
044        
045       /**
046        * Return the filter value.
047        * @param resource the enclosing resource
048        * @return the resolved value
049        * @exception ResourceNotFoundException (never thrown)
050        */
051        public String getValue( Resource resource ) throws ResourceNotFoundException
052        {
053            return resource.resolve( m_value );
054        }
055        
056       /**
057        * Compare this object with another for equality.
058        * @param other the other object
059        * @return true if equal
060        */
061        public boolean equals( Object other )
062        {
063            if( super.equals( other ) && ( other instanceof SimpleFilterDirective ) )
064            {
065                SimpleFilterDirective directive = (SimpleFilterDirective) other;
066                return m_value.equals( directive.m_value );
067            }
068            else
069            {
070                return false;
071            }
072        }
073        
074       /**
075        * Compute the hash value.
076        * @return the hashcode value
077        */
078        public int hashCode()
079        {
080            int hash = super.hashCode();
081            hash ^= super.hashValue( m_value );
082            return hash;
083        }
084    }