Hi Morten,
On May 12, 2010, at 11:13 PM, Morten wrote:
> I am interested in using extending WadlGeneratorConfig in order
> to customize my Wadl (and maybe specify my JAXBContext - see
> seperate post).
>
> I looked at the examples which all shows how to pass file references
> to a builder in configure(). As per normal Java EE practices, it
> would seem to be a much better practice to use URLs, URI's or
> inputstreams instead as this will work in all kind of deployment
> scenarios unlike Files. The javadoc makes references to using
> inputstreams but the prop() method only accepts strings so I am
> curious about how to use InputStream's instead of files ?
>
If you have a WadlGenerator implementation with a method "setFoo" and
a property of name "foo" and value "bar", for example:
public class MyWadlGeneratorConfig extends WadlGeneratorConfig {
@Override
public List<WadlGeneratorDescription> configure() {
return generator( MyWadlGenerator.class )
.prop( "foo", "bar" )
.descriptions();
}
}
public class MyWadlGenerator {
void setFoo(InputStream in) { ... }
}
The the resource named "bar" will be looked up using
ClassLoader.getResourceAsStream
> Another problem is how to pass parameters into any WadlGenerators
> that I create ? All the configure examples uses xxx.class references
> which jersey instantiate so that I can't pass parameters to the
> constructor. Any examples of how to create my own instances (I tried
> overloading getWadlGenerator() instead of configure() but got some
> nullpointer execeptions if I did so I guess I did not implement it
> correctly). Any examples of creating my own instances of
> WadlGenerators so I can pass relevant information?
>
You can pass in properties to setter methods:
public class MyWadlGeneratorConfig extends WadlGeneratorConfig {
@Override
public List<WadlGeneratorDescription> configure() {
return generator( MyWadlGenerator.class )
.prop( "string", "someString" )
.prop( "b", 1 )
.descriptions();
}
}
public class MyWadlGenerator {
void setString(String s) { ... }
void setInteger(Integer s) { ... }
}
It is not ideal though.
From looking at the code i think there was an intention to allow this
(see the static generator methods on WadlGeneratorConfig) but then it
seems like it was forgotten because the following of
WadlGeneratorConfig requires overriding:
public abstract List<WadlGeneratorDescription> configure();
rather than:
public abstract WadlGenerator configure();
IMHO this whole area needs to be cleaned up. Marc did some work in a
branch on using Java annotations rather than JavaDoc, which i think
improves the ease of use, but Marc is no longer with us so we need to
pick up that work.
Paul.