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.penguin.common; 017 018 019/** 020 * 共通的に使用されるメソッドを集約したクラスです。 021 * 022 * hayabusのcommon.HybsSystemと役割としてはほぼ同じです。 023 * パッケージ間の依存を切るためにこちらにも最小限の機能を持たせておきます。 024 * 025 * @og.group 初期化 026 * 027 * @version 4.0 028 * @author Takahashi Masakazu 029 * @since JDK5.0, 030 */ 031public final class SystemUtil { 032 033 /** システム依存の改行記号をセットします。 */ 034 public static final String CR = System.getProperty("line.separator"); 035 036 /** HTMLでの改行記号( <br /> )をセットします。 */ 037 public static final String BR = "<br />" + CR ; 038 039 /** システム依存のファイルセパレーター文字をセットします。 */ 040 public static final char FS = System.getProperty("file.separator").charAt(0); 041 042 /** 043 * デフォルトコンストラクターをprivateにして、 044 * オブジェクトの生成をさせないようにする。 045 * 046 */ 047 private SystemUtil() {} 048 049 /** 050 * 指定されたクラスローダを使って、識別id に応じた オブジェクトを作成します。 051 * 作成するには、デフォルトコンストラクターが必要です。 052 * initialize パラメータは true 相当(それまでに初期化されていない場合だけ初期化)です。 053 * 054 * @param cls 作成するクラスのフルネーム 055 * 056 * @return オブジェクト 057 * @throws RuntimeException 何らかのエラーが発生した場合 058 */ 059 public static Object newInstance( final String cls ) { 060 try { 061 return Class.forName( cls ).newInstance(); 062 } 063 catch( ClassNotFoundException ex1 ) { 064 String errMsg = "クラスが見つかりません。class=[" + cls + "]" + CR 065 + ex1.getMessage() ; 066 throw new RuntimeException( errMsg,ex1 ); 067 } 068 catch( LinkageError ex2 ) { 069 String errMsg = "リンケージが失敗しました。class=[" + cls + "]" + CR 070 + ex2.getMessage(); 071 throw new RuntimeException( errMsg,ex2 ); 072 } 073 catch( InstantiationException ex3 ) { 074 String errMsg = "インスタンスの生成が失敗しました。class=[" + cls + "]" + CR 075 + ex3.getMessage() ; 076 throw new RuntimeException( errMsg,ex3 ); 077 } 078 catch( IllegalAccessException ex4 ) { 079 String errMsg = "クラスまたは初期化子にアクセスできません。class=[" + cls + "]" + CR 080 + ex4.getMessage(); 081 throw new RuntimeException( errMsg,ex4 ); 082 } 083 catch( RuntimeException ex5 ) { // 3.6.0.0 (2004/09/17) 084 String errMsg = "予期せぬエラー class=[" + cls + "]" + CR 085 + ex5.getMessage() ; 086 throw new RuntimeException( errMsg,ex5 ); 087 } 088 } 089}