/*
 * blanco Framework
 * Copyright (C) 2004-2006 IGA Tosiki
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 */
package blanco.db.expander.query;

import java.util.List;

import blanco.cg.BlancoCgObjectFactory;
import blanco.cg.valueobject.BlancoCgClass;
import blanco.cg.valueobject.BlancoCgMethod;
import blanco.cg.valueobject.BlancoCgSourceFile;
import blanco.db.common.expander.BlancoDbAbstractMethod;
import blanco.db.common.valueobject.BlancoDbSetting;
import blanco.db.common.valueobject.BlancoDbSqlInfoStructure;

/**
 * 個別のメソッドを展開するためのクラス。
 */
public class FinalizeDotNet extends BlancoDbAbstractMethod {
    public FinalizeDotNet(final BlancoDbSetting argDbSetting,
            final BlancoDbSqlInfoStructure argSqlInfo,
            final BlancoCgObjectFactory argCgFactory,
            final BlancoCgSourceFile argCgSourceFile,
            final BlancoCgClass argCgClass) {
        super(argDbSetting, argSqlInfo, argCgFactory, argCgSourceFile,
                argCgClass);
    }

    public void expand() {
        final BlancoCgMethod cgMethod = fCgFactory.createMethod("Finalize",
                "Finalizeメソッド");
        fCgClass.getMethodList().add(cgMethod);

        cgMethod.setAccess("protected");

        cgMethod.getLangDoc().getDescriptionList().add(
                "クローズ忘れのバグを検知することを目的とします。");

        final List<String> listLine = cgMethod.getLineList();

        listLine.add("if (fStatement != null) {");
        listLine.add("const String message = \"" + fCgClass.getName()
                + " : Close()メソッドによるリソースの開放が行われていません。\";");
        listLine.add("System.Console.WriteLine(message);");

        if (fDbSetting.getLogging()) {
            listLine.add("");
            listLine.add("fLog.error(\"" + cgMethod.getName()
                    + ": \" + message);");
        }

        listLine.add("}");
    }
}