You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Krishna Caldas <kr...@dextra.com.br> on 2007/09/24 01:50:23 UTC

T5: Inject JNDI resources

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: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: T5: Inject JNDI resources

Posted by Massimo Lusetti <ml...@gmail.com>.
On 9/25/07, Howard Lewis Ship <hl...@gmail.com> wrote:

> Here's the deal: every bit of code that goes into Tapestry ends up being my
> responsibility (or one of the other committers). That means maintenance,
> documentation, etc.  With our plates as full as they already are, I'm trying
> to avoid any extra.

Perfectly reasonable but couldn't the contrib repos be made 'not
officially supported' so to not put to much pressure on devs?

> I'm looking to set up an alternate development location for Tapestry that
> will have its own SVN, and JIRA.  Don't try to keep me to a schedule :-).

That's nice and a good alternative if the import in a contrib module
not officially supported isn't a viable path for apache policies.

-- 
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: T5: Inject JNDI resources

Posted by Howard Lewis Ship <hl...@gmail.com>.
Here's the deal: every bit of code that goes into Tapestry ends up being my
responsibility (or one of the other committers). That means maintenance,
documentation, etc.  With our plates as full as they already are, I'm trying
to avoid any extra.

I'm looking to set up an alternate development location for Tapestry that
will have its own SVN, and JIRA.  Don't try to keep me to a schedule :-).

On 9/25/07, Massimo Lusetti <ml...@gmail.com> wrote:
>
> On 9/25/07, Howard Lewis Ship <hl...@gmail.com> wrote:
>
> > 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.
>
> This is perfect for a contrib module (or sub-modules) and since
> Tapestry is a top level project this should bestraight forward.
>
> In the wiki there's a lot of nice features which could live very well
> in such a module, don't you think so?
>
> --
> Massimo
> http://meridio.blogspot.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>


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

Creator Apache Tapestry and Apache HiveMind

Re: T5: Inject JNDI resources

Posted by Massimo Lusetti <ml...@gmail.com>.
On 9/25/07, Howard Lewis Ship <hl...@gmail.com> wrote:

> 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.

This is perfect for a contrib module (or sub-modules) and since
Tapestry is a top level project this should bestraight forward.

In the wiki there's a lot of nice features which could live very well
in such a module, don't you think so?

-- 
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: T5: Inject JNDI resources

Posted by Howard Lewis Ship <hl...@gmail.com>.
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 <kr...@gmail.com> 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: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>


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

Creator Apache Tapestry and Apache HiveMind

T5: Inject JNDI resources

Posted by Krishna Caldas <kr...@gmail.com>.
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: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org