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