Win a copy of Rust Web Development this week in the Other Languages forum!

Dave Mulligan

Greenhorn
+ Follow
since Mar 14, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dave Mulligan

I had a similar, but different problem with Tomcat 6. Each time it started it would create a new tomcat-users.xml file with no content between the <tomcat-users> and the </tomcat-users> tag. After much wailing and gnashing of teeth and I spotted that all the content that I *thought* was in there was in fact commented out in the default file.

Ho hum. Hope this saves someone some time.
12 years ago
Oh dear, now I'm embarrassed. Try values() intead of entrySet() :roll:
Should have been obvious to any intelligent lifeform with a reference book.
Dave
18 years ago
OK, this is one of those things that sounds like it should be simple, but I'm just being blind. Feel free to start any (helpful) answer with "as should be obvious to any intelligent lifeform..."
I have a HashMap of Address objects, with Strings as the keys. I want to extract an array of Address objects from it. So I tried

but that throws an ArrayStoreException. I think that this is because the Set that is returned by the entrySet() method contains Map.Entry objects, not Address objects but that hasn't helped me work out how to get the contents as an Address[] array.
Any help gratefully accepted
Dave
18 years ago
Not that I'm one to worry a topic to death, or anything :roll: , but I've become interested in this particular issue, and have a follow-up question, to which Layne may or may not need the answer.
Here it is: sticking with the example of just adding two ComplexNumbers, there is a small but undeniable chance that the result of adding two ComplexDoubles will in fact result in a complex number whose real and imaginary parts are both integers (little "i"). In that case, this would better be returned as a ComplexInteger. Is there a generally accepted method or pattern for applying a cast in these sort of cases, or do we now have to resort to something like:

in the ComplexDouble class, and its inverse in the ComplexInteger class (as the result of dividing one ComplexInteger by another will probably not be a ComplexInteger)?
Incidentally, Layne, you may want to re-think the idea of using doubles as your data members, since they only give approximate answers, so a / b * b will not necessarily give you a again. BigDecimal might be the way to go.
[ June 16, 2003: Message edited by: Dave Mulligan ]
Ahh, all becomes clear...
I had missed that ComplexInteger called the addSumWithInt method of addend, rather than it's own addSumWithInt method.
Thanks for the explanation.
I tried something like that (without knowing the name - "double dispatch", must remember that, thanks ) But I ran into a problem that I couldn't get around using that approach: if you add a ComplexDouble to a ComplexInteger, the result should be a ComplexDouble, whereas if you add two ComplexIntegers together, the result should be another ComplexInteger.
In other words, the ComplexInteger class needs the "plus" (I agree - better than "add") method to be overloaded to return either a ComplexInteger or a ComplexDouble, but you can't overload a method by just modifying the return type. And, you can't define two "plus" methods, one that takes a ComplexInteger and one that takes a ComplexDouble, because then the client can't just have a generic ComplexNumber as the parameter in their code.
Am I missing something basic, or do we actually need "instanceOf" in this, ermm, instance?
Hi Layne,
I don't know of a pattern that applies directly to this, although the State pattern seems closest. Isn't this better approached as a tricky bit of polymorphism?
I've played around with this for a time, & I have a solution that has three classes: a base ComplexNumber class, and then 2 subclasses, ComplexInteger and ComplexDouble, which define their data members as ints and doubles respectively. The problem I ran into was that I couldn't find a way to have a getReal() or a getImaginary() method in the common class, because there is no return type that will allow ComplexInteger to return an int and ComplexDouble to return a double, and have the value recognized as an int. You can define a method <code> public double getInt() </CODE> but then the return value is always a double, even if it came from a ComplexInteger.
So, what I ended up doing was defining methods getRealInt() and getRealDouble() (and the same for the imaginary part), and having ComplexDouble throw an UnsupportedOperationException if it was asked for an int.
Then the code for add() looks like this:
so the client doesn't have to worry about whether they have a ComplexInteger or a ComplexDouble.
I'm not really happy with this approach, though - it seems little better than using the instanceOf operator to me.
Hope this is helpful
Dave
[ June 14, 2003: Message edited by: Dave Mulligan ]
I think I've figured it out.
I'd missed the <%@ page session="true" %> tag from the top of the page. Doh! :roll:
18 years ago
JSP
You could try something like this, assuming that you are enforcing unique user IDs (ie a SELECT statement using UserID will return either zero or one rows):

