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     * @og.rev 5.6.7.1 (2013/08/09) エラーに、エンジンのバã?ジョン等ã?シスãƒ?ƒ 関係ã?æƒ??を付与しますã?
034     *
035     * @version  4.0
036     * @author   Kazuhiko Hasegawa
037     * @since    JDK5.0,
038     */
039    public class HybsSystemException extends RuntimeException {
040            private static final long serialVersionUID = 567120130809L ;
041    
042            /** シスãƒ?ƒ 依存ã?改行記号をセãƒ?ƒˆしますã?  */
043            private static final String CR = System.getProperty("line.separator");
044    
045            /** ?”タブã?代わりのスペã?ス */
046            private static final String TAB = "    " ;
047    
048            /** エラーメãƒ?‚»ージに付与するシスãƒ?ƒ 関係ã?æƒ?? 5.6.7.3 (2013/08/23) */
049            private static final String ERR_INFO =
050                                                            "  -------- Exception Information ---------"    + CR
051                                                    +       TAB               + HybsSystem.sys( "OS_INFO"      )    + CR            // Windows 7 Service Pack 1
052                                                    +       TAB               + HybsSystem.sys( "SERVER_INFO"  )    + CR            // 10374232-0004 ( 200.1.50.239 )
053                                                    +       TAB               + HybsSystem.sys( "SERVLET_INFO" )    + CR            // Apache Tomcat/7.0.42
054                                                    +       TAB + TAB + HybsSystem.sys( "TOMCAT_HOME"  )    + CR            // C:/opengionV6/uap/bin/../../apps/tomcat7.0.42
055                                                    +       TAB               + HybsSystem.sys( "JDK_INFO"     )    + CR            // Java HotSpot(TM) Server VM 23.25-b01
056                                                    +       TAB + TAB + HybsSystem.sys( "JAVA_HOME"    )    + CR            // H:/java/tomcat5.5.17
057                                                    +       TAB               + HybsSystem.sys( "ENGINE_INFO"  )    + CR            // 5.6.6.0 Release5 Builds (2013182)
058                                                    +       TAB + TAB + HybsSystem.sys( "REAL_PATH"    )                            // C:/opengionV6/uap/webapps/gf/
059                                                    +       TAB + "(" + HybsSystem.sys( "SYSTEM_ID"    )    + ")" + CR      // GF
060                                                    +       "  ----------------------------------------"    + CR ;
061    
062            /**
063             *  詳細メãƒ?‚»ージを指定しなã�?�§ HybsSystemException を構築しますã?
064             *
065             * @og.rev 5.6.7.1 (2013/08/09) エラーに、エンジンのバã?ジョン等ã?æƒ??を付与しますã?
066             */
067            public HybsSystemException() {
068                    // 4.3.4.4 (2009/01/01)
069    //              super();
070                    System.err.println( ERR_INFO );
071            }
072    
073            /**
074             *  æŒ?®šされた詳細メãƒ?‚»ージを持つ HybsSystemException を構築しますã?
075             *
076             * @og.rev 5.6.7.1 (2013/08/09) エラーに、エンジンのバã?ジョン等ã?æƒ??を付与しますã?
077             *
078             * @param       str     詳細メãƒ?‚»ージ
079             */
080            public HybsSystemException( final String str ) {
081                    super( str );
082                    System.err.println( ERR_INFO );
083            }
084    
085            /**
086             *  æŒ?®šされた詳細メãƒ?‚»ージを持つ HybsSystemException を構築しますã?
087             *
088             * @og.rev 5.6.7.1 (2013/08/09) エラーに、エンジンのバã?ジョン等ã?æƒ??を付与しますã?
089             *
090             * @param       th      例外Throwableオブジェクãƒ?
091             */
092            public HybsSystemException( final Throwable th ) {
093                    super( th );
094                    System.err.println( ERR_INFO );
095            }
096    
097            /**
098             *  æŒ?®šされたオブジェクトを受け取る HybsSystemException を構築しますã?
099             *
100             * @og.rev 3.5.5.4 (2004/04/15) 引数をã?RuntimeException(String , Throwable )にあわせますã?
101             * @og.rev 5.6.7.1 (2013/08/09) エラーに、エンジンのバã?ジョン等ã?æƒ??を付与しますã?
102             *
103             * @param       str     詳細メãƒ?‚»ージ
104             * @param       th      例外Throwableオブジェクãƒ?
105             * @see         java.lang.RuntimeException#RuntimeException(String,Throwable)
106             */
107            public HybsSystemException( final String str,final Throwable th ) {
108                    super( str,th );
109                    System.err.println( ERR_INFO );
110            }
111    
112            /**
113             * こã? Throwable オブジェクトã?詳細メãƒ?‚»ージæ–?­—å?を返しますã?
114             * こã?クラスは、発生å?の Throwable の StackTrace をã?例外チェーン機è?
115             * を利用して取得してã�?�¾すã?
116             * またã?"org.opengion." を含ã‚?‚¹タãƒ?‚¯トレースのみ、メãƒ?‚»ージとして追åŠ?�—ますã?
117             *
118             * @og.rev 4.0.0.0 (2005/01/31) 例外チェーンを遡ってメãƒ?‚»ージをå?力しますã?
119             *
120             * @param  thIn Throwableオブジェクãƒ?
121             *
122             * @return  Throwableの詳細メãƒ?‚»ージ
123             */
124    //      public static String getLongMessage( final Throwable thIn ) {
125    //              StringBuilder buf   = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
126    //              StringBuilder trace = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
127    //
128    //              buf.append( CR );
129    //              buf.append( "Version :" ).append( BuildNumber.ENGINE_INFO ).append( CR );
130    //
131    //              Throwable th = thIn ;
132    //              while( th != null ) {
133    //                      trace = getStackData( trace,th );
134    //                      if( th instanceof HybsSystemException ) {
135    //                              buf.append( th.getMessage() );
136    //                      }
137    //                      else {
138    //                              String msg = th.getMessage();
139    //                              if( msg != null && buf.indexOf( msg ) < 0 ) {
140    //                                      buf.append( msg );
141    //                              }
142    //                      }
143    //                      buf.append( CR );
144    //                      th = th.getCause();
145    //              }
146    //
147    //              buf.append( trace.toString() );
148    //              return buf.toString();
149    //      }
150    
151            /**
152             * "org.opengion." を含ã‚?StackTraceElement のメãƒ?‚»ージæ–?­—å?を返しますã?
153             *
154             * @og.rev 4.0.0.0 (2005/01/31) 新規追åŠ?
155             *
156             * @param  buf StringBuilder 以前ã?エラーメãƒ?‚»ージ
157             * @param  th  Throwable スタãƒ?‚¯トレースを取りå?すThrowableオブジェクãƒ?
158             *
159             * @return  "org.opengion." を含ã‚?StackTraceElement のメãƒ?‚»ージ
160             */
161    //      private static StringBuilder getStackData( final StringBuilder buf,final Throwable th ) {
162    //              if( th != null ) {
163    //                      int cnt = 0;
164    //                      StackTraceElement[] trace = th.getStackTrace();
165    //                      for( int i=0; i<trace.length; i++ ) {
166    //                              String msg = trace[i].toString();
167    //                              if( buf.indexOf( msg ) < 0 ) {
168    //                                      if( msg != null && msg.indexOf( "org.opengion." ) >= 0 ) {
169    //                                              buf.append( "\tat " ).append( msg ).append( CR );
170    //                                      }
171    //                                      else if( cnt++ < 5 ) {
172    //                                              buf.append( "\tat " ).append( msg ).append( CR );
173    //                                      }
174    //                                      else if( cnt++ == 5 ) {
175    //                                              buf.append( "\t   ......" ).append( CR );
176    //                                      }
177    //                              }
178    //                      }
179    //                      buf.append( "\t   ... more ..." ).append( CR );
180    //              }
181    //              return buf;
182    //      }
183    }