wood burning stoves 2.0*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Pattern Suggestion: Vendor providing challenging  problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Pattern Suggestion: Vendor providing challenging  problem" Watch "Pattern Suggestion: Vendor providing challenging  problem" New topic
Author

Pattern Suggestion: Vendor providing challenging problem

M Kozelek
Greenhorn

Joined: Feb 08, 2005
Posts: 21
Hello,

I recently was made responsible for integrating a reporting tool with an application we have in house that is relatively mature. It's replacing a custom FOP implementation.

There are two scenarios I must account for:

1- Using class files as datasources when the application executes a report.
2- Using class files as datasources when inside the vendors design tool and creating a report template.

In order for #1 to work, I have to accomplish #2 since the datasouce info is embedded into the report template.

The issue is that you can't pass the report design tool a parameter... just the fully qualified name of the class to use as a datasource. The datasource uses JDBC to return a resultset and the query/params are externalized in a XML file specific to the report.

Now before I go on, I have this working... I just don't like my solution AT ALL.

I have created an abstract class that is responsible for all of the XML parsing and database connection stuff, but I have had to create individual child classes that basically just hold the name of the report and subuery they are responsible for. This gets passed into the child class's constructor who calls super.init(name, query).

Works great, but doesn't seem right. This means for every report, I have to have a child class that is used for each query/subquery and an associated XML config.

The vendors suggestion had the names for all the reports in the abstract class (no longer abstract) and then a bunch of if-else statements. Wouldn't be terrible, but we have a lot of reports and this class would get large.

So finally, my question is, when you are in a situation where you can't really pass a parameter to help determine some course of action, is there a pattern that address this issue?

If you could point me in the right direction, I would appreciate it.

Thanks in advance!

mk
Gerald Davis
Ranch Hand

Joined: May 15, 2002
Posts: 872
I get bored of talking about design patterns
M Kozelek
Greenhorn

Joined: Feb 08, 2005
Posts: 21
Anyone else?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The if tests suggested by the vendor ... what do they test? Does the report writer tell the class the report name or id or something? I often try to replace a bunch of if tests with a single lookup in a map using whatever they give you as key. Maybe show us a sample of what the suggested if tests look like.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[MK]: It's replacing a custom FOP implementation.

Those initials probably mean something to many people, but not me. And www.acronymfinder.com doesn't seem to help. A hint would be appreciated.

The vendors suggestion had the names for all the reports in the abstract class (no longer abstract) and then a bunch of if-else statements. Wouldn't be terrible, but we have a lot of reports and this class would get large.

...I have had to create individual child classes that basically just hold the name of the report and subuery they are responsible for. This gets passed into the child class's constructor who calls super.init(name, query).


As Stan suggested, using a Map rather than a bunch of if-else seems like a good alternative. Perhaps you can create a single class that reads a single config file. The config file would list all the report names and the associated subqueries. You read this file once and create a Map which links a report name to a particular query. Does that sound feasible?

[Gerald]: I get bored of talking about design patterns

Do you suppose that might be a sign you shouldn't be hanging around this particular forum, then? :roll: Please, rub a couple neurons together and try to create a spark. You don't like anything about object-oriented programming. Fine. So why are you here? Please try not to intrude on posts from people who actually want to be here.


"I'm not back." - Bill Harding, Twister
Gerald Davis
Ranch Hand

Joined: May 15, 2002
Posts: 872
All methodologies have their uses and understanding of design patters is very important as you understand, it is design reuse and the key good communication between developers. Its is also bridge the gap between the understanding of low level strongly typed languages to high.

We cannot under estimate the importance of opposing view and competition, it is what made our country great. Most of the time, I agree on 85% of all issues about I just do not talk about these 85% of issues only the ones we don't agree on.

Why I said what I did was partly because I was saying what was on my mind(i am not completely board with design patterns) and partly because I wanted the guy to know I am around hand have read his message. This forum has got a bit empty lately and knowing someone has read my message is good so I thought the dude would feel the same way; its just daayz talk it don't mean nothing.
Gerald Davis
Ranch Hand

Joined: May 15, 2002
Posts: 872
Originally posted by M Kozelek:

So finally, my question is, when you are in a situation where you can't really pass a parameter to help determine some course of action, is there a pattern that address this issue?


I guess your message is simple to understand;However, I did have to read it a second time, as I am a bit dyslexic. The logic was hidden behind the words a little. Much the same way as logic is often hidden in a verbose languages like C++ and to a limited extent Java.

I do believe (I could be wrong) that your message down could have been broken down to a simple question: �How can I convert if_else, which is not convenient because of the a amount of conditions need, to a more element solution�.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Jim Yingst:
[MK]: It's replacing a custom FOP implementation.

Those initials probably mean something to many people, but not me. And www.acronymfinder.com doesn't seem to help. A hint would be appreciated.


I guess that would be Apache-FOP, an open source XSL-FO processor. (We used that some time ago, too, but now switched to ^JasperReports...)


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
M Kozelek
Greenhorn

Joined: Feb 08, 2005
Posts: 21
Yes, the Map() solution is now feasible. I spoke with a contact from the vendor and the solution finally emerged.

The actual problem, is that I can't pass parameters in the report designer. So even if I had a Map(), I would have nothing to pass it in order to get the value back I want.

At least this is what it seemed at first. There is a way of faking it with this tool where I can force the product to read a parameter not associated with the process (what at first was interpreted as a constraint), and use that to store a value.

From the design time perspective, this is a little cumbersome still, but at run-time this will be awesome.

So thank you for your help everyone.. well except Gerald that is.

I've taken care to make sure that we can rip and replace the report engine if necessary without impacting the code too much. However, I didn't follow any formal pattern.

Is this a case of Adapter, Strategy, or something else? I'm not very experienced with patterns obviously, but I was looking into these to see if there was anything they provided that I may not be accounting for.

Thanks again!!!

mk
Gerald Davis
Ranch Hand

Joined: May 15, 2002
Posts: 872
Oooyyy !
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Pattern Suggestion: Vendor providing challenging problem
 
Similar Threads
Jakarta commons Digester
simple jasper report in java without a database.
Jasper Reports - No datasource? Help please!
Generate Charts with JasperReport
How to Create Auto Schema