File: eaf_n_cst_loggingservice_base.sru
Size: 25441
Date: Tue, 22 Jan 2008 23:39:23 +0100
$PBExportHeader$eaf_n_cst_loggingservice_base.sru
forward
global type eaf_n_cst_loggingservice_base from nonvisualobject
end type
end forward

global type eaf_n_cst_loggingservice_base from nonvisualobject
end type
global eaf_n_cst_loggingservice_base eaf_n_cst_loggingservice_base

type variables
Protected:
Powerobject                   ipo_requestor
string                        is_requestorname_plusdot
string                        is_componentname
string                        is_objectname

boolean                    ib_trace = false
boolean                    ib_debug = false
boolean                    ib_detailed = false
boolean                    ib_warning = true
boolean                    ib_usedatabaselogging = false
boolean                    ib_isinservercontext

n_cst_constants            inv_constants

String is_service = "EAFLog"

end variables

forward prototypes
public function long setrequestor (powerobject apo_requestor)
public function long propagatesettings (ref n_cst_baseservice anv_target)
public function integer setdebug (boolean ab_value)
public function integer settrace (boolean ab_value)
public function integer setdetailed (boolean ab_value)
public function integer setwarning (boolean ab_value)
public function boolean getdebug ()
public function boolean gettrace ()
public function boolean getwarning ()
public function boolean getdetailed ()
public function boolean getusedatabaselogging ()
public subroutine log (string as_methodname, string as_messagetype, string as_messagetext)
public subroutine warninglog (string as_methodname, string as_messagetype, string as_messagetext)
public subroutine debuglog (string as_methodname, string as_messagetype, string as_messagetext)
public subroutine detailedlog (string as_methodname, string as_messagetype, string as_messagetext)
public function long propagatesettings (ref n_cst_xmlparser anv_target)
public function long adderror (string as_methodname, string as_text, ref n_cst_messageservice anv_messaging)
public subroutine warninglog (string as_methodname, string as_messagetext)
public subroutine tracelog (string as_methodname, string as_messagetext)
public function integer setusedatabaselogging (boolean ab_value)
public function long populatesettings ()
end prototypes

public function long setrequestor (powerobject apo_requestor);////////////////////////////////////////////////////////////////
// Description:
//    An optional method.
//    Sets the object which requested this service
// Revisions
//    1.0   - Initial version
// Arguments:  
//    apo_requestor - The object which requested this service
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setRequestor "

// Validate arguments
If isNull(apo_requestor) Or Not isValid(apo_requestor) Then
   Return -1
End If

// Store the requestor reference
ipo_requestor = apo_requestor

is_objectname = ipo_requestor.className()

Return 1

end function

public function long propagatesettings (ref n_cst_baseservice anv_target);////////////////////////////////////////////////////////////////
// Description:
//    Propagate component log settings to service classes
// Note.
//    
// Revisions
//    3.0   - Initial version
// Arguments:
//    None
// Returns: 
//     1 - Success 
//    -1 - Failure 
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "propagateSettings(REF n_cst_baseservice anv_target) "

//Propagate Trace setting
if ib_trace then
   anv_target.setTrace( true )
end if

//Propagate Debug Setting
if ib_debug then
   anv_target.setDebug( true )
end if

//Propagate Warning setting
if ib_warning then
   anv_target.setWarning( true )
end if

//Propagate Detailed Debugging
if ib_detailed then
   anv_target.setDetailed( true )
end if

//Propagate Database Logging
if ib_usedatabaselogging then
   anv_target.setUseDatabaseLogging( true )
end if

//Propagate settings to dependent objects
return anv_target.propagateLogSettings()

end function

public function integer setdebug (boolean ab_value);////////////////////////////////////////////////////////////////
// Description:
//    Sets the debug variable
//    Required for the LogPropagation interface
//    
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_error - The actual error messsage
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setDebug( boolean value ) "

ib_debug = ab_value

Return 1

end function

public function integer settrace (boolean ab_value);////////////////////////////////////////////////////////////////
// Description:
//    Sets the trace variable
//    Required for the LogPropagation interface
//    
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_error - The actual error messsage
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setTrace( boolean value ) "

ib_trace = ab_value

Return 1

end function

public function integer setdetailed (boolean ab_value);////////////////////////////////////////////////////////////////
// Description:
//    Sets the detailed debugging variable
//    Required for the LogPropagation interface
//    
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_error - The actual error messsage
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setDetailed( boolean value ) "

ib_detailed = ab_value


Return 1

end function

public function integer setwarning (boolean ab_value);////////////////////////////////////////////////////////////////
// Description:
//    Sets the warning variable
//    Required for the LogPropagation interface
//    
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_error - The actual error messsage
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setWarning( boolean value ) "

ib_warning = ab_value

Return 1

end function

