jicarilla-sandbox/platform/container/impl/src/java/org/jicarilla/container DefaultCustomizableResolver.java,NONE,1.1
Leo Simons <[email protected]>
| Newsgroups | gmane.comp.java.jicarilla.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/jicarilla/jicarilla-sandbox/platform/container/impl/src/java/org/jicarilla/container
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1730/platform/container/impl/src/java/org/jicarilla/container
Added Files:
DefaultCustomizableResolver.java
Log Message:
Start support for overriding specific parts of the autowiring policy
--- NEW FILE: DefaultCustomizableResolver.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;
import org.jicarilla.lang.Switch;
import org.jicarilla.lang.Assert;
import org.jicarilla.lang.Selector;
import org.jicarilla.lang.SelectorSwitch;
import org.jicarilla.container.util.PolicyUtil;
import java.util.Map;
import java.util.HashMap;
/**
*
*
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: DefaultCustomizableResolver.java,v 1.1 2004/03/23 14:22:35 lsimons Exp $
*/
public class DefaultCustomizableResolver implements Resolver
{
protected Resolver m_delegate;
protected Switch m_overrides;
protected int m_getCallCount;
protected Map m_getCallOverrides;
public DefaultCustomizableResolver( Resolver delegate )
{
this( delegate, new SelectorSwitch() );
}
public DefaultCustomizableResolver( Resolver delegate, Switch overrides )
{
this( delegate, overrides, new HashMap() );
}
public DefaultCustomizableResolver( Resolver delegate, Switch overrides,
Map getCallOverrides )
{
Assert.assertNotNull( "delegate argument may not be null", delegate );
Assert.assertNotNull( "overrides argument may not be null",
overrides );
Assert.assertNotNull( "getCallOverrides argument may not be null",
getCallOverrides );
m_delegate = delegate;
m_overrides = overrides;
m_getCallOverrides = getCallOverrides;
m_getCallCount = -1;
}
public Object get( Object key ) throws ResolutionException,
JicarillaIllegalAccessException,
JicarillaInvocationTargetException,
JicarillaInstantiationException, JicarillaClassNotFoundException,
InitializationException, JicarillaException
{
m_getCallCount++;
final Integer count = new Integer( m_getCallCount );
if( m_getCallOverrides.containsKey( count ) )
{
return m_getCallOverrides.get( count );
}
if(m_overrides.containsKey( key ) )
{
return m_overrides.get( key );
}
if(m_overrides.containsKey( key ) )
{
return m_overrides.get( key );
}
return m_delegate.get( key );
}
public Object[] getAll( Object key )
throws JicarillaIllegalAccessException,
JicarillaInvocationTargetException,
JicarillaInstantiationException, JicarillaClassNotFoundException,
InitializationException, JicarillaException
{
if( m_overrides.containsKey( key ) )
{
return new Object[] { m_overrides.get( key ) };
}
else
{
return m_delegate.getAll( key );
}
}
public boolean contains( Object key )
{
return m_overrides.containsKey( key ) ||
m_delegate.contains( key );
}
public void releaseInstance( Object instance ) throws Exception
{
m_delegate.releaseInstance( instance );
}
public DefaultCustomizableResolver override( Object key, Object instance )
{
final Selector selector =
PolicyUtil.getSelectorForCriterion( key );
override( selector, instance );
return this;
}
public DefaultCustomizableResolver override( Selector selector, Object instance )
{
Assert.assertNotNull( "selector argument may not be null", selector );
Assert.assertNotNull( "instance argument may not be null", instance );
m_overrides.put( selector, instance );
return this;
}
/**
*
* @param callNumber index starts at 0
* @param instance
*/
public DefaultCustomizableResolver override( int callNumber, Object instance )
{
m_getCallOverrides.put( new Integer(callNumber), instance );
return this;
}
}
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click