You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hivemind.apache.org by Olivier Bourgeois <ze...@wanadoo.fr> on 2005/02/14 00:50:32 UTC

Re: Recursive call in AdaptaterRegistry [Solved]

Thanks a lot !

I tried again today, works like a charm.

For the little story, in fact I was trying to do something like this :

<module id="test" version="1.0.0">
    <configuration-point id="HtmlAdapters" 
        schema-id="hivemind.lib.AdapterRegistry"/>

    <contribution configuration-id="HtmlAdapters">
        <adapter class="java.lang.String" 
	object="instance:test..StringAdapter"/>   
       <adapter class="java.lang.Integer"
	object="instance:test.IntegerAdapter"/>  
   </contribution>
   <service-point id="HtmlAdapter" 
        interface="test.IHtmlAdapter">
        <invoke-factory
	service-id="hivemind.lib.AdapterRegistryFactory">
	<construct configuration-id="HtmlAdapters" >
		<service>HtmlAdapter</service>
	</construct>
       </invoke-factory>
  </service-point>
</module>

which cannot work.

I didn't knew I could use object="service: ...." in the contribution
point and put each adapter in a service point. (BTW I found out that a
good sample for adapters is the new Tapestry AssetFactories).
	This is radically changing the whole thing and making the
solution simple but powerfull ;)


Olivier.


Le Sun, 6 Feb 2005 09:30:52 -0500
Howard Lewis Ship <hl...@gmail.com> a écrit:

> On Sun, 6 Feb 2005 10:28:16 +0100, Olivier Bourgeois
> <ze...@wanadoo.fr> wrote:
> > Thanks for the quick answer Howard,
> > 
> >         I tried again to inject the service into itself, but I
> >         stumbled onto
> > two problems again, I solved only the first one :
> > 
> >         - first you were right there was an error in the beginning
> >         of
> > the console that I did not saw. It said that it was impossible to
> > instantiate my adapters.
> 
> There's a "brittle" error handler that will throw a fatal exception at
> the first error, rather  than just logging it.  It may be a good
> practice to start using that.
> 
> I prefer log-and-continue (the default), since I may be able to catch
> and fix multiple errors.
> 
> 
> 
> >         I finally found out that it was because I was missing a
> >         constructor
> > without parameters ( I was using constructor only injection ) in my
> > adapter. I find this a little bit odd since I thought Java was
> > always providing one constrcutor by default even if not explicitly
> > written.
> 
> Java compiler creates a public no-args constructor for you if and only
> if you don't
> define a constructor  yourself.  It's syntactic sugar.
> 
> 
> > 
> >         - second problem now that the adapters are instantiated
> >         again, the
> > service is still not injected in itself. I tried all the ways I am
> > aware of  (adding also getter/setter in my adapter) :
> >                 -
> >                 <construct><service>XmlAdapter</service></construct>
> >                 - <construct service-id-property="">... -
> >                 <construct><set-service
> >                 property=""service-id=""/>...
> > 
> > But none of them is working : I got an "element not allowed here"
> > error in the console. So I had a look at the hivemodule.xml in the
> > hivemind-lib.jar, and for the service-point AdapterRegistryFactory
> > element the schema is as follow:
> > 
> > <parameters-schema>
> >   <element name="construct">
> >         <attribute name="configuration-id"
> >         translator="configuration" required="true">          A
> >         configuration utilizing the
> > hivemind.lib.AdapterRegistry schema, which          defines the
> > classes and matching adapters.        </attribute>
> >      <conversion
> > class="org.apache.hivemind.lib.adapter.AdapterRegistryParameter">
> >     <map attribute="configuration-id" property="contributions"/>
> >     </conversion>
> >   </element>
> > </parameters-schema>
> > 
> > So I suppose that means I can't because the schema definition for
> > AdaptaterRegistry is a subset of BuilderFactory's one.
> > 
> > Or am I missing some other way to do this ?
> > 
> 
> I think you are missing something here.  You have a specific adapter,
> implemented as a service, that needs to  know about the adapter
> registry which it is registered into.
> 
> Therefore, you should inject the adapter registry service into the
> adapter.  So if AR is the service-id,  your service-point shoudl look
> like:
> 
> <service-point id="MyAdaptor" interface="....">
>   <invoke-factory>
>     <construct class="...MyAdaptorImpl".>
>       <set-service property="registry" service-id="AR"/>
>     </construct>
>   </invoke-factory>
> </service-point>
> 
> Or the correct constructor-inject variation thereof.


---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org