corbamnqreqlogger.java

来自「UCS (Ultra Corba Simulator) is one more 」· Java 代码 · 共 61 行

JAVA
61
字号
package com.corba.mnq.ui;

import com.corba.mnq.main.MNQmainFrame;

import java.io.FileWriter;
import java.io.IOException;

public class CorbaMNQReqLogger {

    private MNQmainFrame client;

    /**
     * Constructor of CorbaMNQReqLogger
     * 
     * @param client
     *            reference to the initiator MNQmainFrame
     */
    public CorbaMNQReqLogger(MNQmainFrame client) {
        this.client = client;
    }

    /**
     * Writes the provided String (loggable) to the provided logFile
     * 
     * @param loggable
     *            the String to write to logfile
     * @throws OperationCannotBeLoggedException
     *             in case the logFile cannot be accessed
     */
    protected void writeToLogFile(String loggable) throws OperationCannotBeLoggedException {
        if (client == null) { throw new OperationCannotBeLoggedException(
                "The client reference is null!"); }
        String logFile = client.getOperationLogFileName();
        if (logFile == null || logFile.equals("")) { throw new OperationCannotBeLoggedException(
                "The operation log filename is null or empty!"); }
        try {
            FileWriter fileWriter = new FileWriter(logFile, true);
            if (fileWriter != null) {
                fileWriter.write(loggable);
                fileWriter.close();
            } else {
                throw new OperationCannotBeLoggedException("The provided file cannot be accessed!");
            }
        } catch (IOException e) {
            throw new OperationCannotBeLoggedException("The provided file cannot be accessed!");
        }
    }

    /**
     * name: "OperationCannotBeLoggedException"
     * 
     * @author ucs_2008
     */
    static class OperationCannotBeLoggedException extends Exception {

        public OperationCannotBeLoggedException(String message) {
            super(message);
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?