KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > util > env > EnvAccessException


1 /*
2  * Copyright 2004 Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.util.env ;
19
20 import java.io.IOException JavaDoc;
21
22 /**
23  * A simple wrapper exception around exceptions that could occur while accessing
24  * environment parameters.
25  *
26  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
27  * @version $Revision: 1.4 $
28  */

29 public class EnvAccessException extends IOException JavaDoc
30 {
31     /** the environment variable name if available */
32     public final String JavaDoc m_variable ;
33     /** root cause */
34     public final Throwable JavaDoc m_cause ;
35     
36     /**
37      * Creates an exception denoting a failure while attempting to access an
38      * environment variable within an operating system and shell specific
39      * environment that is caused by another exception.
40      *
41      * @param a_cause the underlying exception that caused the failure
42      */

43     EnvAccessException( final Throwable JavaDoc a_cause )
44     {
45         super() ;
46         
47         m_variable = null ;
48         m_cause = a_cause ;
49     }
50
51
52     /**
53      * Creates an exception denoting a failure while attempting to access an
54      * environment variable within an operating system and shell specific
55      * environment.
56      *
57      * @param a_message the reason for the access failure
58      */

59     EnvAccessException( final String JavaDoc a_message )
60     {
61         super( a_message ) ;
62         
63         m_variable = null ;
64         m_cause = null ;
65     }
66
67     
68     /**
69      * Creates an exception denoting a failure while attempting to access an
70      * environment variable within an operating system and shell specific
71      * environment that is caused by another exception.
72      *
73      * @param a_variable the variable whose value was to be accessed
74      * @param a_cause the underlying exception that caused the failure
75      */

76     EnvAccessException( final String JavaDoc a_variable, final Throwable JavaDoc a_cause )
77     {
78         super() ;
79         
80         m_variable = a_variable ;
81         m_cause = a_cause ;
82     }
83
84
85     /**
86      * Creates an exception denoting a failure while attempting to access an
87      * environment variable within an operating system and shell specific
88      * environment.
89      *
90      * @param a_variable the variable whose value was to be accessed
91      * @param a_message the reason for the access failure
92      */

93     EnvAccessException( final String JavaDoc a_variable, final String JavaDoc a_message )
94     {
95         super( a_message ) ;
96         
97         m_variable = a_variable ;
98         m_cause = null;
99     }
100
101
102     /**
103      * Gets the variable that was to be accessed.
104      *
105      * @return the value of the variable
106      */

107     public String JavaDoc getVariable()
108     {
109         return m_variable ;
110     }
111
112     
113     /**
114      * Return the causal exception.
115      *
116      * @return the exception that caused this exception (possibly null)
117      */

118     public Throwable JavaDoc getCause()
119     {
120         return m_cause ;
121     }
122
123     
124     /**
125      * Prepends variable name to the base message.
126      *
127      * @see java.lang.Throwable#getMessage()
128      */

129     public String JavaDoc getMessage()
130     {
131         String JavaDoc l_base = super.getMessage() ;
132         
133         if ( null == l_base )
134         {
135             return "Failed to access " + m_variable + " environment variable" ;
136         }
137         
138         return "Failed to access " + m_variable
139             + " environment variable - " + l_base ;
140     }
141 }
142
143
144
145
Popular Tags