[r5]: / Tags / The -Abstract Factory- Pattern / Abstract Factory2.project  Maximize  Restore  History

Download this file

217 lines (154 with data), 146.2 kB

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR

-------------------------------------------------------------------------------
FB_FileLoggerFactory
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_FileLoggerFactory EXTENDS FB_AbstractLoggerFactory

VAR
    pTxtLogger: pointer;
    pCsvLogger: pointer;
    pXmlLogger: pointer;
    ipLogger: ILogger;
END_VAR

-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    sFilename: string;
END_VAR

VAR
    sFilenameExtension: string;
END_VAR
sFilenameExtension := RIGHT(sFilename, 3);
IF (sFilenameExtension = 'txt' OR sFilenameExtension = 'TXT') THEN
    pTxtLogger := __NEW(FB_TxtLogger);
    ipLogger := pTxtLogger^;
ELSIF (sFilenameExtension = 'csv' OR sFilenameExtension = 'CSV') THEN
    pCsvLogger := __NEW(FB_CsvLogger);
    ipLogger := pCsvLogger^;
ELSIF (sFilenameExtension = 'xml' OR sFilenameExtension = 'XML') THEN
    pXmlLogger := __NEW(FB_XmlLogger);
    ipLogger := pXmlLogger^;
ELSE
    ipLogger := 0;
END_IF

-------------------------------------------------------------------------------
GetLogger
-------------------------------------------------------------------------------


METHOD GetLogger: ILogger
GetLogger := ipLogger;

-------------------------------------------------------------------------------
FB_exit
-------------------------------------------------------------------------------


METHOD FB_exit: BOOL

VAR_INPUT
    bInCopyCode: BOOL;
END_VAR
IF (pTxtLogger <> 0) THEN
	__DELETE(pTxtLogger);
	pTxtLogger := 0;
END_IF

IF (pCsvLogger <> 0) THEN
	__DELETE(pCsvLogger);
	pCsvLogger := 0;
END_IF

IF (pXmlLogger <> 0) THEN
	__DELETE(pXmlLogger);
	pXmlLogger := 0;
END_IF

-------------------------------------------------------------------------------
FB_Logger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_Logger

VAR
    ipLogger: ILogger;
END_VAR

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
Write := 'Error';
IF (ipLogger <> 0) THEN
	Write := ipLogger.Write(sMsg);
END_IF	

-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    refLoggerFactory: REFERENCE TO FB_AbstractLoggerFactory;
END_VAR
IF (__ISVALIDREF(refLoggerFactory)) THEN
	ipLogger := refLoggerFactory.GetLogger();
ELSE
	ipLogger := 0;
END_IF

-------------------------------------------------------------------------------
FB_TxtLogger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_TxtLogger

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
Write := CONCAT('TxtLogger: ', sMsg);

-------------------------------------------------------------------------------
FB_CsvLogger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_CsvLogger

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
Write := CONCAT('CsvLogger: ', sMsg);
-------------------------------------------------------------------------------
FB_XmlLogger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_XmlLogger

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
Write := CONCAT('XmlLogger: ', sMsg);
-------------------------------------------------------------------------------
FB_AbstractLoggerFactory
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_AbstractLoggerFactory

-------------------------------------------------------------------------------
GetLogger
-------------------------------------------------------------------------------


METHOD GetLogger: ILogger
;
-------------------------------------------------------------------------------
MAIN
-------------------------------------------------------------------------------


PROGRAM MAIN

VAR
    fbFileLoggerFactory: FB_FileLoggerFactory;
    refFileLoggerFactory: REFERENCE TO FB_FileLoggerFactory;
    fbLogger: FB_Logger;
    sRetMsg: string;
END_VAR
sRetMsg := fbLogger.Write('Hello');