Update of /cvsroot/jicarilla/jicarilla-sandbox/platform/container-integration/src/java/org/jicarilla/container/integration/avalon
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19900/container-integration/src/java/org/jicarilla/container/integration/avalon
Added Files:
FortressBasedComponentAdapter.java
FortressBasedKeyAwareComponentAdapter.java
FortressContainerBasedSelector.java
JicarillaBasedComponentHandler.java
JicarillaBasedFortressContainer.java
ServiceManagerBasedKeyAwareComponentAdapter.java
ServiceManagerBasedSelector.java
Log Message:
split out integration code from the main container project
--- NEW FILE: FortressBasedComponentAdapter.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.integration.avalon;
import org.apache.avalon.fortress.Container;
import org.apache.avalon.fortress.impl.handler.ComponentHandler;
import org.apache.avalon.framework.service.ServiceException;
import org.jicarilla.container.Adapter;
import org.jicarilla.container.JicarillaInstantiationException;
import java.util.HashMap;
import java.util.Map;
/**
*
*
* @author <a href="mail at leosimons dot com">Leo Simons</a>
* @version $Id: FortressBasedComponentAdapter.java,v 1.1 2004/03/08 21:05:24 lsimons Exp $
*/
public class FortressBasedComponentAdapter
implements Adapter
{
protected final Container m_container;
protected final String m_key;
protected final String m_hint;
protected final Map m_instances = new HashMap();
public FortressBasedComponentAdapter( final Container container,
final String key, final String hint )
{
m_container = container;
m_key = key;
m_hint = hint;
}
public Object getInstance()
{
try
{
final ComponentHandler handler =
(ComponentHandler)m_container.get(
m_key, m_hint );
final Object instance = handler.get();
m_instances.put( instance, handler );
return instance;
}
catch( ServiceException e )
{
throw new JicarillaInstantiationException( e );
}
catch( Exception e )
{
throw new JicarillaInstantiationException( e );
}
}
public void releaseInstance( final Object component ) throws Exception
{
if( !m_instances.containsKey( component) )
return;
final ComponentHandler handler =
(ComponentHandler)m_instances.get( component );
handler.put( component );
}
}
--- NEW FILE: FortressBasedKeyAwareComponentAdapter.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.integration.avalon;
import org.apache.avalon.fortress.Container;
import org.apache.avalon.fortress.impl.handler.ComponentHandler;
import org.apache.avalon.framework.service.ServiceException;
import org.jicarilla.container.JicarillaInstantiationException;
import org.jicarilla.container.KeyAwareAdapter;
import java.util.HashMap;
import java.util.Map;
/**
*
*
* @author <a href="mail at leosimons dot com">Leo Simons</a>
* @version $Id: FortressBasedKeyAwareComponentAdapter.java,v 1.1 2004/03/08 21:05:24 lsimons Exp $
*/
public class FortressBasedKeyAwareComponentAdapter
implements KeyAwareAdapter
{
protected final Container m_container;
protected final Map m_instances = new HashMap();
public FortressBasedKeyAwareComponentAdapter( final Container container )
{
m_container = container;
}
public Object getInstance( final Object key )
{
try
{
final ComponentHandler handler =
(ComponentHandler)m_container.get( key.toString(), null );
final Object instance = handler.get();
m_instances.put( instance, handler );
return instance;
}
catch( ServiceException e )
{
throw new JicarillaInstantiationException( e );
}
catch( Exception e )
{
throw new JicarillaInstantiationException( e );
}
}
public void releaseInstance( final Object component ) throws Exception
{
if( !m_instances.containsKey( component) )
return;
final ComponentHandler handler =
(ComponentHandler)m_instances.get( component );
handler.put( component );
}
}
--- NEW FILE: FortressContainerBasedSelector.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.integration.avalon;
import org.apache.avalon.fortress.Container;
import org.jicarilla.framework.Assert;
import org.jicarilla.framework.CriterionExposingSelector;
/**
*
*
* @author <a href="mail at leosimons dot com">Leo Simons</a>
* @version $Id: FortressContainerBasedSelector.java,v 1.1 2004/03/08 21:05:24 lsimons Exp $
*/
public class FortressContainerBasedSelector
implements CriterionExposingSelector
{
protected final Container m_container;
public FortressContainerBasedSelector( final Container container )
{
Assert.assertNotNull( "container argument may not be null",
container );
m_container = container;
}
public boolean select( final Object object )
{
if( object == null )
return false;
return m_container.has( object.toString(), null );
}
public Object getCriterion()
{
return m_container;
}
public boolean equals( final Object o )
{
if( this == o )
return true;
if( !(o instanceof FortressContainerBasedSelector) )
return false;
final FortressContainerBasedSelector fortressContainerBasedSelector =
(FortressContainerBasedSelector)o;
if( !m_container.equals( fortressContainerBasedSelector.m_container ) )
return false;
return true;
}
public int hashCode()
{
return m_container.hashCode();
}
}
--- NEW FILE: JicarillaBasedComponentHandler.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.integration.avalon;
import org.apache.avalon.fortress.impl.handler.ComponentHandler;
import org.apache.avalon.framework.CascadingRuntimeException;
import org.jicarilla.container.Adapter;
import org.jicarilla.framework.Assert;
/**
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: JicarillaBasedComponentHandler.java,v 1.1 2004/03/08 21:05:24 lsimons Exp $
*/
public class JicarillaBasedComponentHandler implements ComponentHandler
{
protected final Adapter m_delegate;
public JicarillaBasedComponentHandler( final Adapter delegate )
{
Assert.assertNotNull( "delegate argument may not be null", delegate );
m_delegate = delegate;
}
public Class getComponentClass()
{
try
{
final Object instance = m_delegate.getInstance();
final Class clazz = instance.getClass();
m_delegate.releaseInstance( instance );
return clazz;
}
catch( Exception e )
{
throw new CascadingRuntimeException( e.getMessage(), e );
}
}
public void prepareHandler() throws Exception
{
}
public Object get() throws Exception
{
return m_delegate.getInstance();
}
public void put( final Object component )
{
try
{
m_delegate.releaseInstance( component );
}
catch( Exception e )
{
}
}
}
--- NEW FILE: JicarillaBasedFortressContainer.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.integration.avalon;
import org.apache.avalon.fortress.Container;
import org.apache.avalon.framework.service.ServiceException;
import org.jicarilla.container.Adapter;
import org.jicarilla.container.DefaultContainer;
import org.jicarilla.framework.Switch;
import java.util.HashMap;
import java.util.Map;
/**
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: JicarillaBasedFortressContainer.java,v 1.1 2004/03/08 21:05:24 lsimons Exp $
*/
public class JicarillaBasedFortressContainer extends DefaultContainer
implements Container
{
protected final Map m_handlerMap = new HashMap();
protected final Map m_hintMap = new HashMap();
public Object get( final String key, final Object hint ) throws ServiceException
{
if( key == null )
throw new ServiceException( key, "key argument may not be null" );
if( hint == null )
{
if( super.getResolver().contains( key ) )
{
final Adapter value =
(Adapter)super.m_switch.get( key );
return new JicarillaBasedComponentHandler(
value );
}
}
else
{
final String combinedKey = key + '/' + hint;
if( super.getResolver().contains( combinedKey ) )
{
final Switch.Entry entry =
(Switch.Entry)super.m_switch.get(
combinedKey );
return new JicarillaBasedComponentHandler(
(Adapter)entry.getValue() );
}
}
final String message = "No entry exists for the provided key/hint '" +
key + '/' + hint + "'!";
throw new ServiceException( key, message );
}
public boolean has( final String key, final Object hint )
{
if( hint == null )
{
if( super.getResolver().contains( key ) )
return true;
}
else if( key != null &&
super.getResolver().contains( key + '/' + hint ) )
{
return true;
}
return false;
}
}
--- NEW FILE: ServiceManagerBasedKeyAwareComponentAdapter.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.integration.avalon;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.jicarilla.container.KeyAwareAdapter;
import org.jicarilla.framework.Assert;
import org.jicarilla.framework.CascadingRuntimeException;
/**
*
*
* @author <a href="mail at leosimons dot com">Leo Simons</a>
* @version $Id: ServiceManagerBasedKeyAwareComponentAdapter.java,v 1.1 2004/03/08 21:05:24 lsimons Exp $
*/
public class ServiceManagerBasedKeyAwareComponentAdapter implements KeyAwareAdapter
{
protected final ServiceManager m_delegate;
public ServiceManagerBasedKeyAwareComponentAdapter(
final ServiceManager delegate )
{
Assert.assertNotNull( "delegate argument may not be null", delegate );
m_delegate = delegate;
}
public Object getInstance( final Object key )
{
if( key == null )
return null;
try
{
return m_delegate.lookup( key.toString() );
}
catch( ServiceException e )
{
throw new CascadingRuntimeException( e.getMessage(), e );
}
}
public void releaseInstance( final Object component ) throws Exception
{
m_delegate.release( component );
}
}
--- NEW FILE: ServiceManagerBasedSelector.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.integration.avalon;
import org.apache.avalon.framework.service.ServiceManager;
import org.jicarilla.framework.Assert;
import org.jicarilla.framework.Selector;
/**
*
*
* @author <a href="mail at leosimons dot com">Leo Simons</a>
* @version $Id: ServiceManagerBasedSelector.java,v 1.1 2004/03/08 21:05:24 lsimons Exp $
*/
public class ServiceManagerBasedSelector implements Selector
{
protected final ServiceManager m_delegate;
public ServiceManagerBasedSelector( final ServiceManager delegate )
{
Assert.assertNotNull( "delegate argument may not be null", delegate );
m_delegate = delegate;
}
public boolean select( final Object object )
{
if( object == null )
return false;
return m_delegate.hasService( object.toString() );
}
public boolean equals( final Object o )
{
if( this == o ) return true;
if( !(o instanceof ServiceManagerBasedSelector) ) return false;
final ServiceManagerBasedSelector serviceManagerBasedSelector = (ServiceManagerBasedSelector)o;
if( !m_delegate.equals( serviceManagerBasedSelector.m_delegate ) ) return false;
return true;
}
public int hashCode()
{
return m_delegate.hashCode() + 110;
}
}
-------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.