You'll need to create the NoSuchUserException class - just extend Exception.
On another note, you might want to try pulling this code out of the JSP into a bean, a servlet, or even a custom tag to improve re-usability in case you need this functionality on another page, and to help with the maintainance of your JSP.
Hope this helps
Dave
[ April 15, 2003: Message edited by: Dave Mulligan ]
18 years ago
JSP
Hi all,
Thanks for bothering to read this. I'm trying to tidy up some JSPs which had scriptlets all over them, by building the functionality into custom tags. The problem I'm seeing is that calls to
request.getSession(false)
return different HTTPSession objects, even though the HTTPServletRequest object is the same one (at least according to the ID tag in my debugger).
Here's the relevant fragment of the JSP:

Here's the code from the <shriek:connect /> tag. It is intended to get a database connection from the ConnectionFactory & store it in the session.

This seems to work fine.
The next tag, <shriek:restaurantListByLocale>, tries to use that Connection from the session. Here's the code from that tag handler:

printSessionAttributes() just dumps all of the session's attributes onto the console.
What happens is that the HTTPSession object returned in the doStartTag() method is a different one to the one returned in the doInitBody() method, and so the JSPException with the message "Connection not found in session" is thrown.
Can anyone shed some light on this? And perhaps recommend a good book on custom tags - all my books are very light on details.
Many many thanks
Dave
[ April 15, 2003: Message edited by: Dave Mulligan ]
18 years ago
JSP
Thanks Jim,
Now I know I can safely encode the entire stream, including the tags & the encoding instructions, it works just fine.
Thanks again for the help
Dave
18 years ago
Just re-read my last post & realized I could have been clearer about why I want to encode only the content of the XML tags, and not the entire output stream.
The very start of my XML is:

So, if I encode the entire stream, the instruction on how to decode the content will itself be encoded!
Dave
18 years ago
You can trace where the method is called from in WSAD by right-clicking the method in the Outline panel and choosing "References".
Dave
Thanks Jim,
1. I agree. I'm learning to trust that nagging "I really shouldn't be doing this" feeling.
2. I see what you're suggesting, but I don't think this solves my problem, unless I've misunderstood the problem. When I create the XML I want to send, doesn't only the content of the tags need to be encoded, and not the tags themselves? If, for example, I want to send in my XML, don't I only have to run "+44 121-534-8707" through the encoder?
If this is right, then I run into a new problem with using the OutputStreamWriter - how do I append the encoded byte array that it produces to the StringBuffer that is building my XML?
Oh, and just to add to the fun, I'm restricted to JDK 1.1.8, so I can't use the java.nio.Encoder class & related methods.
I've come up with this as a way to do this:

but it has the disadvantage of encoding every character, even the low ASCII values that are valid, which destroys the readability of my XML. On the other hand, it will be (should be) reconstructed by the receiving machine, so this shouldn't be a problem.
Am I on the right track?
Thanks
Dave
18 years ago
Hi all,
I have a need to convert incoming String data into UTF-16, so that I can send it as an XML stream to a listener. I've found this algorithm to translate into UTF-8, (W3C open-source code) but can't find one for UTF-16. The reason for wanting to go to UTF-16 is that the receiving application wants UTF-16.
Here are my questions:
1. Does it matter if I send my text encoded as UTF-8 and say that it is "UTF-16"? It seems to work, but I'm very nervous about this.
2. Does anyone have a simple UTF-16 converter, similar to the one above?
Many thanks
Dave
18 years ago