001 /* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016 package org.opengion.hayabusa.db; 017 018 import org.opengion.hayabusa.common.HybsSystem; 019 import org.opengion.hayabusa.common.SystemManager; 020 import org.opengion.fukurou.util.Cleanable; 021 022 import java.util.Map; 023 import java.util.HashMap; 024 import java.util.Locale ; 025 026 /** 027 * DBCellRenderer/DBCellEditor オブジェクトを取得する為に使用する?ファクトリクラスです? 028 * 029 * DBCell オブジェク?の識別ID を?に、DBCellFactory.newInstance( String id ) 030 * メソ?で?DBCell オブジェクトを取得します? 031 * 032 * @og.group ??タ表示 033 * @og.group ??タ編? 034 * 035 * @version 4.0 036 * @author Kazuhiko Hasegawa 037 * @since JDK5.0, 038 */ 039 public final class DBCellFactory { 040 private static final String DEFAULT_RENDERER = "LABEL"; 041 private static final String DEFAULT_EDITOR = "TEXT"; 042 private static final Map<String,CellRenderer> rMap = new HashMap<String,CellRenderer>(); 043 private static final Map<String,CellEditor> eMap = new HashMap<String,CellEditor>(); 044 045 // 4.0.0 (2005/01/31) Cleanable インターフェースによる初期化?? 046 static { 047 Cleanable clr = new Cleanable() { 048 public void clear() { 049 DBCellFactory.clear(); 050 } 051 }; 052 053 SystemManager.addCleanable( clr ); 054 } 055 056 /** 057 * ?ォルトコンストラクターをprivateにして? 058 * オブジェクト?生?をさせな??する? 059 * 060 */ 061 private DBCellFactory() { 062 } 063 064 /** 065 * 識別id に応じ?DBCell オブジェクトを取得します? 066 * 067 * @og.rev 2.1.2.1 (2002/11/27) id が指定されて???合? ?ォルトを?するよ?変更? 068 * @og.rev 3.1.1.1 (2003/04/03) DBCell のファクトリクラスに DBColumn オブジェクトを渡す? 069 * @og.rev 3.1.2.1 (2003/04/10) synchronized の方法を修正? 070 * @og.rev 3.5.6.0 (2004/06/18) ?プラグイン関連付け設定を、シス?パラメータ に記述します? 071 * @og.rev 4.0.0.0 (2005/01/31) キーの?を、Renderer. から、Renderer_ に変更します? 072 * 073 * @param id DBCell インターフェースを実?たサブクラスの識別id 074 * @param clm DBColumnオブジェク? 075 * 076 * @return DBCellオブジェク? 077 */ 078 public static CellRenderer newRenderer( final String id,final DBColumn clm ) { 079 String type = ( id == null ) ? DEFAULT_RENDERER : id.toUpperCase(Locale.JAPAN) ; 080 String cls = HybsSystem.sys( "Renderer_" + type ); // 4.0.0 (2005/01/31) 081 082 CellRenderer cell; 083 synchronized( rMap ) { 084 cell = rMap.get( type ); 085 if( cell == null ) { 086 cell = (CellRenderer)HybsSystem.newInstance( cls ); // 3.5.5.3 (2004/04/09) 087 rMap.put( type,cell ); 088 } 089 } 090 return cell.newInstance( clm ); 091 } 092 093 /** 094 * 識別id に応じ?DBCell オブジェクトを取得します? 095 * 096 * @og.rev 2.1.2.1 (2002/11/27) id が指定されて???合? ?ォルトを?するよ?変更? 097 * @og.rev 3.1.1.1 (2003/04/03) DBCell のファクトリクラスに DBColumn オブジェクトを渡す? 098 * @og.rev 3.1.2.1 (2003/04/10) synchronized の方法を修正? 099 * @og.rev 3.5.6.0 (2004/06/18) ?プラグイン関連付け設定を、シス?パラメータ に記述します? 100 * @og.rev 4.0.0.0 (2005/01/31) キーの?を、Editor. から、Editor_ に変更します? 101 * 102 * @param id DBCell インターフェースを実?たサブクラスの識別id 103 * @param clm DBColumnオブジェク? 104 * 105 * @return DBCellオブジェク? 106 */ 107 public static CellEditor newEditor( final String id,final DBColumn clm ) { 108 String type = ( id == null ) ? DEFAULT_EDITOR : id.toUpperCase(Locale.JAPAN) ; 109 String cls = HybsSystem.sys( "Editor_" + type ); // 4.0.0 (2005/01/31) 110 111 CellEditor cell; 112 synchronized( eMap ) { 113 cell = eMap.get( type ); 114 if( cell == null ) { 115 cell = (CellEditor)HybsSystem.newInstance( cls ); // 3.5.5.3 (2004/04/09) 116 eMap.put( type,cell ); 117 } 118 } 119 return cell.newInstance( clm ); 120 } 121 122 /** 123 * DBCell オブジェクトをプ?ルからすべて削除します? 124 * シス?全体を初期化するときや、動作が不安定になったときに行います? 125 * プ?ルの方法?体が,?のキャ?ュ?使?たしかして??, 126 * 実行中でも??でも?ールを?期化できます? 127 * 128 * @og.rev 3.1.1.1 (2003/04/03) キャ?ュクリアメソ?を新規追?? 129 * @og.rev 3.1.2.1 (2003/04/10) synchronized の方法を修正? 130 */ 131 public static void clear() { 132 synchronized( rMap ) { rMap.clear(); } 133 synchronized( eMap ) { eMap.clear(); } 134 } 135 }