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 */ 016package org.opengion.plugin.column; 017 018import org.opengion.hayabusa.db.AbstractRenderer; 019import org.opengion.hayabusa.db.CellRenderer; 020import org.opengion.hayabusa.db.DBColumn; 021 022import org.opengion.hayabusa.resource.ResourceFactory; 023import org.opengion.hayabusa.resource.ResourceManager; 024 025/** 026 * DBLABEL レンデラーは、値をラベルリソースの表示ラベルに変換するクラスです。 027 * 028 * DBMENU で同様の処理を記述できますが、ラベルリソース に限定した使い方を 029 * 想定してます。 030 * 031 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 032 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 033 * 034 * @og.rev 4.0.0.0 (2006/11/16) 新規作成 035 * @og.group データ表示 036 * 037 * @version 4.0 038 * @author Kazuhiko Hasegawa 039 * @since JDK5.0, 040 */ 041public class Renderer_DBLABEL extends AbstractRenderer { 042 //* このプログラムのVERSION文字列を設定します。 {@value} */ 043 private static final String VERSION = "4.0.0.0 (2006/11/16)" ; 044 045 private static final CellRenderer dbCell = new Renderer_DBLABEL() ; 046 047 private final ResourceManager resource ; 048 049 /** 050 * デフォルトコンストラクター。 051 * このコンストラクターで、基本オブジェクトを作成します。 052 * 053 */ 054 public Renderer_DBLABEL() { 055 resource = ResourceFactory.newInstance( "ja" ); // 日本語だけ特別 056 } 057 058 /** 059 * デフォルトコンストラクター。 060 * 061 * @param clm DBColumnオブジェクト 062 */ 063 private Renderer_DBLABEL( final DBColumn clm ) { 064 String lang = clm.getLang(); 065 resource = ResourceFactory.newInstance( lang ); 066 } 067 068 /** 069 * 各オブジェクトから自分のインスタンスを返します。 070 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 071 * まかされます。 072 * 073 * @param clm DBColumnオブジェクト 074 * 075 * @return CellRendererオブジェクト 076 */ 077 public CellRenderer newInstance( final DBColumn clm ) { 078 if( "ja".equalsIgnoreCase( clm.getLang() ) ) { 079 return dbCell ; 080 } 081 082 return new Renderer_DBLABEL( clm ); 083 } 084 085 /** 086 * データの表示用文字列を返します。 087 * 088 * @param value 入力値 089 * 090 * @return データの表示用文字列 091 */ 092 @Override 093 public String getValue( final String value ) { 094 if( value == null || value.length() == 0 ) { return ""; } 095 096 return resource.getLabel( value ); 097 } 098}