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

global type eaf_n_cst_messageservice from nonvisualobject
end type
global eaf_n_cst_messageservice eaf_n_cst_messageservice

type variables
protected:

//Element Names
string                        EAF_MESSAGES      =  "EAFMessages"
string                        EAF_MESSAGE       =  "EAFMessage"
string                        EAF_MESSAGE_NAME  =  "EAFMessageName"
string                        EAF_MESSAGE_TYPE  =  "EAFMessageType"
string                        EAF_MESSAGE_TEXT  =  "EAFMessageText"


//Messages                    
n_cst_messageattrib           inv_messages[]
end variables

forward prototypes
public function long add (string as_name, string as_type, string as_text)
public function long add (ref n_cst_messageattrib anv_message)
public function long getmessage (string as_name, ref n_cst_messageattrib anv_message)
public function long getmessages (ref n_cst_messageattrib anv_messages[])
public function long append (ref n_cst_messageservice anv_messageservice)
public function long reset ()
public function long getmessagecount ()
public function long getmessagecount (string as_messagetype)
public function long getmessages (string as_messagetype, ref n_cst_messageattrib anv_messages[])
public function long getmessage (string as_name, string as_type, ref n_cst_messageattrib anv_message)
public function long getmessagetext (string as_name, ref string as_text)
public function long getmessagetext (string as_name, string as_type, ref string as_text)
public function long add (string as_name, string as_text)
public function long add (string as_name, blob ab_data)
public function long getmessagetext (string as_name, ref blob ab_data)
public function long toxml (string as_character, ref string as_document)
public function long toxml (string as_characterset, ref string as_document, ref blob ab_data)
public function long append (string as_messages, blob ab_data)
public function long append (string as_messages)
public function long parse (string as_messages, blob ab_data)
public function long parse (string as_messages)
end prototypes

public function long add (string as_name, string as_type, string as_text);////////////////////////////////////////////////////////////////
// Description:
//    Adds a message to the arrray using string values for name, type, and text
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_name - name
//    as_type - type
//    as_text  - text
// 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 = "add( String, String, String ) "

n_cst_messageattrib           lnv_message

lnv_message = create n_cst_messageattrib
lnv_message.is_name = as_name
lnv_message.is_type = as_type
lnv_message.is_text = as_text


return add( lnv_message )


end function

public function long add (ref n_cst_messageattrib anv_message);////////////////////////////////////////////////////////////////
// Description:
//    Adds a message to the arrray using a message attribute object
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv__message - REF - message to be added
// 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 = "add( REF n_cst_messageattrib ) "

boolean              lb_exists

long                 ll_messagecount
long                 ll_messageindex

ll_messagecount = upperBound( inv_messages )

//Check to see if message exists by name and type
//If it does, replace that message with the message object passed in
//Only check for messages with specified names
if len(trim(anv_message.is_name)) >0 and not isNull( anv_message.is_name ) then
   for ll_messageindex = 1 to ll_messagecount
      if lower( anv_message.is_name ) = lower( inv_messages[ll_messageindex].is_name ) and lower( anv_message.is_type ) = lower( inv_messages[ll_messageindex].is_type ) then
         inv_messages[ll_messageindex].is_text = anv_message.is_text
         lb_exists = true
      end if
   next
end if

//message did not exist previously - add new message to the list
if not lb_exists then
   inv_messages[ll_messagecount+1] = anv_message
end if

return 1

end function

public function long getmessage (string as_name, ref n_cst_messageattrib anv_message);////////////////////////////////////////////////////////////////
// Description:
//    Locates the message attrib object given the message name
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_name - message name
//    anv_message - Message attrib object to hold the message data
// 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 = "getMessage( String, REF n_cst_messageattrib ) "

boolean              lb_exists

long                 ll_messagecount
long                 ll_messageindex

ll_messagecount = upperBound( inv_messages )

if not isValid( anv_message ) then
   anv_message = create n_cst_messageattrib
else
   anv_message.is_name = ""
   anv_message.is_type = ""
   anv_message.is_text = ""
end if