public function boolean getdebug ();////////////////////////////////////////////////////////////////
// Description:
//    Return the current debug setting
//    
// Revisions
//    3.0   - Initial version
// Arguments:  
//    None
// Returns:
//     boolean    ib_debug
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getDebug() "

Return ib_debug


end function

public function boolean gettrace ();////////////////////////////////////////////////////////////////
// Description:
//    Return the current trace setting
//    
// Revisions
//    3.0   - Initial version
// Arguments:  
//    None
// Returns:
//     boolean    ib_trace
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getTrace() "

Return ib_trace

end function

public function boolean getwarning ();////////////////////////////////////////////////////////////////
// Description:
//    Return the current warning setting
//    
// Revisions
//    3.0   - Initial version
// Arguments:  
//    None
// Returns:
//     boolean    ib_warning
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getWarning() "

Return ib_warning

end function

public function boolean getdetailed ();////////////////////////////////////////////////////////////////
// Description:
//    Return the current detailed setting
//    
// Revisions
//    3.0   - Initial version
// Arguments:  
//    None
// Returns:
//     boolean    ib_detailed
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getDetailed() "

Return ib_detailed

end function

public function boolean getusedatabaselogging ();////////////////////////////////////////////////////////////////
// Description:
//    Return the current usedatabaselogging setting
//    
// Revisions
//    3.0   - Initial version
// Arguments:  
//    None
// Returns:
//     boolean    ib_usedatabaselogging
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getUseDatabaseLogging() "

Return ib_usedatabaselogging

end function

public subroutine log (string as_methodname, string as_messagetype, string as_messagetext);////////////////////////////////////////////////////////////////
// Description:
//    Build message to be added to the client log file
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_methodname  -  The method where the error happened
//    as_messagetype -  Message type from constants object
//    as_messagetext -  Text of the message
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "log( String as_methodName, String as_messageType, String as_messageText ) "

string                  ls_padding = "                      "
string                  ls_message
long                    ll_filenum

ls_message = "Component: " + is_componentname + inv_constants.CRLF
ls_message += ls_padding + "Object: " + is_objectname + inv_constants.CRLF
ls_message += ls_padding + "Method: " + as_methodname + inv_constants.CRLF
ls_message += ls_padding + "Message Type: " + as_messagetype + inv_constants.CRLF
ls_message += ls_padding + "Message: " + as_messagetext + inv_constants.CRLF

// Write to log file
ll_filenum = FileOpen(is_service + ".txt", LineMode!, Write!, LockWrite!, Append!)
FileWriteEx(ll_filenum, String(Today()) + " " + String(Now()) + "~t" + ls_message)
FileClose(ll_FileNum)

end subroutine

public subroutine warninglog (string as_methodname, string as_messagetype, string as_messagetext);////////////////////////////////////////////////////////////////
// Description:
//    Warning logging
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_methodname  -  The method where the error happened
//    as_messagetype -  Message type from constants object
//    as_messagetext -  Text of the message
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "warningLog( String as_methodName, String as_messageType, String as_messageText ) "

if ib_warning then
   log( as_methodname, as_messagetype, as_messagetext )
end if

end subroutine

public subroutine debuglog (string as_methodname, string as_messagetype, string as_messagetext);////////////////////////////////////////////////////////////////
// Description:
//    Debug logging
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_methodname  -  The method where the error happened
//    as_messagetype -  Message type from constants object
//    as_messagetext -  Text of the message
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "debugLog( String as_methodName, String as_messageType, String as_messageText ) "

if ib_debug then
   log( as_methodname, as_messagetype, as_messagetext )
end if

end subroutine

public subroutine detailedlog (string as_methodname, string as_messagetype, string as_messagetext);////////////////////////////////////////////////////////////////
// Description:
//    Detailed debug logging
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_methodname  -  The method where the error happened
//    as_messagetype -  Message type from constants object
//    as_messagetext -  Text of the message
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "detailedLog( String as_methodName, String as_messageType, String as_messageText ) "

if ib_detailed then
   log( as_methodname, as_messagetype, as_messagetext )
end if

end subroutine

public function long propagatesettings (ref n_cst_xmlparser anv_target);////////////////////////////////////////////////////////////////
// Description:
//    Propagate component log settings to service classes
// Note.
//    
// Revisions
//    3.0   - Initial version
// Arguments:
//    None
// Returns: 
//     1 - Success 
//    -1 - Failure 
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "propagateSettings(REF n_cst_baseservice anv_target) "

//Propagate Trace setting
if ib_trace then
   anv_target.setTrace( true )
end if

//Propagate Debug Setting
if ib_debug then
   anv_target.setDebug( true )
end if

//Propagate Warning setting
if ib_warning then
   anv_target.setWarning( true )
end if

//Propagate Detailed Debugging
if ib_detailed then
   anv_target.setDetailed( true )
end if

//Propagate Database Logging
if ib_usedatabaselogging then
   anv_target.setUseDatabaseLogging( true )
end if

