KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > susebox > java > lang > DefaultEnvironment


1 /*
2  * DefaultEnvironment.java: Environment implementation based on the Java System class.
3  *
4  * Copyright (C) 2002 Heiko Blau
5  *
6  * This file belongs to the Susebox Java Core Library (Susebox JCL).
7  * The Susebox JCL is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or (at your
10  * option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License along
18  * with the Susebox JCL. If not, write to the
19  *
20  * Free Software Foundation, Inc.
21  * 59 Temple Place, Suite 330,
22  * Boston, MA 02111-1307
23  * USA
24  *
25  * or check the Internet: http://www.fsf.org
26  *
27  * Contact:
28  * email: heiko@susebox.de
29  */

30
31 package de.susebox.java.lang;
32
33 //-----------------------------------------------------------------------------
34
// Imports
35
//
36
import java.io.InputStream JavaDoc;
37 import java.io.PrintStream JavaDoc;
38
39
40 //-----------------------------------------------------------------------------
41
// Class DefaultEnvironment
42
//
43

44 /**<p>
45  * The <code>DefaultEnvironment</code> implements the {@link Environment} interface
46  * using the JDK class {@link java.lang.System}. Instances of this class are
47  * returned by the singleton {@link EnvironmentProvider} ({@link EnvironmentProvider#getEnvironment})
48  * if there is no other <code>Environment</code> available for the caller.
49  *</p>
50  *
51  * @see Environment
52  * @see EnvironmentProvider
53  * @author Heiko Blau
54  */

55 public class DefaultEnvironment implements Environment {
56   
57   //---------------------------------------------------------------------------
58
// methods of the Environment interface
59
//
60

61   /**
62    * This method returns {@link java.lang.System#in}, the standard input channel.
63    *
64    * @return the {@link java.io.InputStream} that serves as standard input
65    * @see java.lang.System#in
66    */

67   public InputStream JavaDoc in() {
68     return System.in;
69   }
70   
71   /**
72    * This method returns {@link java.lang.System#out}, the standard output channel.
73    *
74    * @return the {@link java.io.PrintStream} that serves as standard output
75    * @see java.lang.System#out
76    */

77   public PrintStream JavaDoc out() {
78     return System.out;
79   }
80   
81   /**
82    * This method returns {@link java.lang.System#err}, the standard error channel.
83    *
84    * @return the {@link java.io.PrintStream} that serves as standard error output
85    * @see java.lang.System#err
86    */

87   public PrintStream JavaDoc err() {
88     return System.err;
89   }
90
91   /**
92    * This method stores the exit code of an application. It can be called more
93    * than once.
94    *
95    * @param status the exit code of an application
96    * @see java.lang.System#exit
97    */

98   public void setExitStatus(int status) {
99     _exitStatus = status;
100   }
101
102   /**
103    * Retrieving the currently set exit code.
104    *
105    * @return the currently set exit code of an application
106    */

107   public int getExitStatus() {
108     return _exitStatus;
109   }
110
111   /**
112    * This method exits the instance of its <code>Environment</code> implementation.
113    * After calling <code>exit</code> the <code>Environment</code> instance is
114    * generally not any longer usable. In particular, an implementation can choose
115    * to call {@link java.lang.System#exit}.
116    *
117    * @see #setExitStatus
118    * @see java.lang.System#exit
119    */

120   public void exit() throws UnsupportedOperationException JavaDoc {
121     System.exit(getExitStatus());
122   }
123
124   
125   //---------------------------------------------------------------------------
126
// members
127
//
128
private int _exitStatus = 0;
129 }
130
Popular Tags