Rick Crawford

Ranch Hand
+ Follow
since Aug 17, 2001
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rick Crawford

Thanks so much for your response. I'd like to ask a few more questions if I may. I'm trying to understand what you can and can't do with ServletContext.
I ended up creating a couple of classes for outage management. My Outage class contains the start and end times for a specific outage. It features an isOutageInEffect() method that returns boolean by comparing the current date and time to the start and end times of an Outage instance. I then created an OutageCalendar class for maintaining a collection of Outages (in case we ever have to have more than one outage / week.) This class also has an isOutageInEffect()
method to test each Outage in the collection. I created an xml file with my outage information, and use it to build the OutageCalendar.
I'm kind of a servlet novice, but I've been studying Servlet contexts and see references to getInitParameter, which I'm thinking is the way to get a handle on the context. But is there a way to utilize this functionality I've mentioned above within ServletContext?
Another idea I was considering: what if I made my OutageCalendar class a singleton class? In it's constructor, it could load up all the outages in the config file. Then each servlet could just ask the same copy of the OutageCalendar if an outage is in effect.
Thanks again for the response.
Rick <><
21 years ago
Hello all. I've got a question that I hope there's a ready answer for. I wasn't sure if this is the right forum for this, but I thought I'd start here.
I am working on a website that will experience scheduled outages for back-end database administration. I'm trying to figure out an elegant way to detect when an outage is in effect so my application won't attempt to connect to the database, and display some sort of a 'we're sorry
but the web is unavailable until ??? time' message. I thought about having an 'outage-config.xml' file where the scheduled outages are
listed, but I hate to have to read this file everytime one of my application pages are hit. I am concerned about the file io overhead, as well as the XML parsing that'd have to be done. Is there some slick way to do this that someone could share? Is there a way to have a separate process, an outage poller maybe, that wakes up every so often and reads this file, then sets a system property that my servlets and .jsp's could check to see if an outage is in effect? By the way, I'm using Tomcat 3.2.3 on a Linux box.
Thanks in advance for any assistance,
Rick <><
21 years ago
Hello all. I'm doing some experimenting with Apache Axis. I've successfully deployed a couple of trivial web services, and am even to the point of returning and serializing JavaBeans from the service. Life is good. But now I have a question that I’m kind of stuck on.
I’m trying to figure out how to write a Java client to use one of my web services that returns a JavaBean, but this time I don't want to depend on Bean serialization on the client to pull out the pieces of data within the class. The scenario is that of a client who doesn’t have access to my compiled Java classes.
What I think I need to do is to invoke the service as per normal, then somehow ask the return result for the soap response, parsing the XML myself for the individual pieces and parts. Is this the correct approach for a scenario like this? I’ve been reading about and experimenting with the MessageContext and Message classes thinking they would give me a handle to the actual soap response, but so far I don’t have anything that works.
Thanks in advance for any suggestions,
Rick <><
21 years ago
Hello all. I'm hoping someone here can give me some advice.
I've got an assignment that is going to involve sharing a Java application's functionality to a non-Java (VB) client. The Java application is hosted on a webserver running Tomcat. This client will have to access the application across our company's network. I'm thinking that creating a Soap service may be the way to go.
I downloaded the Soap SDK from Apache. I found a simple tutorial that demonstrated how to build an Soap-RPC service with a Java client. I modified the example to actually return data extracted from a database:
First the server:

Next, the client:

It seems to work okay. But I'm not sure where to go from here. My actual implementation will be MUCH more complicated than this. For my use, this server would need to return back a lot of information about a customer than just its name. I need the server to pass back several attributes.. that could be placed in an XML datagram! Would I have to set up a separate 'getter' method for each attribute, and
re-run the service for each?
I really don't know how to even ask this, but I'll try: if your server needs to return more than one value, what are your options? I would
imagine that if I was going Java-to-Java, I might be able to pass back a JavaBean (or some other type of Java container, like a HashMap.) But what do you do if your client is non-Java?
I'm quite confused, and very much appreciate any advice on this!
Rick Crawford <><
21 years ago
Awesome! Works like a champ!
Thanks for the help,
Rick <><
21 years ago
Hello all. I've got a question / problem using Calendar.roll(). It's probably just me understanding how things work (usually is), but before I code a workaround, I want to make sure I'm doing this right. What I'm trying to do is take an input date, then advance it by a certain number of months.
For example:

Here's the output, based on the current date of 2002-03-26:

But what I REALLY want to see is this:

..where the year is also incremented by adding one month each time once January is reached.
My question is, will I have to explicitly code for this: check to see if we're currently up to December, then increment the month AND year?
Rick <><
21 years ago
Our web development team has come upon a standard layout we'd like to adopt for all Java classes that we're going to write. For example, we'd like to provide a little starter method template that already has some of our standard error handling in place.
I know about code templates, as I've already created a few of those. But this is a bit different, in that anytime we start a new class we'd like for the wizard to use our layout instead of the default. Is there is a way to modify the behavior of the new class wizard in JBuilder 5?
Rick <><
Thanks so much for the response. What you recommended is precisely what I ended up doing to get my code converted. What a pain! I'm glad to hear there's a more automatic way to accomplish this in JBuilder 6.
I sincerely appreciate the help.
Rick <><
Hello all. I'm using JBuilder 5.0 and have a question about how to repackage a bunch of classes that exist in several projects.
Due to some company imposed mandates, I've got to repackage the Java classes in several projects from com.xxx to com.xxx.xxx (not actually 'xxx', just an example.) In other words, I've got to add another 'node' to the package name. I know that I'll have to change the package name in each Java class and recompile, but when I do JBuilder complains:
"MyCode.java": Error #: 901 : package com.xxx.xxx stated in source c:\Documents and Settings\rlc1234\jbproject\MyNewProject\src\com\xx\MyCode.java does not match directory com.xxx
I could probably shut JBuilder down and manually create all new directories under the existing src and classes directories within each project, then move each .java file, but I was hoping there was a better way.
Any suggestions?
Rick <><
[ January 25, 2002: Message edited by: Rick Crawford ]
Thanks for the reply. One thing that I didn't make very clear is that FONTFACE, FONTSIZE, XPOS, etc. are nodes that are common for several data items that are not shown in my example, not just the MESSAGES nodes. The entire XML configuration file is pretty big, but here are a few more nodes in addition to the MESSAGES section:

