001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2005 Klaus Bartz
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: package com.izforge.izpack.util.os;
023:
024: import com.coi.tools.os.win.NativeLibException;
025: import com.izforge.izpack.LocaleDatabase;
026:
027: /**
028: * This class allows it to define error messages for <code>NativeLibException</code> s in the
029: * IzPack locale files. The getMessage methode searches in the current langpack for entries which
030: * are corresponding to that one which are received from native part. If the langpack do not contain
031: * the entry, the resource boundle is used.
032: *
033: * @author Klaus Bartz
034: *
035: */
036: public class WrappedNativeLibException extends Exception {
037:
038: private static final long serialVersionUID = 3257562893309720112L;
039:
040: /** The packs locale database. */
041: protected static LocaleDatabase langpack = null;
042:
043: /**
044: * Default constructor.
045: */
046: public WrappedNativeLibException() {
047: super ();
048: }
049:
050: /**
051: * @param message
052: */
053: public WrappedNativeLibException(String message) {
054: super (message);
055: }
056:
057: /**
058: * @param cause
059: */
060: public WrappedNativeLibException(Throwable cause) {
061: super (cause);
062: }
063:
064: /**
065: * @param message
066: * @param cause
067: */
068: public WrappedNativeLibException(String message, Throwable cause) {
069: super (message, cause);
070: }
071:
072: /*
073: * (non-Javadoc)
074: *
075: * @see java.lang.Throwable#getMessage()
076: */
077: public String getMessage() {
078: StringBuffer retval = new StringBuffer();
079: boolean next = false;
080: boolean ok = false;
081: if (getCause() instanceof NativeLibException) {
082: NativeLibException nle = (NativeLibException) getCause();
083: if (langpack != null) {
084: while (true) {
085: if (nle.getLibMessage() != null) {
086: String val = (String) langpack
087: .get("NativeLibException."
088: + nle.getLibMessage());
089: if (val == null)
090: break;
091: retval.append(val);
092: next = true;
093: } else if (nle.getLibErr() != 0) {
094: String val = (String) langpack
095: .get("NativeLibException.libErrNumber."
096: + Integer.toString(nle
097: .getLibErr()));
098: if (val == null)
099: break;
100: if (next)
101: retval.append("\n");
102: next = true;
103: retval.append(val);
104: }
105: if (nle.getOsErr() != 0) {
106: String val = langpack
107: .get("NativeLibException.libInternal.OsErrNumPraefix")
108: + Integer.toString(nle.getOsErr());
109: if (val == null)
110: break;
111: if (next)
112: retval.append("\n");
113: next = true;
114: retval.append(val);
115: }
116: if (nle.getOsMessage() != null) {
117: String val = langpack
118: .get("NativeLibException.libInternal.OsErrStringPraefix")
119: + nle.getOsMessage();
120: if (val == null)
121: break;
122: if (next)
123: retval.append("\n");
124: next = true;
125: retval.append(val);
126: }
127: ok = true;
128: break;
129: }
130: }
131: if (ok && retval.length() > 0)
132: return (nle.reviseMsgWithArgs(retval.toString()));
133: else
134: return (nle.getMessage());
135:
136: } else
137: return (super .getMessage());
138: }
139:
140: /**
141: * Returns the langpack.
142: *
143: * @return Returns the langpack.
144: */
145: public static LocaleDatabase getLangpack() {
146: return langpack;
147: }
148:
149: /**
150: * Sets the langpack to the given locale database.
151: *
152: * @param langpack the langpack to set.
153: */
154: public static void setLangpack(LocaleDatabase langpack) {
155: WrappedNativeLibException.langpack = langpack;
156: }
157: }
|