Odd Question as usual

CharlesIPTI

Active Member
Licensed User
Longtime User
I'm trying to keep my code legible if not elegant. I have MULTIPLE web service calls getting and updating data.

I have an activity housing the JobDone & UrlDone subs.
I would like to know if its impossible to call specific parsers in other code modules from this single JobDone Sub. I'm trying to separate the objects, sorry the types for a bit more clarity in the code.

SUMMARY ::
B4X:
Sub JobDone (JobPassed As String)   
       
     Select JobPassed
           Case "Logout"
                 HttpUtil Stuff Here  Stream Stuff 
              parser.Parse(InputStream, "Parser") 

     Case "GetLocMap"   
                 HttpUtil Stuff Here  Stream Stuff
                 daObject.cLocParser.Parse(InputStream, "daObject.cLocParser")

          Case "SomeOtherWebMethod"
                 HttpUtil Stuff Here  Stream Stuff
                 sumOtherObject.ItsSpecificParser.Parse(InputStream, "sumOtherObject.ItsSpecificParser")




My test to hop into another code module has been fruitless, however simply calling ANOTHER parser in the same code module is apparently working but ... this isn't much different than the over crowded select case statement I was already going to implement

Example ::
getCartLocParser.Parse(InputStream, "getCartLocParser")
This works , its not trying to jump into another code module


So I'd either;
have some 12-19 different parsers in this single module each manipulating its specific "type" (class) of course each has its start & end element subs.
OR
One gigantic almost unintelligible confusing mess of if statements and try catches as I juggle these various requests and responses from the web service in ONE parser (two actually considering the begin & end element subs)


You see why I want to break this out into object ,, excuse me.... type specific responses, requests


I humbly and gratefully appreciate ANY and ALL insight or ideas in addressing this concern.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Code modules cannot handle events.
2. Events are raised in the activity or service that initialized the parser object.

There are technical reasons for these restrictions which are related to the way Android manages activities and services inside your application.

There are several ways that you can use to delegate the events and implement the parsing code in a code module.
The simplest is to have multiple Parse event handles in this module where each one just delegates to the correct code module.
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Lets see if I understand this correctly

Erel I think I understand your recommendation but I obviously can't picture just how to implement this just yet.. As you see I thought I could just call a method in the other code module from my JobDone.

If I understand correctly
in
my JobDone in the case of

Case "GetLocMap"

I have the code there send the InputStream to a local sub
and THAT local sub in-turn call the specific code module for the originating type and its parsers (int that code module) do the work ?


Summary::
I just add another level of indirection by intercepting the InputStream
send it to a local Sub and that sub sends it to my code module specifically created for this "type"
And this code module (Type Specific) simply
containing a parser specifically for its"Type"


Sounds Right ??

:eek: :icon_clap:
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use a single parser and create multiple event handlers subs that will delegate the sax events to the required code module:
B4X:
Sub Parser1_StartElement (Uri As String, Name As String, Attributes As Attributes)
   CodeMocule1.StartElement(Name, Attributes)
End Sub
Sub Parser1_EndElement (Uri As String, Name As String, Text As StringBuilder)
   CodeModule1.EndElement(Name, Text)
End Sub

Sub Parser2_StartElement (Uri As String, Name As String, Attributes As Attributes)
   CodeMocule2.StartElement(Name, Attributes)
End Sub
Sub Parser2_EndElement (Uri As String, Name As String, Text As StringBuilder)
   CodeModule21.EndElement(Name, Text)
End Sub

Sub Parser3_StartElement (Uri As String, Name As String, Attributes As Attributes)
   CodeMocule3.StartElement(Name, Attributes)
End Sub
Sub Parser3_EndElement (Uri As String, Name As String, Text As StringBuilder)
   CodeModule3.EndElement(Name, Text)
End Sub

B4X:
Sub JobDone (JobPassed As String)    
       
     Select JobPassed
           Case "Logout"
                 HttpUtil Stuff Here  Stream Stuff 
               parser.Parse(InputStream, "Parser1") 

      Case "GetLocMap"    
                 HttpUtil Stuff Here  Stream Stuff
                 parser.Parse(InputStream, "Parser2") 

          Case "SomeOtherWebMethod"
                 HttpUtil Stuff Here  Stream Stuff
                 parser.Parse(InputStream, "Parser3")
 
Upvote 0
Top