File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes wrapping a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "wrapping a class" Watch "wrapping a class" New topic
Author

wrapping a class

Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Hello All, I have a spellchecker module that needs to be 'wrapped'. I need to understand a bit more about the concept of wrapping a class. My end goal/task here is to 'wrap this module so that it can be used by many different applications. I have the guts of the program, Jazzy, and I need to know how to go about making the functionality accessible through wrapping. TIA
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm not really sure what you're asking: is it an API? An application?
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Hi, sorry for the ambiguity. It is an API for a spell checker program. What I am trying to take a spellchecker program and modify it to plug into a web app we have here at the college. We are using templates for profs, etc. to send mass mailings and currently there is no spell checking on it. So...long story short I am wondering how the best way to get the spellchecker integrated into the web app. I was told I need to write a wrapper class and I was wondering what all that entails. I believe that I need ti identify the API components of the spellchecker and expose them to web app? Does this sound even close to the mark? Thanks again.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm not even sure why you'd need to wrap it--just include the library in your collection of web app libs and call it from within the system.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18993
    
    8

Dan Grindstaff wrote:I was told I need to write a wrapper class and I was wondering what all that entails. I believe that I need ti identify the API components of the spellchecker and expose them to web app?


Yeah, that sounds right. But is this one of the cases where the pointy-haired manager says "Simple, all you have to do is..."? Or was it said by somebody who actually knows something about the application in question? I ask because the vast majority of applications don't have a published API whereby other code can access their functions.

If your application has a GUI interface that's a pretty good sign that it wasn't designed for access like that. Of course that's just a general statement, so yes. Start by identifying the spellchecker's API components.
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Thanks for the replies! I was able to download the source code and build it and it runs as an applet so maybe it cannot be accessed as a library. I was thinking of trying to integrate the spell checking classes and methods into a new library file that (as you pointed out) could be accessed as a library. Oh, also, my tech lead suggested creating a wrapper class for it. TIA.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Depending on how it's set up it might be possible to use the library as-is.

Roller, a popular Java-based blogging app, seems to use Jazzy--I suspect using it as-is is trivial.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18993
    
    8

Dan Grindstaff wrote:... it runs as an applet so maybe it cannot be accessed as a library...


Well, at least it's Java. So it might well have an API, and the applet is just an example of a wrapper which calls that API. From what David says it sounds like you have a pretty good chance.
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Thanks, again for the great answers! I have some more information that I need to share. I need to somehow modify Jazzy to function on the back end so that I pass it requests from a servlet (string) and it passes back a spelling suggestion if there is an error. These are my marching orders. This seems to me to be a little cumbersome. Shouldn't there be a way to call it's functionality like a program would reference a library? Any ideas would be greatly appreciated. Thanks!
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Hi Dan,

Here is a link to your post on the Sun Forums. Please Be forthright when posting to other sites.


Steve
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Dan Grindstaff wrote:Thanks, again for the great answers! I have some more information that I need to share. I need to somehow modify Jazzy to function on the back end so that I pass it requests from a servlet (string) and it passes back a spelling suggestion if there is an error. These are my marching orders. This seems to me to be a little cumbersome. Shouldn't there be a way to call it's functionality like a program would reference a library? Any ideas would be greatly appreciated. Thanks!


Have you found its API? It looks like the site completely lacks documentation, but they do provide a source-code download so you should be able to see what methods are available, and perhaps build javadocs from it to make some reference material.
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Thanks for your continued help and I will follow the protocol about crossing sites, sorry about that. You are absolutely right, there is no published API but javadoc comments to be extracted from the code itself. I have decided to go this route and build a summary of methods that can be called for the simplest spell checker functionality. This project is a demo for the rest of the MnSCU college dev teams so I am really building a prototype. I was hoping to get away with implementing it as simply as possible by just referencing the jar (although there doesns'nt appear to be one) in the MnSCU web app code. Oh well, I will continue on the wrapper adventure. Thanks again for all your help guys and sorry about the crossing posts boffo. Dan.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There's a jar; see here.

There's an Ant task to build javadocs; ant javadoc.

There's example code of how to use it:Looks like it might be British English, but it's probably trivial to figure out their dictionary format and roll your own.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Building a Jar is trivial, the core application (in the com.swabunga.spell.engine and com.swabunga.spell.event packages have no external dependencies that I can see.

I made a local copy of the API, and the code is poorly documents (no surprise I guess being as they don't provide any documentation on their website). But there is an interface called SpellDictionary which looks to be the crux of the tool. It provides methods to check if a word is correct and methods to get suggested words if it is not correct. So you will want to look at implementations of that interface.

And I am sure looking at the provided examples will help.

Looks like their download site does have a javadoc download. Check under the >Jazzy > Jazzy 0.5 > option.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

(It looks like you need to create a dict directory for a compile if you're interested in building it yourself, or fix their build script. You may want to look for a more recent spellchecker.)
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Hello All, I was thinking of turning com.swabunga.spell.engine and com.swabunga.spell.event packages bundled with the dictionary into a bean and calling the functionality from a servlet for demo purposes, then finding a way to modify the existing communications jsp to call it when I get the go ahead. We are using JBoss. Any advice is greatly appreciated. TIA.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why can't you just use the library as-is?
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Hi David, Could you please expand on just using the library as is? Thanks, Dan.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I posted a code sample already; not sure what else to do.
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Hi, I'm sorry I should be more clear. I am wondering what context to call your code from. Should I write a JSP and call it from there or how do I make use of it? Thanks, Dan.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Hmm... I am starting to wonder exactly how you plan to use this.

What context do you WANT to use this in? You talk about wrapping it in a bean, now to call it from a JSP. What exactly are you trying to spell check? When exactly do you expect the spellchecking to occur?

My fear is that you have client - side code, say an HTML text area, and you want to spell check the contents of it. That is fine, but using JEE technologies (alone) you would do the spell checking on the Server Side. You would have to submit the form, pass the contents through the spell checker as in the code that David provided (best called from a Servlet or an action class called from the Servlet), then send the results of the spell check back to the client. This sounds a bit out of the way, but if you are good with Ajax it may not be so tough.

If you want to spell check as the customer types, or as close to it as possible without the cost of 1 or more server round-trips then you need to work with client-side technologies. That would be Javascript for the most part. My first thought would be to see if there are already-implemented Javascript spell checkers.

If you need to use a Java spellchecker, but you want to do it client-side then you are really left with an Applet.
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Steve Luke wrote:My fear is that you have client - side code, say an HTML text area, and you want to spell check the contents of it. That is fine, but using JEE technologies (alone) you would do the spell checking on the Server Side. You would have to submit the form, pass the contents through the spell checker as in the code that David provided (best called from a Servlet or an action class called from the Servlet), then send the results of the spell check back to the client. This sounds a bit out of the way, but if you are good with Ajax it may not be so tough..


Hi, This is exactly what I want to do. That is why I was thinking the bean residing on the app server would work. I am not very good with AJAX but was told I need to ramp up on JSON to pass results back to the page.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

The you don't need to create a 'bean' or wrap the API in any way. Just use a Servlet which would be designed to receive the requests from Javascript, translates it into text and then feeds it directly into the API. I think David's example is spot on for the type of code you would need to put into the Servlet for the spell checking part.

Catch up on JSON and AJAX, as well as basic Servlet communications to address the rest.
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Thanks! David, Steve and Paul! I appreciate you being willing to help out in such great detail. I really needed this!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: wrapping a class