File: eaf_n_cst_contentproviderservicebroker.sru
Size: 7417
Date: Tue, 22 Jan 2008 23:40:18 +0100
$PBExportHeader$eaf_n_cst_contentproviderservicebroker.sru
forward
global type eaf_n_cst_contentproviderservicebroker from eaf_n_cst_baseservice
end type
end forward

global type eaf_n_cst_contentproviderservicebroker from eaf_n_cst_baseservice
string is_logservice = "n_cst_loggingservice"
end type
global eaf_n_cst_contentproviderservicebroker eaf_n_cst_contentproviderservicebroker

type variables
protected:

string         is_mimetypes[]
string         is_contentproviderservices[]


end variables

forward prototypes
public function long registercontentproviderservice (string as_mimetype, string as_contentproviderservice)
public function long getserviceindex (string as_mimetype)
public function long getcontentproviderservice (string as_mimetype, ref n_cst_contentproviderservice anv_contentproviderservice)
end prototypes

public function long registercontentproviderservice (string as_mimetype, string as_contentproviderservice);////////////////////////////////////////////////////////////////
// Description:
//    Registers the class name of the content provider service with
//    the specified MIME type
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_mimetype - MIME type of requested content provider service
//    as_contentproviderservice - Class name of the content provider 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 = "registerContentProviderService string as_mimetype, string as_contentproviderservice"

long           ll_index

inv_log.traceLog( METHOD_NAME, "" )

//check to see if mime type has been registered
ll_index = getServiceIndex( as_mimetype )

Choose Case ll_index
   Case 0
      //service does not exist - create new index
      ll_index = upperBound( is_contentproviderservices ) + 1
      inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Did not find existing content provider for " + as_mimetype + ". About to register " + as_contentproviderservice )
   Case -1
      return -1
   Case 1
      //service exists - overwrite existing service      
      inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Found existing content provider for " + as_mimetype + ". About to register " + as_contentproviderservice + " as the new content provider service." )
End Choose

//register service
is_mimetypes[ll_index] = as_mimetype
is_contentproviderservices[ll_index] = as_contentproviderservice

inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Registered MIME Type " + as_mimetype + " to " + as_contentproviderservice )

return 1

end function

public function long getserviceindex (string as_mimetype);////////////////////////////////////////////////////////////////
// Description:
//    Returns the index of the content provider service given the mime type
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_mimetype - MIME type of requested content provider service
// Returns: 
//     0 - MIME type index not found
//    >0 - Index of the content provider service
////////////////////////////////////////////////////////////////
// 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.
//////////////////////////////////////////////////////////////// 

long                 ll_servicecount
long                 ll_serviceindex

//loop through existing registered services checking mime type match
ll_servicecount = upperBound( is_contentproviderservices )

as_mimetype = Lower( as_mimetype )

for ll_serviceindex = 1 to ll_servicecount
   if Lower( is_mimetypes[ll_serviceindex] ) = as_mimetype then
      return ll_serviceindex
   end if   
next

return 0

end function

public function long getcontentproviderservice (string as_mimetype, ref n_cst_contentproviderservice anv_contentproviderservice);////////////////////////////////////////////////////////////////
// Description:
//    Creates the content provider service associated with the mime type
//    Places the created object reference in anv_contentproviderservice
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_mimetype - MIME type of requested content provider service
//    anv_contentproviderservice - (REF) Content provider service reference variable
// 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 = "getContentProviderService ( string , REF n_cst_contentproviderservice )"

long              ll_index


inv_log.traceLog( METHOD_NAME, "" )

ll_index = getServiceIndex( as_mimetype )

if ll_index < 1 then
   inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_ERROR, "Failed to locate a Content Provider Service for MIME Type " + as_mimetype )
   return -1
end if

if isValid( anv_contentproviderservice ) then
   destroy anv_contentproviderservice
end if

anv_contentproviderservice = create using is_contentproviderservices[ll_index]

return 1

end function

on eaf_n_cst_contentproviderservicebroker.create
call super::create
end on

on eaf_n_cst_contentproviderservicebroker.destroy
call super::destroy
end on

event constructor;call super::constructor;////////////////////////////////////////////////////////////////
// Description:
//    Constructor
//
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// 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.
//////////////////////////////////////////////////////////////// 

//Register the built-in content type providers
registerContentProviderService( inv_constants.MIME_TYPE_EAF_RESULTSET, inv_constants.EAF_RESULTSET_PROVIDER_SERVICE )
registerContentProviderService( inv_constants.MIME_TYPE_PDF, inv_constants.EAF_PDF_PROVIDER_SERVICE )
registerContentProviderService( inv_constants.MIME_TYPE_DW_NATIVE, inv_constants.EAF_DW_NATIVE_PROVIDER_SERVICE )
registerContentProviderService( inv_constants.MIME_TYPE_HTML, inv_constants.EAF_HTML_PROVIDER_SERVICE )
registerContentProviderService( inv_constants.MIME_TYPE_TEXT, inv_constants.EAF_TEXT_PROVIDER_SERVICE )
registerContentProviderService( inv_constants.MIME_TYPE_EXCEL, inv_constants.EAF_EXCEL_PROVIDER_SERVICE )
registerContentProviderService( inv_constants.MIME_TYPE_XML, inv_constants.EAF_XML_PROVIDER_SERVICE )
registerContentProviderService( inv_constants.MIME_TYPE_PSR, inv_constants.EAF_PSR_PROVIDER_SERVICE )
end event