You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Igor Drobiazko <ig...@gmail.com> on 2009/07/25 17:59:09 UTC

Re: Standalone IOC: integrating javassist Translator and using @Inject

ComponentClassTransformWorker is supposed to transform only component (and
page) classes.
The ijection mechanism can be extended in two ways:
- by contributing a org.apache.tapestry5.ioc.ObjectProvider
- by contributing a org.apache.tapestry5.services.InjectionProvider

A InjectionProvider can transform classes but it is a part of tapestry-core.
A ObjectProvider is a part of tapestry-ioc but it can not transform classes.


What if you inject the service
org.apache.tapestry5.ioc.services.ClassFactory in one of your services?


On Sat, Jul 25, 2009 at 5:06 PM, Adriaan Joubert <ad...@gmail.com>wrote:

> Hi,
>
> we have a large application that has a fat client interface as well as
> a tapestry 5 web front end.
>
> Tapestry 5 IOC is marvelous and we would like to use it in our client
> application. Using tapestry standalone turns out to be easy, however I
> have two related issues:
>
> 1. I'd love to use @Inject in our code
> 2. We have our own @Delegate annotation to generate a bunch of
> delegate methods for a field (this is for use with the jgoodies
> binding framework when extending beans with additional functionality)
>
> Currently we have our own classloader that uses javassist to modify
> the classes and I implemented a javassist Translator to do the donkey
> work.
>
> Digging through Tapestry I found
> contributeComponentClassTransformWorker(), so this seems like a good
> mechanism to add a transform to deal with our @Delegate annotation.
> Unfortunately this is the point where I got lost.
>
> I cannot add this into the standalone application IOC AppModule, as it
> uses a bunch of tapestry classes that are not in the IOC package,
> specifically InjectWorker. So do I need to roll my own for use in a
> standalone application?
>
> As far as I can make out these annotations are only processed in
> classes loaded through the IOC registry? As I would like to modify
> classes that are not loaded through the registry I would need to do
> this through the class loader. Sounds as if this could cause problems
> when running with Tapestry?
>
> I'd appreciate any comments or suggestions on how to proceed.
>
> Thanks!
>
> Adriaan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko

Re: Standalone IOC: integrating javassist Translator and using @Inject

Posted by Adriaan Joubert <ad...@gmail.com>.
So, I have been trying a number of approaches with varying success.

Using a service in a standalone implementation and retrieving the
service with a call to getService() on the registry works as expected.
Any @Inject annotations on fields work great.

I have had less joy with the class factory. I've had to move a lot of
calls around to ensure that I never reference the class anywhere
before calling a service that injects the class factory, and ask it to
create the class.

As I understand it, I need to

1. create the class in the class loader with

	ClassFab classFab = classFactory_.newClass(typeName, Object.class);
	<transformations go here>
	classFab.createClass();

2. I can then create the class with new as usual, and will receive an
instance of the modified class.

The first step needs to happen before the class is ever referenced. If
I do this during startup, this may mean creating a bunch of classes in
the class loader that I may never use. And I need to have the
correctly stringified name of every class that I wish to transform.
Not pretty, but probably doable.

My second problem is that I have not been able to find a good example
in the IOC code for calling the class transformations. Is there a
ready-made transformer that will apply all the transformations that
are registered in the AppModule for the project?

Any help or thoughts appreciated.

Cheers,

Adriaan

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


Re: Standalone IOC: integrating javassist Translator and using @Inject

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Sat, 25 Jul 2009 13:53:47 -0300, Adriaan Joubert <ad...@gmail.com>  
escreveu:

> Ah, so I can use the class factory to create objects rather than using
> new? And then the standard @Inject works automatically?

Registry.autobuild(Class clasz) instantiates an object of a given class  
and injects its dependencies. Haven't tested @Inject injection, though,  
only constructor-based injection.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Standalone IOC: integrating javassist Translator and using @Inject

Posted by Adriaan Joubert <ad...@gmail.com>.
Hi Igor,

thanks for your mail!

2009/7/25 Igor Drobiazko <ig...@gmail.com>:
> ComponentClassTransformWorker is supposed to transform only component (and
> page) classes.
> The ijection mechanism can be extended in two ways:
> - by contributing a org.apache.tapestry5.ioc.ObjectProvider
> - by contributing a org.apache.tapestry5.services.InjectionProvider
>
> A InjectionProvider can transform classes but it is a part of tapestry-core.
> A ObjectProvider is a part of tapestry-ioc but it can not transform classes.
>
>
> What if you inject the service
> org.apache.tapestry5.ioc.services.ClassFactory in one of your services?

Ah, so I can use the class factory to create objects rather than using
new? And then the standard @Inject works automatically?  I'll have a
look at this and report back.

Cheers,

Adriaan

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