//Propagate settings to dependent objects
return anv_target.propagateLogSettings()

end function

public function long adderror (string as_methodname, string as_text, ref n_cst_messageservice anv_messaging);////////////////////////////////////////////////////////////////
// Description:
//    Appends an error to the log and to the MessageService passed by reference
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_methodname  -  Name of the method where error occured
//    as_text        -  Text of the Error
//    anv_messaging  -  Reference object for MessageService
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////// Copyright © 2000 - 200703 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "addError ( string, string, REF n_cst_messageservice ) "

//Write the Error to the Log
log( as_methodname, inv_constants.MESSAGE_TYPE_EAF_ERROR, as_text )

//Append the Error to the MessageService
anv_messaging.add( inv_constants.MESSAGE_TYPE_EAF_ERROR, inv_constants.MESSAGE_TYPE_EAF_ERROR, as_text)

Return 1

end function

public subroutine warninglog (string as_methodname, string as_messagetext);////////////////////////////////////////////////////////////////
// Description:
//    Warning logging
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_methodname  -  The method where the error happened
//    as_messagetype -  Message type from constants object
//    as_messagetext -  Text of the message
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "warningLog( String as_methodName, String as_messageType, String as_messageText ) "

if ib_warning then
   log( as_methodname, inv_constants.MESSAGE_TYPE_EAF_WARNING, as_messagetext )
end if

end subroutine

public subroutine tracelog (string as_methodname, string as_messagetext);////////////////////////////////////////////////////////////////
// Description:
//    Trace logging
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_methodname  -  The method where the error happened
//    as_messagetype -  Message type from constants object
//    as_messagetext -  Text of the message
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "traceLog( String as_methodName, String as_messageType, String as_messageText ) "

if ib_trace then
   log( as_methodname, inv_constants.MESSAGE_TYPE_EAF_TRACE, as_messagetext )
end if

end subroutine

public function integer setusedatabaselogging (boolean ab_value);////////////////////////////////////////////////////////////////
// Description:
//    Sets the debug variable
//    Required for the LogPropagation interface
//    
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_error - The actual error messsage
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setUseDatabaseLogging( boolean value ) "

ib_usedatabaselogging = ab_value

Return 1

end function

public function long populatesettings ();////////////////////////////////////////////////////////////////
// Description:
//    Invoked when the object is created at the base level of the component
//    Queries component properties and the variable manager for values
// Revisions
//    3.0   - Initial Version
// Arguments:  
//    None
// Returns: 
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "populateSettings "

// Declare local variables
long                       ll_rc
string                        ls_value
boolean                    lb_value
n_cst_variablemanager      lnv_variablemanager

lnv_variablemanager = create n_cst_variablemanager

// Check Component Properties for Debug
lnv_variablemanager.GetValue( inv_constants.DEBUG_PROPERTY_NAME, ls_value)
ls_value = upper(trim(ls_value))
setDebug( (ls_value = "YES" or ls_value = "TRUE") )

// Check Component Properties for Trace
lnv_variablemanager.GetValue( inv_constants.TRACE_PROPERTY_NAME, ls_value)
ls_value = upper(trim(ls_value))
setTrace( (ls_value = "YES" or ls_value = "TRUE") )

// Check Component Properties for Detailed Debugging
lnv_variablemanager.GetValue( inv_constants.DEBUG_DETAILED_PROPERTY_NAME, ls_value)
ls_value = upper(trim(ls_value))
setDetailed( (ls_value = "YES" or ls_value = "TRUE") )

// Check Component Properties for Warning
//Warning is on by default unless specifically disabled
lnv_variablemanager.GetValue( inv_constants.WARNING_PROPERTY_NAME, ls_value)
ls_value = upper(trim(ls_value))
lb_value = (ls_value = "NO" or ls_value = "FALSE")
if lb_value then
   setWarning( false )
end if

// Check Component Properties for Use Database Logging
lnv_variablemanager.GetValue( inv_constants.USE_DATABASE_LOGGING_PROPERTY_NAME, ls_value)
ls_value = upper(trim(ls_value))
setUseDatabaseLogging( (ls_value = "YES" or ls_value = "TRUE") )

debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Debug Setting:" + string( ib_debug ) )
debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Trace Setting:" + string( ib_trace ) )
debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Detailed Setting:" + string( ib_detailed ) )
debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "UseDatabaseLogging Setting:" + string( ib_usedatabaselogging ) )

destroy lnv_variablemanager

return 1

end function

on eaf_n_cst_loggingservice_base.create
call super::create
TriggerEvent( this, "constructor" )
end on

on eaf_n_cst_loggingservice_base.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

event destructor;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when the object is destroyed
// Revisions
//    3.0   - Initial version
// Arguments:  
//    None
// Returns: 
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "destructor "

if isValid( inv_constants ) then
   destroy inv_constants
end if


end event

event constructor;//create the constants class
inv_constants = create n_cst_constants

end event