What I'd like to do is access this data by the high level node name, such as SHIPPERNAME, then pick out these common fields and store them in a structure (an inner class.) Right now, I'm retrieving the values with multiple calls to my 'getVal' method, like this:

..and so on. But what I'd rather do is create some sort of a method call that would interrogate all the nodes within the '/MAINPAGEOVERLAY/SHIPPERNAME', looking for the named values of FONTFACE, FONTSIZE, etc., storing them within a structure:

My imaginary method signature (that I can't figure out how to write):

I would then use the values from the returned printPosition object. And as I alluded to in the previous message, the high level node, such as MESSAGES, could contain lower level nodes such as MESSAGE. But at some point when the lowest level has been reached, the common attributes of FONT and XPOS would be found.
This is all pretty complicated, and I apologize if I'm not being very clear on this. As always, I sincerely appreciate the help.
Rick <><
Hello all. I'm trying to use XPath expressions to read an XML file. My basic question is, how do I create a method that uses XPath to position a 'pointer' to a section within an XML document, then iterate through 'child' and 'grandchild' nodes looking for desired values?
Here is the relevant subset of the file:

I wrote (actually, copied from somewhere, probably the Moose) a little helper method to look for data elements within the XML:

..and I use the method like this:

Everything works pretty well if the section I'm looking for occurs only once in the file. But I want to access the attributes FONTFACE, FONTSIZE, XPOS, YPOS and TEXT within each MESSAGE section. I suppose could rename the MESSAGE nodes to MESSAGE1, MESSAGE2, MESSAGE3, then path them in explicitly, but I'd prefer to leave it flexible enough that I could add a fourth MESSAGE.
I realize that I couldn't return all five child elements at once. But I figured I'd create another class with member variables for each element and use that for the return value.
Thanks in advance for any help,
Rick <><
My application is going to be running within a servlet. The application server I'm using is Tomcat. Basically, I'll receive a request from a browser that will contain user entered
'remarks' that may range from zero to dozens of words. Without getting into too much detail, I then have to dynamically format these comments into a print area with a specific font face and size. I don't want to hard-code these formatting parameters in the servlet. Instead, I'd prefer to read them in from a properties or an XML configuration file.
I may have nothing to worry about. As soon as Tomcat is finished with my request, the AWT thread may just die of its own accord. I guess I'm a little leery, since I don't know for sure.
Thanks so much,
Rick <><
22 years ago
Thanks so much for the code! I just cut 'n pasted it into JBuilder and tried it.. and it works great! I also got a kick out of the paragraph you used to test with!
One question though. I notice that your version has a feature similar to mine: there has to be a System.exit in the code to kill it. I had to cancel/reset the application within JBuilder if I take this out. This might or might not be a problem in my real application, which is a web-based application; I'll just have to give it a try. Is the requirement for a call to System.exit to kill the process an AWT thing there's just no getting around?
Once again, I'm extremely grateful for the help!
Rick <><
22 years ago
Well, I think I may have figured out the solution to my original question, only to discover another problem. The code below seems to do precisely what I want, but when the process (the call to my formatText method) finishes, the application won't 'quit' on its own. I have to add a System.exit(0) to kill it, and that may cause problems once I port this code into my complete application.
Based on process of elimination, the line of code that's hanging things is this one:
FontMetrics fm = myCanvas.getFontMetrics(new Font("Arial",Font.PLAIN, 12));
Here's the complete code:

I tried another method, but got the same results (plus a bunch of deprecation warnings):

Like I said, this all seems to be working but this one itty bitty glitch. Hopefully someone can spot what I'm doing wrong, or can suggest a better way to get the fontMetrics numbers I need to calculate a stringWidth based on a given font face and size.
Rick <><

[This message has been edited by Rick Crawford (edited December 19, 2001).]
22 years ago
I posted this question over in the 'Java Intermediate' forum, but thought the nature of my question might be better suited for this forum.
Without going into too much background detail, I need to parse a bunch of words separated by spaces, like a long paragraph, into a list (probably an ArrayList.) Each element in the list will be a String containing a section of the paragraph not to exceed a given length. I don't want to split any words. This is a non-graphical application (it's a web application.) This processing will be done in preparation to print onto (annotate) an image file.
In other words, I need a non-graphical word wrapper.
I could write a class that does pretty much I've described to this point (although any sample code someone else already has working would be much appreciated.) The real kicker is that I want to be able to specify a font size and face for the method to take under consideration in calculating the contents of each String. I would need to somehow specify a maximum number of pixels(?) as the length of each line.
This class would also need to calculate the offset between the 'sentence' Strings to print them down the page (the image.)
Here's a high-level use case of how I'd envision this to work:
TextWrapper tw = new TextWrapper();
tw.setTextToWrap("Here's the stuff we want to wrap all over the place, blah, blah, blah");
tw.setFont(new Font("Arial",Font.PLAIN,10));
for (int i = 0; i < tw.getNumLines(); i++) {
String nextLine = (String)tw.getLine(i);
// write out each line
Any suggestions to help me get started in the right direction on this? Thanks in advance for any assistance,
Rick <><

22 years ago