for ll_messageindex = 1 to ll_messagecount
   if lower( as_name ) = lower( inv_messages[ll_messageindex].is_name ) then
      anv_message.is_name = inv_messages[ll_messageindex].is_name
      anv_message.is_type = inv_messages[ll_messageindex].is_type
      anv_message.is_text = inv_messages[ll_messageindex].is_text
      anv_message.ib_value = inv_messages[ll_messageindex].ib_value
      return 1
   end if
next


return -1

end function

public function long getmessages (ref n_cst_messageattrib anv_messages[]);////////////////////////////////////////////////////////////////
// Description:
//    Returns all messages in array of message attribute objects
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_messages - message attribute objects holding the message information
// 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 = "getMessages( REF n_cst_messageattrib[] ) "

long                 ll_messagecount
long                 ll_messageindex
long                 ll_newmessageindex

ll_messagecount = upperBound( inv_messages )

for ll_messageindex = 1 to ll_messagecount
   ll_newmessageindex = upperBound( anv_messages ) + 1
   anv_messages[ll_newmessageindex] = create n_cst_messageattrib
   anv_messages[ll_newmessageindex].is_name = inv_messages[ll_messageindex].is_name
   anv_messages[ll_newmessageindex].is_type = inv_messages[ll_messageindex].is_type
   anv_messages[ll_newmessageindex].is_text = inv_messages[ll_messageindex].is_text
   anv_messages[ll_newmessageindex].ib_value = inv_messages[ll_messageindex].ib_value
next

return 1


return 1

end function

public function long append (ref n_cst_messageservice anv_messageservice);////////////////////////////////////////////////////////////////
// Description:
//    Appends the contents of a message service to this message service array
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_messageservice   - Source message service
// 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 = "append( REF n_cst_messageservice ) "

long                 ll_messagecount
long                 ll_messageindex
long                 ll_newmessageindex

n_cst_messageattrib  lnv_messages[]

//get all messages from passed in MessageService
anv_messageservice.getMessages( lnv_messages )

ll_messagecount = upperBound( lnv_messages )

//Copy message content from messages from passed in MessageService
for ll_messageindex = 1 to ll_messagecount
   ll_newmessageindex = upperBound( inv_messages ) + 1
   inv_messages[ll_newmessageindex] = create n_cst_messageattrib
   inv_messages[ll_newmessageindex].is_name = lnv_messages[ll_messageindex].is_name
   inv_messages[ll_newmessageindex].is_type = lnv_messages[ll_messageindex].is_type
   inv_messages[ll_newmessageindex].is_text = lnv_messages[ll_messageindex].is_text
   inv_messages[ll_newmessageindex].ib_value = lnv_messages[ll_messageindex].ib_value
next

return 1

end function

public function long reset ();////////////////////////////////////////////////////////////////
// Description:
//    Resets the message array
//
// 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 = "reset()"

long                       ll_messagecount
long                       ll_messageindex

n_cst_messageattrib        lnv_messages[]

//Destroy the existing message objects
ll_messagecount = upperBound( inv_messages )

for ll_messageindex = 1 to ll_messagecount
   if isValid( inv_messages[ll_messageindex] ) or not isNull(inv_messages[ll_messageindex]) then
      destroy inv_messages[ll_messageindex]
   end if
next

inv_messages = lnv_messages

return 1

end function

public function long getmessagecount ();////////////////////////////////////////////////////////////////
// Description:
//    Returns a count of all messages
//
// 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 = "getMessageCount( ) "

return upperBound( inv_messages )
end function

public function long getmessagecount (string as_messagetype);////////////////////////////////////////////////////////////////
// Description:
//    Returns a count of all messages of a specific type
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_messagetype - message type
// 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 = "getMessageCount( String ) "

long                 ll_messagecount
long                 ll_messageindex
long                 ll_matchcount

ll_messagecount = upperBound( inv_messages )

for ll_messageindex = 1 to ll_messagecount
   if lower( as_messagetype ) = lower( inv_messages[ll_messageindex].is_type ) then
      ll_matchcount++
   end if
next



return ll_matchcount

end function

public function long getmessages (string as_messagetype, ref n_cst_messageattrib anv_messages[]);////////////////////////////////////////////////////////////////
// Description:
//    Returns all messages in array of message attribute objects given the message type
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_type - message type
//    anv_messages - message attribute objects holding the message information
// 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 = "getMessages( String, REF n_cst_messageattrib[] ) "

