> -----Ursprüngliche Nachricht----- > Von: Simon Nash [mailto:[email protected]] > Gesendet: Mittwoch, 28. November 2012 16:17 > An: [email protected] > Betreff: Re: Get Contribution at runtime? > > Millies, Sebastian wrote: > > Hello there, > > > > > > > > is there a way to find out the contribution of a class at runtime? > > > > > > > > The reason I ask: > > > > > > > > That way, I could include versions of libraries that differ from the > Tuscany > > > > runtime by NOT putting them in the contribution itself, but in some > > other place > > > > over which I have full control (an “endorsed” directory or some > such). > > > > I would then load them using my own EndorsedLibrariesClassloader at > > > > runtime, after Tuscany has already started up all my components. > > > This seems like an interesting approach. It could perhaps become part > of > Tuscany if you're willing to contribute (no pun intended) the code. > > > > > > > Of course, that new classloader would need access to the current > > contribution > > > > in order to resolve imports etc. > > If the new classloader is just loading external libraries, why does it > need to resolve imports via the contribution? Imports are only > relevant > when you're loading contributions. > > Simon
Of course you're right. The new classloader should look for the external libs, then delegate to the parent (the ContributionClassLoader). I was still thinking of changing the order in which classes are searched (contribution and imports first, parent last), but that's no problem here. The whole idea has a drawback, however: The external libraries are not visible to the contributions, but the other way around. So I could not have appropriately typed references in my contributions, but would have to use reflection, right? Is there not a way to create contributions so that I can explicitly set the classloader? Taking the ContributionClassLoaderTest as a point of departure, I see coding like this: ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); contributionFactory = modelFactories.getFactory(ContributionFactory.class); Contribution contrib = contributionFactory.createContribution(); contrib.setURI( ...) contrib.setLocation( url.toString() ); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); contrib.setClassLoader(new ContributionClassLoader(contrib, classLoader)); I'd need some API that would let me start a composite with contributions constructed like that? I. e. some replacement for the node API SCANode node = SCANodeFactory.newInstance().createSCANode( compositeURI, scaContributions); node.start(); where I could pass in appropriately constructed Contribution instances instead of SCAContributions. Is there already such an API? Otherwise I could go and try write my own. My best bet would be to do the stuff that NodeImpl() does before it calls configureNode() outside of NodeImpl, and add a new constructor to NodeImpl to accept Contribution arrays. Any better advice? -- Sebastian IDS Scheer Consulting GmbH Geschäftsführer/Managing Directors: Michael Rehm, Ivo Totev Sitz/Registered office: Altenkesseler Straße 17, 66115 Saarbrücken, Germany - Registergericht/Commercial register: Saarbrücken HRB 19681 http://www.ids-scheer-consulting.com
