You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Yang Lei <yl...@gmail.com> on 2010/10/21 23:42:47 UTC

How to get classLoader from contribution.

I have a need to get the classLoader resolved from a contribution after
Node.start. I noticed a couple of things when I try to get it to work.

1. It seems NodeImpl has the list of contribution object who contains the
classLoader. So I used the following code to access it.

*for* (org.apache.tuscany.sca.contribution.Contribution item:
((NodeImpl)node).getContributions())

{

...item.getClassLoader();

}

I wonder if if there is a more elegant way to do it. e.g. If I can get the
org.apache.tuscany.sca.contribution.Contribution from the
org.apache.tuscany.sca.node.Contribution,
then I do not need to interate the contirbutions from the NodeImpl, nor I
need to cast the NodeImpl type

2. When I execute the above code, the classLoader retrieved is null. I
noticed there is no code setting classLoader in the contribution. So I
changed ClassLoaderModelResolver constructor to add the following line .

contribution.setClassLoader(*this*);



I would like to know what is the right way for me to get classLoader for a
given contribution which honors the import statement.

-- 
Thanks. Yang.

Re: How to get classLoader from contribution.

Posted by Luciano Resende <lu...@gmail.com>.
On Thu, Oct 21, 2010 at 2:42 PM, Yang Lei <yl...@gmail.com> wrote:
> I have a need to get the classLoader resolved from a contribution after
> Node.start. I noticed a couple of things when I try to get it to work.
>
> 1. It seems NodeImpl has the list of contribution object who contains the
> classLoader. So I used the following code to access it.
>
> for (org.apache.tuscany.sca.contribution.Contribution item:
> ((NodeImpl)node).getContributions())
>
> {
>
> ...item.getClassLoader();
>
> }
>
> I wonder if if there is a more elegant way to do it. e.g. If I can get the
> org.apache.tuscany.sca.contribution.Contribution from the
> org.apache.tuscany.sca.node.Contribution, then I do not need to interate the
> contirbutions from the NodeImpl, nor I need to cast the NodeImpl type
>
> 2. When I execute the above code, the classLoader retrieved is null. I
> noticed there is no code setting classLoader in the contribution. So I
> changed ClassLoaderModelResolver constructor to add the following line .
>
> contribution.setClassLoader(
>
> this);
>
>
>
> I would like to know what is the right way for me to get classLoader for a
> given contribution which honors the import statement.
>
> --
>
> Thanks. Yang.
>

The support for Import/Export is done via a delegation chain trough
the Resolver. Maybe you could accomplish the same trough the
ModelResolver from a given contribution ?


-- 
Luciano Resende
http://people.apache.org/~lresende
http://twitter.com/lresende1975
http://lresende.blogspot.com/