001: /*
002: * DefaultEnvironment.java: Environment implementation based on the Java System class.
003: *
004: * Copyright (C) 2002 Heiko Blau
005: *
006: * This file belongs to the Susebox Java Core Library (Susebox JCL).
007: * The Susebox JCL is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as published by the
009: * Free Software Foundation; either version 2.1 of the License, or (at your
010: * option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE.
015: * See the GNU Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License along
018: * with the Susebox JCL. If not, write to the
019: *
020: * Free Software Foundation, Inc.
021: * 59 Temple Place, Suite 330,
022: * Boston, MA 02111-1307
023: * USA
024: *
025: * or check the Internet: http://www.fsf.org
026: *
027: * Contact:
028: * email: heiko@susebox.de
029: */
030:
031: package de.susebox.java.lang;
032:
033: //-----------------------------------------------------------------------------
034: // Imports
035: //
036: import java.io.InputStream;
037: import java.io.PrintStream;
038:
039: //-----------------------------------------------------------------------------
040: // Class DefaultEnvironment
041: //
042:
043: /**<p>
044: * The <code>DefaultEnvironment</code> implements the {@link Environment} interface
045: * using the JDK class {@link java.lang.System}. Instances of this class are
046: * returned by the singleton {@link EnvironmentProvider} ({@link EnvironmentProvider#getEnvironment})
047: * if there is no other <code>Environment</code> available for the caller.
048: *</p>
049: *
050: * @see Environment
051: * @see EnvironmentProvider
052: * @author Heiko Blau
053: */
054: public class DefaultEnvironment implements Environment {
055:
056: //---------------------------------------------------------------------------
057: // methods of the Environment interface
058: //
059:
060: /**
061: * This method returns {@link java.lang.System#in}, the standard input channel.
062: *
063: * @return the {@link java.io.InputStream} that serves as standard input
064: * @see java.lang.System#in
065: */
066: public InputStream in() {
067: return System.in;
068: }
069:
070: /**
071: * This method returns {@link java.lang.System#out}, the standard output channel.
072: *
073: * @return the {@link java.io.PrintStream} that serves as standard output
074: * @see java.lang.System#out
075: */
076: public PrintStream out() {
077: return System.out;
078: }
079:
080: /**
081: * This method returns {@link java.lang.System#err}, the standard error channel.
082: *
083: * @return the {@link java.io.PrintStream} that serves as standard error output
084: * @see java.lang.System#err
085: */
086: public PrintStream err() {
087: return System.err;
088: }
089:
090: /**
091: * This method stores the exit code of an application. It can be called more
092: * than once.
093: *
094: * @param status the exit code of an application
095: * @see java.lang.System#exit
096: */
097: public void setExitStatus(int status) {
098: _exitStatus = status;
099: }
100:
101: /**
102: * Retrieving the currently set exit code.
103: *
104: * @return the currently set exit code of an application
105: */
106: public int getExitStatus() {
107: return _exitStatus;
108: }
109:
110: /**
111: * This method exits the instance of its <code>Environment</code> implementation.
112: * After calling <code>exit</code> the <code>Environment</code> instance is
113: * generally not any longer usable. In particular, an implementation can choose
114: * to call {@link java.lang.System#exit}.
115: *
116: * @see #setExitStatus
117: * @see java.lang.System#exit
118: */
119: public void exit() throws UnsupportedOperationException {
120: System.exit(getExitStatus());
121: }
122:
123: //---------------------------------------------------------------------------
124: // members
125: //
126: private int _exitStatus = 0;
127: }
|