1 19 20 package org.apache.avalon.fortress.impl.lookup.test; 21 22 import junit.framework.TestCase; 23 import org.apache.avalon.fortress.Container; 24 import org.apache.avalon.fortress.impl.AbstractContainer; 25 import org.apache.avalon.fortress.impl.lookup.FortressServiceManager; 26 import org.apache.avalon.fortress.impl.lookup.FortressServiceSelector; 27 import org.apache.avalon.fortress.impl.test.TestComponentHandler; 28 import org.apache.avalon.fortress.test.data.Role1; 29 import org.apache.avalon.framework.service.ServiceException; 30 import org.apache.avalon.framework.service.ServiceSelector; 31 32 public class TestContainer implements Container 33 { 34 private String m_key; 35 private Object m_hint = AbstractContainer.DEFAULT_ENTRY; 36 private TestComponentHandler m_component; 37 private FortressServiceSelector m_selector; 38 39 public TestContainer() { 40 m_component = new TestComponentHandler(); 41 } 42 43 public void setExpectedKey( String key ) 44 { 45 m_key = key; 46 m_selector = new FortressServiceSelector( this, m_key ); 47 } 48 49 public void setExpectedHint( Object hint ) 50 { 51 m_hint = hint; 52 } 53 54 public Object get( String key, Object hint ) throws ServiceException 55 { 56 if ( exists( key, hint ) ) 57 { 58 if ( hint.equals( AbstractContainer.SELECTOR_ENTRY ) ) 59 { 60 return m_selector; 61 } 62 else 63 { 64 return m_component; 65 } 66 } 67 68 throw new ServiceException( m_key, "Unexpected key/hint combo" ); 69 } 70 71 public boolean has( String key, Object hint ) 72 { 73 if ( exists( key, hint ) ) 74 { 75 return true; 76 } 77 78 return false; 79 } 80 81 private boolean exists( String key, Object hint ) 82 { 83 boolean exists = false; 84 85 if ( m_key.equals( key ) ) 86 { 87 if ( null == m_hint ) 88 { 89 exists = hint == null; 90 } 91 else 92 { 93 exists = m_hint.equals( hint ); 94 } 95 } 96 97 return exists; 98 } 99 } 100 | Popular Tags |