This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hook class  RSS feed

 
Michael Workman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first post in the Big Moose Saloon! I'm sure it won't be my last, (unless I'm gunned down out in the street after this one.)

Allow me to belly-up to the Big Moose bar and throw this out to anyone who cares to help me.

I need a 'simplified' explanation of how the Hook class is used and works, and maybe with an example. I just can't seem to wrap my thinking around it. Here's my deal: At work we have a Java app we call dbsync2 that does a lot, but in its simplest form can consume a complex XML document as a source data set and present it to the dbsync engine to synchronize two tables or flat files across same or different platforms. The methods in dbsync2 can be overridden with a Java bean shell. Within the bean shell, you 'Hook' events to customize dbsync2's behavior.

I just don't understand what the Hook class accomplishes, or how it works, between the Java dbsync engine, the xml configuration file, and the hook events within the Java bean shell. I realize you may need more information on the specifics of my situation, but a generic 'simplified' explanation and example of the Hook class and how it works generally speaking, would suffice for me.

I'm going to turn around now and throw back this shot that was just poured for me. Just don't shoot me in the back! Thanks bartender.

Mike W.





 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,

Welcome to JavaRanch! It's pretty rare that anyone gets shot around here these days. If we really don't like somebody, we just send 'em out back to shovel pig manure. You're gonna do fine.

Anyway, I am thinking that if there's a class named "Hook" that figures prominently in your application, it may be custom to that environment; there's no class by that name in the standard Java APIs nor in the BeanShell library. Maybe if you showed us some code, we could help you understand what you were looking at.
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael, you can start investigating from the import you use in the code, that should be the starting point. from there the package and then google
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From your brief description, I would guess that your Hook class is akin to what the standard APIs would call an EventHandler (and works like 'Closures', 'Lambda Functions', or 'Funs' work in other languages.) The idea is this: Your dbsync2 class probably has a series of methods that gets called for specific 'events' in the XML file (for example, when you close a specific XML tag. Here is a simplified example. Say you have an XML file like this:

Then, your dbsync2 code might have methods like this:

Those methods would represent the 'default' behavior for processing the particular parts of the XML. Somewhere there is an XML Parser which knows how to read the file, and call these methods at the correct time. That isn't the important part here. What is important is what happens when these methods (or behaviors) get called. You say that you are given the opportunity to 'override' the behavior by providing Hook instances. So as simply as possible, this would mean that if you provide a Hook for a particular behavior, then that hook's method should get called instead of the default behavior of the method. It might look like this:


Then when you wanted to override the behavior you could do:


So there is some behavior that happens when you do nothing. In the design above, the default behavior is provided as a Hook implementation. When a specific 'Event' in the XML file gets processed then the correct Hook is called. If you haven't set your own Hook, then the 'default' one is run, but if you set your own implementation then your Hook gets called instead - this 'overriding' the default behavior.
 
Michael Workman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you one and all for your quick and helpful responses. Steve you are dead on as to what is taking place, and your explanation and code is much appreciated. I have a more thorough understanding now of how our Hook class is used. Thanks everybody!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!