1 55 package org.apache.avalon.framework.component; 56 57 import java.util.HashMap ; 58 import java.util.Map ; 59 60 72 public class DefaultComponentSelector 73 implements ComponentSelector 74 { 75 private final HashMap m_components = new HashMap (); 76 private boolean m_readOnly; 77 78 86 public Component select( Object hint ) 87 throws ComponentException 88 { 89 final Component component = (Component)m_components.get( hint ); 90 91 if( null != component ) 92 { 93 return component; 94 } 95 else 96 { 97 throw new ComponentException( hint.toString(), "Unable to provide implementation." ); 98 } 99 } 100 101 106 public boolean hasComponent( final Object hint ) 107 { 108 boolean componentExists = false; 109 110 try 111 { 112 this.release( this.select( hint ) ); 113 componentExists = true; 114 } 115 catch( Throwable t ) 116 { 117 } 119 120 return componentExists; 121 } 122 123 128 public void release( final Component component ) 129 { 130 } 133 134 139 public void put( final Object hint, final Component component ) 140 { 141 checkWriteable(); 142 m_components.put( hint, component ); 143 } 144 145 150 protected final Map getComponentMap() 151 { 152 return m_components; 153 } 154 155 158 public void makeReadOnly() 159 { 160 m_readOnly = true; 161 } 162 163 168 protected final void checkWriteable() 169 throws IllegalStateException 170 { 171 if( m_readOnly ) 172 { 173 throw new IllegalStateException 174 ( "ComponentSelector is read only and can not be modified" ); 175 } 176 } 177 } 178 | Popular Tags |