long                 ll_messagecount
long                 ll_messageindex
long                 ll_newmessageindex

ll_messagecount = upperBound( inv_messages )

for ll_messageindex = 1 to ll_messagecount
   if lower( as_messagetype ) = lower( inv_messages[ll_messageindex].is_type ) then
      ll_newmessageindex = upperBound( anv_messages ) + 1
      anv_messages[ll_newmessageindex] = create n_cst_messageattrib
      anv_messages[ll_newmessageindex].is_name = inv_messages[ll_messageindex].is_name
      anv_messages[ll_newmessageindex].is_type = inv_messages[ll_messageindex].is_type
      anv_messages[ll_newmessageindex].is_text = inv_messages[ll_messageindex].is_text
      anv_messages[ll_newmessageindex].ib_value = inv_messages[ll_messageindex].ib_value
   end if
next

return 1

end function

public function long getmessage (string as_name, string as_type, ref n_cst_messageattrib anv_message);////////////////////////////////////////////////////////////////
// Description:
//    Locates the message attrib object given the message name
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_name - message name
//    anv_message - Message attrib object to hold the message data
// 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 = "getMessage( String, REF n_cst_messageattrib ) "

boolean              lb_exists

long                 ll_messagecount
long                 ll_messageindex

ll_messagecount = upperBound( inv_messages )

if not isValid( anv_message ) then
   anv_message = create n_cst_messageattrib
end if

for ll_messageindex = 1 to ll_messagecount
   if lower( as_name ) = lower( inv_messages[ll_messageindex].is_name ) and lower( as_type ) = lower( inv_messages[ll_messageindex].is_type ) then
      anv_message.is_name = inv_messages[ll_messageindex].is_name
      anv_message.is_type = inv_messages[ll_messageindex].is_type
      anv_message.is_text = inv_messages[ll_messageindex].is_text
      anv_message.ib_value = inv_messages[ll_messageindex].ib_value
      return 1
   end if
next

return -1

end function

public function long getmessagetext (string as_name, ref string as_text);////////////////////////////////////////////////////////////////
// Description:
//    Locates the message text given the message name
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_name - message name
//    as_text - Message Text attribute to hold the message data
// 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 = "getMessageText( String, REF String Text ) "

Long ll_ret
n_cst_messageattrib lnvo_messageattrib

ll_ret = getmessage(as_name, lnvo_messageattrib)

if ll_ret = 1 then
   as_text = lnvo_messageattrib.is_text
end if

return ll_ret
end function

public function long getmessagetext (string as_name, string as_type, ref string as_text);////////////////////////////////////////////////////////////////
// Description:
//    Locates the message text given the message name and message type
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_name - message name
//    as_type - message type
//    as_text - Message Text attribute to hold the message data
// 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 = "getMessageText( String, String, REF String Text ) "

Long ll_ret
n_cst_messageattrib lnvo_messageattrib

ll_ret = getmessage(as_name, as_type, lnvo_messageattrib)

if ll_ret = 1 then
   as_text = lnvo_messageattrib.is_text
end if

return ll_ret
end function

public function long add (string as_name, string as_text);////////////////////////////////////////////////////////////////
// Description:
//    Adds a message to the arrray using string values for  type and text
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_name - name
//    as_text - text
// 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 = "add( String, String ) "

return add( as_name, "", as_text )


end function

public function long add (string as_name, blob ab_data);add(as_name, "Blobdata")

inv_messages[UpperBound(inv_messages)].ib_value = ab_data

return 1
end function

public function long getmessagetext (string as_name, ref blob ab_data);constant string METHOD_NAME = "getMessageText( String, String, REF Blob ) "

Long ll_ret
n_cst_messageattrib lnvo_messageattrib

ll_ret = getmessage(as_name, lnvo_messageattrib)

if ll_ret = 1 then
   ab_data = lnvo_messageattrib.ib_value
end if

return ll_ret
end function

public function long toxml (string as_character, ref string as_document);blob lb_data

lb_data = Blob("None")

return toxml(as_character, as_document, lb_data)
end function

public function long toxml (string as_characterset, ref string as_document, ref blob ab_data);////////////////////////////////////////////////////////////////
// Description:
//    Convert all messages to an XML document
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    String   -  (REF) String to contain XML document
// 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 = "toXML(String, REF String, REF Blob) "

