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.common;
017    
018    /**
019     * 共通的に使用されるエクセプションクラスですã?
020     *
021     * RuntimeException を継承してã�?‚‹ため、try{} catch() {} は不要ですã?
022     * 本シスãƒ?ƒ では、すべてこã?エクセプションクラスを継承させたクラスを作æ?しã?用途によってã€?
023     * 使ã�??けるようにしますã?つまりã?他ã?どのような、Throwable が発生したとしてもã?ä¸?—¦ã€?
024     * try{} catch() {} で受けて、このクラスのサブクラスをã?再度 throw させますã?
025     * そして、å¿?¦�であれば、try{} catch() {} を用ã�?�¦捕まえて、それぞれã?対応å?ç�?‚’行いますã?
026     *
027     * こã?クラスには、å?ã€??発生したエクセプション( Throwable )を引数にとりã?
028     * そã? printStackTrace()æƒ??をã?自åˆ??身のトレースæƒ??に含めますã?
029     * またã?引数にオブジェクトを渡すことができますã?で、object.toString() で、オブジェクトã?
030     * 状態を表示できるようにしておけば、手軽にãƒ?ƒ�ãƒ?‚°に使ã�?�“とが可能になりますã?
031     *
032     * @og.group エラー処ç�?
033     *
034     * @version  4.0
035     * @author   Kazuhiko Hasegawa
036     * @since    JDK5.0,
037     */
038    public class HybsSystemException extends RuntimeException {
039            private static final long serialVersionUID = 400020050131L ;
040    
041            /** シスãƒ?ƒ 依存ã?改行記号をセãƒ?ƒˆしますã?  */
042    //      private static final String CR = System.getProperty("line.separator");
043    
044            /**
045             *  詳細メãƒ?‚»ージを指定しなã�?�§ HybsSystemException を構築しますã?
046             *
047             */
048            public HybsSystemException() {
049                    // 4.3.4.4 (2009/01/01)
050    //              super();
051            }
052    
053            /**
054             *  æŒ?®šされた詳細メãƒ?‚»ージを持つ HybsSystemException を構築しますã?
055             *
056             * @param       str     詳細メãƒ?‚»ージ
057             */
058            public HybsSystemException( final String str ) {
059                    super( str );
060            }
061    
062            /**
063             *  æŒ?®šされた詳細メãƒ?‚»ージを持つ HybsSystemException を構築しますã?
064             *
065             * @param       th      例外Throwableオブジェクãƒ?
066             */
067            public HybsSystemException( final Throwable th ) {
068                    super( th );
069            }
070    
071            /**
072             *  æŒ?®šされたオブジェクトを受け取る HybsSystemException を構築しますã?
073             *
074             * @og.rev 3.5.5.4 (2004/04/15) 引数をã?RuntimeException(String , Throwable )にあわせますã?
075             *
076             * @param       str     詳細メãƒ?‚»ージ
077             * @param       th      例外Throwableオブジェクãƒ?
078             * @see         java.lang.RuntimeException#RuntimeException(String,Throwable)
079             */
080            public HybsSystemException( final String str,final Throwable th ) {
081                    super( str,th );
082            }
083    
084            /**
085             * こã? Throwable オブジェクトã?詳細メãƒ?‚»ージæ–?­—å?を返しますã?
086             * こã?クラスは、発生å?の Throwable の StackTrace をã?例外チェーン機è?
087             * を利用して取得してã�?�¾すã?
088             * またã?"org.opengion." を含ã‚?‚¹タãƒ?‚¯トレースのみ、メãƒ?‚»ージとして追åŠ?�—ますã?
089             *
090             * @og.rev 4.0.0.0 (2005/01/31) 例外チェーンを遡ってメãƒ?‚»ージをå?力しますã?
091             *
092             * @param  thIn Throwableオブジェクãƒ?
093             *
094             * @return  Throwableの詳細メãƒ?‚»ージ
095             */
096    //      public static String getLongMessage( final Throwable thIn ) {
097    //              StringBuilder buf   = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
098    //              StringBuilder trace = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
099    //
100    //              buf.append( CR );
101    //              buf.append( "Version :" ).append( BuildNumber.ENGINE_INFO ).append( CR );
102    //
103    //              Throwable th = thIn ;
104    //              while( th != null ) {
105    //                      trace = getStackData( trace,th );
106    //                      if( th instanceof HybsSystemException ) {
107    //                              buf.append( th.getMessage() );
108    //                      }
109    //                      else {
110    //                              String msg = th.getMessage();
111    //                              if( msg != null && buf.indexOf( msg ) < 0 ) {
112    //                                      buf.append( msg );
113    //                              }
114    //                      }
115    //                      buf.append( CR );
116    //                      th = th.getCause();
117    //              }
118    //
119    //              buf.append( trace.toString() );
120    //              return buf.toString();
121    //      }
122    
123            /**
124             * "org.opengion." を含ã‚?StackTraceElement のメãƒ?‚»ージæ–?­—å?を返しますã?
125             *
126             * @og.rev 4.0.0.0 (2005/01/31) 新規追åŠ?
127             *
128             * @param  buf StringBuilder 以前ã?エラーメãƒ?‚»ージ
129             * @param  th  Throwable スタãƒ?‚¯トレースを取りå?すThrowableオブジェクãƒ?
130             *
131             * @return  "org.opengion." を含ã‚?StackTraceElement のメãƒ?‚»ージ
132             */
133    //      private static StringBuilder getStackData( final StringBuilder buf,final Throwable th ) {
134    //              if( th != null ) {
135    //                      int cnt = 0;
136    //                      StackTraceElement[] trace = th.getStackTrace();
137    //                      for( int i=0; i<trace.length; i++ ) {
138    //                              String msg = trace[i].toString();
139    //                              if( buf.indexOf( msg ) < 0 ) {
140    //                                      if( msg != null && msg.indexOf( "org.opengion." ) >= 0 ) {
141    //                                              buf.append( "\tat " ).append( msg ).append( CR );
142    //                                      }
143    //                                      else if( cnt++ < 5 ) {
144    //                                              buf.append( "\tat " ).append( msg ).append( CR );
145    //                                      }
146    //                                      else if( cnt++ == 5 ) {
147    //                                              buf.append( "\t   ......" ).append( CR );
148    //                                      }
149    //                              }
150    //                      }
151    //                      buf.append( "\t   ... more ..." ).append( CR );
152    //              }
153    //              return buf;
154    //      }
155    }