PickyHintedClassSelector.java :  » Web-Server » JicarillaHTTP » org » jicarilla » container » selectors » Java Open Source

Java Open Source » Web Server » JicarillaHTTP 
JicarillaHTTP » org » jicarilla » container » selectors » PickyHintedClassSelector.java
/* ====================================================================
The Jicarilla Software License

Copyright (c) 2003 Leo Simons.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.container.selectors;

import org.jicarilla.lang.Assert;

/**
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: PickyHintedClassSelector.java,v 1.7 2004/03/23 13:37:52 lsimons Exp $
 */
public class PickyHintedClassSelector extends ClassSelector
{
    protected final String m_hint;

    public PickyHintedClassSelector( final Class clazz, final String hint )
    {
        super( clazz );

        Assert.assertNotNull( "hint argument may not be null", hint );
        m_hint = hint;
    }
    public boolean select( final Object object )
    {
        if( object == null )
            return false;

        if( object instanceof Class )
            return super.select( object );

        if( object instanceof String )
        {
            final String string = (String)object;

            final int slash = string.indexOf('/');
            if( slash == -1 )
                return super.select( string );
            else
            {
                final String clazz = string.substring( 0, slash );
                final String hint = string.substring( clazz.length()+1 );
                return (super.select( clazz ) && m_hint.equals( hint ));
            }
        }

        return false;
    }

    public boolean equals( final Object o )
    {
        if( !super.equals(o) )
            return false;

        if( !(o instanceof PickyHintedClassSelector) )
            return false;

        return m_hint.equals( ((PickyHintedClassSelector)o).m_hint );
    }

    public int hashCode()
    {
        return super.hashCode() + 10 + m_hint.hashCode();
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.