long                       ll_messagecount
long                       ll_messageindex
boolean                    lb_noblobflag = false
n_cst_xmlparser            lnv_xmlparser

//Set character set to UTF-8 in special cases where the argument service could not initialize to get the character set
//Can occur when sharing eaf_shared.pbl in development with client and component targets
//Technically character set is not necessary in EAF4 as everything is UTF-8
if ( as_characterset = "" ) or ( isNull( as_characterset ) ) then
   as_characterset = "UTF-8"
end if

if String(ab_data) = "None" then lb_noblobflag = true

lnv_xmlparser = create n_cst_xmlparser
lnv_xmlparser.setCharacterSet( as_characterset )

lnv_xmlparser.addElement( EAF_MESSAGES )

ll_messagecount = upperBound( inv_messages )

//Loop through all of the messages
for ll_messageindex = 1 to ll_messagecount
   //Start the message
   lnv_xmlparser.addElement( EAF_MESSAGE )

   if not isNull( inv_messages[ll_messageindex] ) and isValid (inv_messages[ll_messageindex] ) then
      //Add the properties
      lnv_xmlparser.addElement( EAF_MESSAGE_NAME, inv_messages[ll_messageindex].is_name, false, true )
      lnv_xmlparser.addElement( EAF_MESSAGE_TYPE, inv_messages[ll_messageindex].is_type, false, true )
      lnv_xmlparser.addElement( EAF_MESSAGE_TEXT, inv_messages[ll_messageindex].is_text, false, true )
      
      if not lb_noblobflag then
         if inv_messages[ll_messageindex].is_text = "Blobdata" then
            ab_data = inv_messages[ll_messageindex].ib_value
            lb_noblobflag = true
         end if
      end if
   end if
   
   //Close the message
   lnv_xmlparser.closeElement( EAF_MESSAGE )
next

lnv_xmlparser.closeElement( EAF_MESSAGES )

lnv_xmlparser.getDocument( as_document )

destroy lnv_xmlparser

return 1

end function

public function long append (string as_messages, blob ab_data);////////////////////////////////////////////////////////////////
// Description:
//    Appends the contents of an XML document of messages to the array
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_messages - Source messages XML document
// 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 = "append( REF n_cst_messageservice ) "

string                     ls_messages[]
string                     ls_values[]
long                       ll_messagecount
long                       ll_messageindex
boolean                    lb_noblobflag = false
n_cst_xmlparser            lnv_parser
n_cst_messageattrib        lnv_message

lnv_parser = create n_cst_xmlparser

lnv_parser.getElementList( as_messages, EAF_MESSAGE, ls_messages)

if String(ab_data) = "None" then lb_noblobflag = true

ll_messagecount = upperBound( ls_messages )

for ll_messageindex = 1 to ll_messagecount
   lnv_message = create n_cst_messageattrib
   lnv_parser.getelementlist( ls_messages[ll_messageindex], EAF_MESSAGE_NAME, ls_values)
   lnv_message.is_name = ls_values[1]
   lnv_parser.getelementlist( ls_messages[ll_messageindex], EAF_MESSAGE_TYPE, ls_values)
   lnv_message.is_type = ls_values[1]
   lnv_parser.getelementlist( ls_messages[ll_messageindex], EAF_MESSAGE_TEXT, ls_values)
   lnv_message.is_text = ls_values[1]
   
   if not lb_noblobflag then
      if lnv_message.is_text = "Blobdata" then
         lnv_message.ib_value = ab_data
         lb_noblobflag = true
      end if
   end if
   
   inv_messages[upperBound( inv_messages ) + 1] = lnv_message
next

destroy lnv_parser

return 1

end function

public function long append (string as_messages);Blob lb_data

lb_data = Blob("None")

return append(as_messages, lb_data)
end function

public function long parse (string as_messages, blob ab_data);////////////////////////////////////////////////////////////////
// Description:
//    Parses the messages from the XML document argument
//
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_messages - XML document containing messages
// 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 = "reset() "

//Reset the messages
reset()

return append( as_messages, ab_data)

end function

public function long parse (string as_messages);Blob lb_data

lb_data = Blob("None")

return parse(as_messages, lb_data)
end function

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

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