You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by daveg-iwd <da...@iwd.iowa.gov> on 2016/10/31 19:16:13 UTC
How to pass a custom resource to custom resource factory?
I have a 3rd party library I can potentially define to tomee as a resource
created by a factory class. But the constructor for the resource factory
only takes a specific class. Something like this:
public class Config {
String opt1;
String opt2;
public setOpt1(String s) { opt1 = s; }
public setOpt2(String s) { opt2 = s; }
public String getOpt1() { return opt1; }
public String getOpt2() { return opt2; }
}
public class TheFactory() {
private Config conf;
public TheFactory(Config c) { this.conf = c }
public Object makeObject() { return .... }
}
I figure I'd define the Config in tomee.xml as
<Resource id="aconfig" class-name="Config">
opt1 blah
opt2 derp
</Resource>
The question is if there is a way to tell the resource definition for the
factory that the input to its constructor is the "aconfig" resource?
I thought it might be something like
<Resource id="afactory" class-name="TheFactory"
factory-name="makeObject" constructor="what to put
here?">
config iwdldap
</Resource>
Is this possible or might I have to make my own factory that would use
Properties instead?
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/How-to-pass-a-custom-resource-to-custom-resource-factory-tp4680444.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: How to pass a custom resource to custom resource factory?
Posted by Romain Manni-Bucau <rm...@gmail.com>.
(didnt tested but sharing the idea)
<Resource id="aconfig" class-name="Config">
opt1 blah
opt2 derp
</Resource>
<Resource id="afactory" class-name="TheFactory"
factory-name="makeObject" constructor="config">
config = @aconfig
</Resource>
Think you can use a Service instea dof resource for aconfig and replace the
@ by $ to link it to the service in the factory.
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>
2016-10-31 20:16 GMT+01:00 daveg-iwd <da...@iwd.iowa.gov>:
> I have a 3rd party library I can potentially define to tomee as a resource
> created by a factory class. But the constructor for the resource factory
> only takes a specific class. Something like this:
>
> public class Config {
> String opt1;
> String opt2;
> public setOpt1(String s) { opt1 = s; }
> public setOpt2(String s) { opt2 = s; }
> public String getOpt1() { return opt1; }
> public String getOpt2() { return opt2; }
> }
>
> public class TheFactory() {
> private Config conf;
> public TheFactory(Config c) { this.conf = c }
> public Object makeObject() { return .... }
> }
>
> I figure I'd define the Config in tomee.xml as
>
> <Resource id="aconfig" class-name="Config">
> opt1 blah
> opt2 derp
> </Resource>
>
> The question is if there is a way to tell the resource definition for the
> factory that the input to its constructor is the "aconfig" resource?
>
> I thought it might be something like
>
> <Resource id="afactory" class-name="TheFactory"
> factory-name="makeObject" constructor="what to put
> here?">
> config iwdldap
> </Resource>
>
> Is this possible or might I have to make my own factory that would use
> Properties instead?
>
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/How-to-pass-a-custom-resource-to-custom-
> resource-factory-tp4680444.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>