Hi,

I tend to go for option 2 or to use JNDI, which may help when using a 
Servlet container.
Unless your ServerResources are extremely generic, it's quite likely 
that they're going to have to know what to expect to load from the 
context (or JNDI). One way to make sure changing the attribute names is 
consistent would be to use constant names (and also prefix them with 
your domain name, to avoid clashes, like Java package names).


In addition, if you really want to pass information from the Component 
Context to the Application Context, you could set the Component Context 
to be a class that extends the default Context and overrides 
createChildContext() to let some attributes through.

Option 4 (getters and setters) in Application can work well too, since 
you can get the Application from the ServerResource. You'd have to do a 
type check/cast.


Best wishes,

Bruno.

[email protected] wrote:
> Hi,
> 
> I am new to Restlet and any similar technology and I am wondering about the 
> right approach to share business and data objects (eg. Hibernate) among 
> Restlet Resources.
> 
> After reading the books, docs and older posts in this forum, I know why the 
> Component Context shall not be used to pass information to the Resource 
> Restlets. I have also seen people talking different approaches:
> 
> 1) Create an singleton that provides access to the shared objects. I 
> personally dislike singleton approaches.
> 
> 2) Put the shared objects as attributes to the Application Context. This 
> requires (implicit) conventions about attribute names and casting. And 
> requires going through each Resource Restlet if some of the convention 
> changes.
> 
> 3) Extend the Context with getter methods for shared objects. Objects are 
> stored as variables inside the Context. Resources then cast the Context and 
> call the getter methods.
> 
> 4) Extend the Application with getter methods for shared objects. Objects are 
> stored as variables inside the Application. Resources then cast the 
> Application and call the getter methods.
> 
> 5) Some better approach that I am missing?
> 
> Sorry if the question is quite elementary, but I am not familiar to 
> webservice/restlet development. I will appreciate your advice.
> 
> Thanks,
> Daniel Felix Ferber
> 
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2462248
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2463147

Reply via email to