KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > util > os > WrappedNativeLibException


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2005 Klaus Bartz
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.util.os;
23
24 import com.coi.tools.os.win.NativeLibException;
25 import com.izforge.izpack.LocaleDatabase;
26
27 /**
28  * This class allows it to define error messages for <code>NativeLibException</code> s in the
29  * IzPack locale files. The getMessage methode searches in the current langpack for entries which
30  * are corresponding to that one which are received from native part. If the langpack do not contain
31  * the entry, the resource boundle is used.
32  *
33  * @author Klaus Bartz
34  *
35  */

36 public class WrappedNativeLibException extends Exception JavaDoc
37 {
38
39     private static final long serialVersionUID = 3257562893309720112L;
40
41     /** The packs locale database. */
42     protected static LocaleDatabase langpack = null;
43
44     /**
45      * Default constructor.
46      */

47     public WrappedNativeLibException()
48     {
49         super();
50     }
51
52     /**
53      * @param message
54      */

55     public WrappedNativeLibException(String JavaDoc message)
56     {
57         super(message);
58     }
59
60     /**
61      * @param cause
62      */

63     public WrappedNativeLibException(Throwable JavaDoc cause)
64     {
65         super(cause);
66     }
67
68     /**
69      * @param message
70      * @param cause
71      */

72     public WrappedNativeLibException(String JavaDoc message, Throwable JavaDoc cause)
73     {
74         super(message, cause);
75     }
76
77     /*
78      * (non-Javadoc)
79      *
80      * @see java.lang.Throwable#getMessage()
81      */

82     public String JavaDoc getMessage()
83     {
84         StringBuffer JavaDoc retval = new StringBuffer JavaDoc();
85         boolean next = false;
86         boolean ok = false;
87         if (getCause() instanceof NativeLibException)
88         {
89             NativeLibException nle = (NativeLibException) getCause();
90             if (langpack != null)
91             {
92                 while (true)
93                 {
94                     if (nle.getLibMessage() != null)
95                     {
96                         String JavaDoc val = (String JavaDoc) langpack.get("NativeLibException."
97                                 + nle.getLibMessage());
98                         if (val == null) break;
99                         retval.append(val);
100                         next = true;
101                     }
102                     else if (nle.getLibErr() != 0)
103                     {
104                         String JavaDoc val = (String JavaDoc) langpack.get("NativeLibException.libErrNumber."
105                                 + Integer.toString(nle.getLibErr()));
106                         if (val == null) break;
107                         if (next) retval.append("\n");
108                         next = true;
109                         retval.append(val);
110                     }
111                     if (nle.getOsErr() != 0)
112                     {
113                         String JavaDoc val = (String JavaDoc) langpack
114                                 .get("NativeLibException.libInternal.OsErrNumPraefix")
115                                 + Integer.toString(nle.getOsErr());
116                         if (val == null) break;
117                         if (next) retval.append("\n");
118                         next = true;
119                         retval.append(val);
120                     }
121                     if (nle.getOsMessage() != null)
122                     {
123                         String JavaDoc val = (String JavaDoc) langpack
124                                 .get("NativeLibException.libInternal.OsErrStringPraefix")
125                                 + nle.getOsMessage();
126                         if (val == null) break;
127                         if (next) retval.append("\n");
128                         next = true;
129                         retval.append(val);
130                     }
131                     ok = true;
132                     break;
133                 }
134             }
135             if (ok && retval.length() > 0)
136                 return (nle.reviseMsgWithArgs(retval.toString()));
137             else
138                 return (nle.getMessage());
139
140         }
141         else
142             return (super.getMessage());
143     }
144
145     /**
146      * Returns the langpack.
147      *
148      * @return Returns the langpack.
149      */

150     public static LocaleDatabase getLangpack()
151     {
152         return langpack;
153     }
154
155     /**
156      * Sets the langpack to the given locale database.
157      *
158      * @param langpack the langpack to set.
159      */

160     public static void setLangpack(LocaleDatabase langpack)
161     {
162         WrappedNativeLibException.langpack = langpack;
163     }
164 }
165
Popular Tags