Re: Extending/replacing a class without a public constructor
From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 06/10/04
- Next message: Christophe Vanfleteren: "Re: Java API for correcting malformed HTML code"
- Previous message: rjweytens: "org.apache.jasper.JasperException: Cannot find bean under name myBean"
- In reply to: Hugh Beyer: "Extending/replacing a class without a public constructor"
- Next in thread: Hugh Beyer: "Re: Extending/replacing a class without a public constructor"
- Reply: Hugh Beyer: "Re: Extending/replacing a class without a public constructor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 10 Jun 2004 15:12:53 -0500
Hugh Beyer wrote:
> I'm having a really frustrating problem and I hope you guys can give me
> some help.
>
> I'm trying to write a test suite for a graphics-heavy app that uses
> MIDP/J2ME. These apps use the Graphics class to do their screen updates.
>
> What I want to do is subclass the Graphics class with my own class that
> captures all calls and writes to a log that my tests can later examine.
> Unfortunately, all the constructors of the Graphics class are private. The
You are mistaken. Both Graphics and Graphics2D (the actual class you
are most likely to run into) have protected no-arg constructors, at
least in Java 1.4.
> system passes in a Graphics class when it's time to update the screen, and
> you can also create a graphics class through a static factory method
> (Image.getGraphics()). But either way, I can't get in and capture the
> method calls to the resulting Graphics object.
>
> Is there any way at all to do this, or am I SOL? Can anyone think of
> another way to accomplish what I want?
You can subclass either class with an implementation that delegates to a
System-created Graphics instance, with logging wrapped around the method
invocations. I suppose that's what you had in mind to begin with. If
aspect-oriented programming were deeply enough supported by Java then
this would be a perfect case for it, but as it is, you probably couldn't
catch the system's manipulations of a Graphics -- only your own code's.
John Bollinger
jobollin@indiana.edu
- Next message: Christophe Vanfleteren: "Re: Java API for correcting malformed HTML code"
- Previous message: rjweytens: "org.apache.jasper.JasperException: Cannot find bean under name myBean"
- In reply to: Hugh Beyer: "Extending/replacing a class without a public constructor"
- Next in thread: Hugh Beyer: "Re: Extending/replacing a class without a public constructor"
- Reply: Hugh Beyer: "Re: Extending/replacing a class without a public constructor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|