[sandbox.akabana]/trunk/yui/yui-framework/src/main/flex/org/seasar/akabana/yui/logging/config/factory/LogConfigurationFactory.as
Parent Directory
|
Revision Log
Revision 992 -
(show annotations)
Mon Jan 25 19:55:45 2010 JST (3 years, 3 months ago) by e1arkw
File size: 3873 byte(s)
Mon Jan 25 19:55:45 2010 JST (3 years, 3 months ago) by e1arkw
File size: 3873 byte(s)
ResourceBundleの取り扱いを変更しました。 直接クラス情報を取得しています。
| 1 | /* |
| 2 | * Copyright 2004-2008 the Seasar Foundation and the Others. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 13 | * either express or implied. See the License for the specific language |
| 14 | * governing permissions and limitations under the License. |
| 15 | */ |
| 16 | package org.seasar.akabana.yui.logging.config.factory |
| 17 | { |
| 18 | import flash.errors.IllegalOperationError; |
| 19 | import flash.system.ApplicationDomain; |
| 20 | |
| 21 | import mx.managers.ISystemManager; |
| 22 | import mx.managers.SystemManagerGlobals; |
| 23 | import mx.resources.IResourceManager; |
| 24 | import mx.resources.ResourceBundle; |
| 25 | import mx.resources.ResourceManager; |
| 26 | |
| 27 | import org.seasar.akabana.yui.logging.config.Configuration; |
| 28 | |
| 29 | [ResourceBundle("log4yui")] |
| 30 | public class LogConfigurationFactory implements IConfigurationFactory { |
| 31 | |
| 32 | private static var propertiesConfigFile:ResourceBundle; |
| 33 | |
| 34 | private static function loadResourceBundle(bundleName:String):ResourceBundle { |
| 35 | var locale:String = getCurrentLocale(SystemManagerGlobals.topLevelSystemManagers[0] as ISystemManager); |
| 36 | |
| 37 | var resourceBundleClassName:String = locale + "$" + bundleName + "_properties"; |
| 38 | var bundleClass:Class = null; |
| 39 | var appDomain:ApplicationDomain = ApplicationDomain.currentDomain; |
| 40 | |
| 41 | if(appDomain.hasDefinition(resourceBundleClassName)) |
| 42 | { |
| 43 | bundleClass = appDomain.getDefinition(resourceBundleClassName) as Class; |
| 44 | } |
| 45 | |
| 46 | if( !bundleClass ){ |
| 47 | resourceBundleClassName = bundleName + "_properties"; |
| 48 | |
| 49 | if(appDomain.hasDefinition(resourceBundleClassName)) { |
| 50 | bundleClass = appDomain.getDefinition(resourceBundleClassName) as Class; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | var result:ResourceBundle = new bundleClass() as ResourceBundle; |
| 55 | return result; |
| 56 | } |
| 57 | |
| 58 | private static function getCurrentLocale(sm:ISystemManager):String |
| 59 | { |
| 60 | var result:String = "en_US"; |
| 61 | var compiledLocales:Array = sm.info()["compiledLocales"]; |
| 62 | if (compiledLocales != null && compiledLocales.length == 1){ |
| 63 | result = compiledLocales[0] as String; |
| 64 | } |
| 65 | return result; |
| 66 | } |
| 67 | |
| 68 | public function create():Configuration { |
| 69 | if(propertiesConfigFile == null) { |
| 70 | var resourceManager:IResourceManager = ResourceManager.getInstance(); |
| 71 | var localeChain:Array = resourceManager.localeChain; |
| 72 | var configuration:Configuration; |
| 73 | |
| 74 | if(localeChain != null && localeChain.length > 0) { |
| 75 | propertiesConfigFile = resourceManager.getResourceBundle(localeChain[0],"log4yui") as ResourceBundle; |
| 76 | } else { |
| 77 | propertiesConfigFile = loadResourceBundle("log4yui"); |
| 78 | |
| 79 | if(propertiesConfigFile == null) { |
| 80 | throw new IllegalOperationError("NOT FOUND log4yui.properties"); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if(hasConfiguration()) { |
| 86 | configuration = PropertiesConfigurationBuilder.create(propertiesConfigFile); |
| 87 | } |
| 88 | return configuration; |
| 89 | } |
| 90 | |
| 91 | private function hasConfiguration():Boolean { |
| 92 | return propertiesConfigFile.content.hasOwnProperty(PropertiesConfigurationBuilder.LOG4YUI_ROOT_LOGGER); |
| 93 | } |
| 94 | } |
| 95 | } |
| Repository Top ViewVC Help |
![]() |
| Powered by ViewVC |

