jicarilla-sandbox/platform/container/impl/src/java/org/jicarilla/container/builder CustomComponent.java,NONE,1.1 CustomComponentHelper.java,NONE,1.1 DefaultBuilder.java,1.13,1.14 ResolverHelper.java,1.5,1.6

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/builder
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24598/platform/container/impl/src/java/org/jicarilla/container/builder

Modified Files:
	DefaultBuilder.java ResolverHelper.java 
Added Files:
	CustomComponent.java CustomComponentHelper.java 
Log Message:
its now possible to do stuff like...
        builder.addComponent(
                SocketServer.class,
                new CustomComponent( SocketServerImpl.class )
                    .redirectCall( 3, "event-pool" )
                    .redirectCall( 4, "pipeline-pool" )
                    .redirectCall( 5, "error-handler" )
        );
        
...testing remains a TODO.

Index: ResolverHelper.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/container/impl/src/java/org/jicarilla/container/builder/ResolverHelper.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ResolverHelper.java	23 Mar 2004 13:37:52 -0000	1.5
+++ ResolverHelper.java	23 Mar 2004 15:59:52 -0000	1.6
@@ -27,7 +27,7 @@
 
 import org.jicarilla.container.KeyAwareAdapter;
 import org.jicarilla.container.Resolver;
-import org.jicarilla.container.adapters.ResolverBasedAdapter;
+import org.jicarilla.container.adapters.ResolverBasedKeyAwareAdapter;
 import org.jicarilla.container.selectors.ResolverSelector;
 import org.jicarilla.lang.Selector;
 
@@ -42,7 +42,7 @@
     public KeyAwareAdapter getAdapter( final Object provider )
             throws Exception
     {
-        return new ResolverBasedAdapter( (Resolver)provider );
+        return new ResolverBasedKeyAwareAdapter( (Resolver)provider );
     }
 
     public Selector getSelector( final Object provider ) throws Exception

--- NEW FILE: CustomComponent.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.builder;

import org.jicarilla.container.CustomizableResolver;
import org.jicarilla.container.DefaultCustomizableResolver;
import org.jicarilla.container.Resolver;
import org.jicarilla.lang.Assert;
import org.jicarilla.lang.Selector;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Use to override parts of the default autowiring policy for a particular
 * component.
 *
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: CustomComponent.java,v 1.1 2004/03/23 15:59:52 lsimons Exp $
 */
public class CustomComponent
{
    // ----------------------------------------------------------------------
    //  Properties
    // ----------------------------------------------------------------------
    protected Class m_class;
    protected List m_overrides;
    
    // ----------------------------------------------------------------------
    //  Constructor
    // ----------------------------------------------------------------------
    public CustomComponent( Class clazz )
    {
        Assert.assertNotNull( "clazz argument may not be null", clazz );
        m_class = clazz;
        
        m_overrides = new ArrayList();
    }
    
    // ----------------------------------------------------------------------
    //  Public API
    // ----------------------------------------------------------------------
    public CustomComponent overrideKey(
            Object key, Object instance )
    {
        m_overrides.add( new KeyOverride( key, instance ) );
        return this;
    }
    
    public CustomComponent override(
            Selector selector, Object instance )
    {
        m_overrides.add( new SelectorOverride( selector, instance ) );
        return this;
    }
    
    /**
     * 
     * @param callNumber index starts at 0
     * @param instance
     */ 
    public CustomComponent overrideCall(
            int callNumber, Object instance )
    {
        m_overrides.add( new CallOverride( callNumber, instance ) );
        return this;
    }
    
    public CustomComponent redirectKey(
            Object oldKey, Object newKey )
    {
        m_overrides.add( new KeyRedirect( oldKey, newKey ) );
        return this;
    }

    public CustomComponent redirectCall(
            int callNumber, Object newKey )
    {
        m_overrides.add( new CallRedirect( callNumber, newKey ) );
        return this;
    }
    
    // ----------------------------------------------------------------------
    //  Internal API
    // ----------------------------------------------------------------------
    Class getClazz()
    {
        return m_class;
    }
    Resolver getResolver( Resolver delegate )
    {
        CustomizableResolver resolver =
                new DefaultCustomizableResolver( delegate );
        
        final Iterator it = m_overrides.iterator();
        while( it.hasNext() )
        {
            Object o = it.next();
            if( o instanceof KeyOverride )
            {
                KeyOverride ko = (KeyOverride)o;
                resolver.overrideKey( ko.key, ko.instance );
            }
            else if( o instanceof SelectorOverride )
            {
                SelectorOverride so = (SelectorOverride)o;
                resolver.overrideKey( so.selector, so.instance );
            }
            else if( o instanceof CallOverride )
            {
                CallOverride co = (CallOverride)o;
                resolver.overrideCall( co.call, co.instance );
            }
            else if( o instanceof KeyRedirect )
            {
                KeyRedirect kr = (KeyRedirect)o;
                resolver.redirectKey( kr.key, kr.newKey );
            }
            else if( o instanceof CallRedirect )
            {
                CallRedirect cr = (CallRedirect)o;
                resolver.redirectCall( cr.call, cr.newKey );
            }
        }
        return resolver;
    }

