[Yanel-dev] Configuring a resource
Rob Adamson
bobacus at gmail.com
Mon Dec 20 17:02:25 CET 2010
Hi Michael,
On 20 December 2010 14:53, Michael Wechner <michael.wechner at wyona.com> wrote:
> Hi Rob
>
> On 12/20/10 1:32 PM, Rob Adamson wrote:
>>
>> Hi,
>>
>> I want to create an object when Yanel starts up, taking a
>> configuration parameter from a file or JNDI, and then pass that object
>> to two different resources.
>>
>> What are my options for achieving this?
>
> One possibility would be to introduce a custom realm implementation, which
> can be configured
>
> http://www.yanel.org/en/documentation/realm/realm-configuration.html#realm-class
>
> See for example
>
> https://svn.wyona.com/repos/public/yanel/contributions/realms/foaf/src/resources/foaf/src/java/org/wyona/yanel/impl/map/FOAFRealm.java
>
>
> and then cast this realm within your custom resource types.
This looks reasonable.
> Another possibility might be to extend
>
> YANEL_HOME/conf/spring-yanel-config.xml
>
> in the sense that one could have such a config per realm.
> Shouldn't be too hard to extend the Yanel core for this.
This would help with the construction of the object itself. But you
still have to be able to pass objects, or a container / context, into
the resources.
> A third possibility would be to introduce a resource type interface called
> "InitializableV1" which
> would mean if a resource type implements this method, then Yanel core will
> call the corresponding
> methods at startup.
Passing in some kind of context?
>> My goal is to move the object
>> configuration (and hence code dependencies) out of the resource
>> classes.
>
> can you give an example?
public class AssetServiceResource extends Resource ... {
private final QueryFactory queryFactory;
public AssetServiceResource() throws MalformedURLException {
// TODO externalise
this(new SolrSearchService(new
CommonsHttpSolrServer("http://localhost:8080/solr")));
}
public AssetServiceResource(QueryFactory queryFactory) {
this.queryFactory = queryFactory;
}
...
I want to configure a QueryFactory externally, then have it passed in somehow.
I think the custom realm may be a way of doing this, with a lookup
method. So I'll try that.
Thanks,
Rob
More information about the Yanel-development
mailing list