This might be useful posted to the Wiki.  It's a bit too small to be bundled
up into its own module, and a bit too specific to be part of tapestry-core.

On 9/23/07, Krishna Caldas <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> We've done an ObjectProvider in order to be able to inject JNDI
> resources in our pages.
>
> For that we created a "Naming" annotation like:
>
> ------------------------------
> @Retention(RetentionPolicy.RUNTIME)
> @Target(ElementType.FIELD)
> public @interface Naming {
>          String mappedBy();
> }
> ------------------------------
>
> A "NamingObjectProvider" like:
>
> ------------------------------
> public class NamingObjectProvider implements ObjectProvider  {
>
>         @SuppressWarnings("unchecked")
>         public <T> T provide(Class<T> clazz, AnnotationProvider provider,
>                         ObjectLocator locator) {
>                 Naming annotation = provider.getAnnotation(Naming.class);
>                 if (annotation == null) {
>                         return null;
>                 }
>                 try {
>                         String jndi = annotation.mappedBy();
>                         Context ctx = new InitialContext();
>                         T manager = (T) ctx.lookup(jndi);
>                         return manager;
>                 } catch (NamingException e) {
>                         throw new RuntimeException("Unable to lookup
> resource.", e);
>                 }
>         }
> }
> ------------------------------
>
> On AppModule we contributed the ObjectProvider:
>
> ------------------------------
>         public void contributeMasterObjectProvider(
>                         OrderedConfiguration<ObjectProvider>
> configuration) {
>                 configuration.add("NamingObjectProvider", new
> NamingObjectProvider());
>         }
> ------------------------------
>
> I'm thought about something like this been a good feature of T5.
> The only dependency of NamingProvider  is on javax.naming.
>
> Sorry if I missed some discussion about this.
> Let me know if there is a better way to do that.
>
> Thanks,
> --
> Krishna
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
Howard M. Lewis Ship
Partner and Senior Architect at Feature50

Creator Apache Tapestry and Apache HiveMind

Reply via email to