1 8 package org.apache.avalon.phoenix.components.application; 9 10 import java.io.File ; 11 import java.io.InputStream ; 12 import org.apache.avalon.framework.context.ContextException; 13 import org.apache.avalon.framework.logger.Logger; 14 import org.apache.avalon.phoenix.BlockContext; 15 import org.apache.avalon.phoenix.interfaces.ApplicationContext; 16 import org.apache.avalon.phoenix.metadata.SarMetaData; 17 18 23 final class DefaultBlockContext 24 implements BlockContext 25 { 26 private String m_name; 27 private ApplicationContext m_applicationContext; 28 29 protected DefaultBlockContext( final String name, 30 final ApplicationContext frame ) 31 { 32 m_name = name; 33 m_applicationContext = frame; 34 } 35 36 public Object get( Object key ) 37 throws ContextException 38 { 39 final SarMetaData metaData = m_applicationContext.getMetaData(); 40 if( BlockContext.APP_NAME.equals( key ) ) 41 { 42 return metaData.getName(); 43 } 44 else if( BlockContext.APP_HOME_DIR.equals( key ) ) 45 { 46 return metaData.getHomeDirectory(); 47 } 48 else if( BlockContext.NAME.equals( key ) ) 49 { 50 return m_name; 51 } 52 else 53 { 54 throw new ContextException( "Unknown key: " + key ); 55 } 56 } 57 58 63 public File getBaseDirectory() 64 { 65 return m_applicationContext.getMetaData().getHomeDirectory(); 66 } 67 68 73 public String getName() 74 { 75 return m_name; 76 } 77 78 public void requestShutdown() 79 { 80 m_applicationContext.requestShutdown(); 81 } 82 83 public InputStream getResourceAsStream( final String name ) 84 { 85 return m_applicationContext.getResourceAsStream( name ); 86 } 87 88 93 public Logger getLogger( final String name ) 94 { 95 return m_applicationContext.getLogger( getName() ).getChildLogger( name ); 96 } 97 } 98 | Popular Tags |