1 87 package org.codehaus.loom.components.application; 88 89 import java.io.File ; 90 import java.io.InputStream ; 91 import org.apache.avalon.framework.context.ContextException; 92 import org.apache.avalon.framework.logger.Logger; 93 import org.apache.avalon.phoenix.BlockContext; 94 import org.codehaus.loom.interfaces.ApplicationContext; 95 96 101 final class DefaultBlockContext 102 implements BlockContext 103 { 104 private final String m_name; 105 private final ApplicationContext m_applicationContext; 106 107 DefaultBlockContext( final String name, 108 final ApplicationContext frame ) 109 { 110 m_name = name; 111 m_applicationContext = frame; 112 } 113 114 public Object get( final Object key ) 115 throws ContextException 116 { 117 if( BlockContext.APP_NAME.equals( key ) ) 118 { 119 return m_applicationContext.getPartitionProfile() 120 .getMetaData() 121 .getName(); 122 } 123 else if( BlockContext.APP_HOME_DIR.equals( key ) ) 124 { 125 return getBaseDirectory(); 126 } 127 else if( BlockContext.NAME.equals( key ) ) 128 { 129 return getName(); 130 } 131 else 132 { 133 throw new ContextException( "Unknown key: " + key ); 134 } 135 } 136 137 142 public File getBaseDirectory() 143 { 144 return m_applicationContext.getHomeDirectory(); 145 } 146 147 152 public String getName() 153 { 154 return m_name; 155 } 156 157 public void requestShutdown() 158 { 159 m_applicationContext.requestShutdown(); 160 } 161 162 public InputStream getResourceAsStream( final String name ) 163 { 164 return m_applicationContext.getResourceAsStream( name ); 165 } 166 167 public Logger getLogger( final String name ) 168 { 169 try 170 { 171 return m_applicationContext.getLogger( getName() ).getChildLogger( 172 name ); 173 } 174 catch( Exception e ) 175 { 176 final String message = 177 "Unable to aquire logger " + name + " due to " + e; 178 throw new IllegalStateException ( message ); 179 } 180 } 181 } 182 | Popular Tags |