    protected class KeyOverride
    {
        public Object key;
        public Object instance;

        public KeyOverride( Object key, Object instance )
        {
            this.key = key;
            this.instance = instance;
        }
    };
    
    protected class SelectorOverride
    {
        public Selector selector;
        public Object instance;

        public SelectorOverride( Selector selector, Object instance )
        {
            this.selector = selector;
            this.instance = instance;
        }
    };
    
    protected class CallOverride
    {
        public int call;
        public Object instance;

        public CallOverride( int call, Object instance )
        {
            this.call = call;
            this.instance = instance;
        }
    };
    
    protected class KeyRedirect
    {
        public Object key;
        public Object newKey;

        public KeyRedirect( Object key, Object newKey )
        {
            this.key = key;
            this.newKey = newKey;
        }
    };
    protected class CallRedirect
    {
        public int call;
        public Object newKey;

        public CallRedirect( int call, Object newKey )
        {
            this.call = call;
            this.newKey = newKey;
        }
    };
}

Index: DefaultBuilder.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/container/impl/src/java/org/jicarilla/container/builder/DefaultBuilder.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- DefaultBuilder.java	23 Mar 2004 13:37:52 -0000	1.13
+++ DefaultBuilder.java	23 Mar 2004 15:59:52 -0000	1.14
@@ -25,23 +25,23 @@
 ==================================================================== */
 package org.jicarilla.container.builder;
 
-import org.jicarilla.container.Container;
 import org.jicarilla.container.Adapter;
+import org.jicarilla.container.Container;
+import org.jicarilla.container.DefaultKeyRelayingContainer;
 import org.jicarilla.container.KeyAwareAdapter;
+import org.jicarilla.container.KeyRelayingContainer;
 import org.jicarilla.container.Resolver;
 import org.jicarilla.container.ResolverProvider;
-import org.jicarilla.container.KeyRelayingContainer;
-import org.jicarilla.container.DefaultKeyRelayingContainer;
-import org.jicarilla.container.factories.Type3Factory;
-import org.jicarilla.container.factories.ManualFactory;
 import org.jicarilla.container.adapters.SingletonAdapter;
+import org.jicarilla.container.factories.ManualFactory;
+import org.jicarilla.container.factories.Type3Factory;
 import org.jicarilla.container.selectors.InstanceofSelector;
 import org.jicarilla.lang.Assert;
 import org.jicarilla.lang.Selector;
 
-import java.util.List;
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 
 /**
  * <p>A Builder implementation that's backed by a container itself. In essence,
@@ -139,6 +139,11 @@
     public Resolver create() throws Exception
     {
         doPopulate();
+        return getResolver();
+    }
+    
+    public Resolver getResolver()
+    {
         return m_container.getResolver();
     }
 
@@ -268,6 +273,10 @@
                 Entry.class,
                 EntryHelper.class
         );
+        addHelper(
+                CustomComponent.class,
+                CustomComponentHelper.class
+        );
 
         // --------------------------------------------------------------------
         // Basics

--- NEW FILE: CustomComponentHelper.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.builder;

import org.jicarilla.container.KeyAwareAdapter;
import org.jicarilla.container.Resolver;
import org.jicarilla.lang.Assert;
import org.jicarilla.lang.Selector;

/**
 * 
 *
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: CustomComponentHelper.java,v 1.1 2004/03/23 15:59:52 lsimons Exp $
 */
public class CustomComponentHelper extends SingletonType35Helper
{
    public KeyAwareAdapter getAdapter( final Object provider,
            final Resolver resolver )
            throws Exception
    {
        Assert.assertNotNull( "provider argument may not be null", provider );
        CustomComponent cc = (CustomComponent)provider;
        
        return super.getAdapter( cc.getClazz(), cc.getResolver( resolver) );
    }

    public Selector getSelector( final Object provider ) throws Exception
    {
        return super.getSelector( ((CustomComponent)provider).getClazz() );
    }
}



-------------------------------------------------------
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.