On Sun, 6 Feb 2005 10:28:16 +0100, Olivier Bourgeois <[EMAIL PROTECTED]> 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.




> Olivier.
> 
> Le Sat, 5 Feb 2005 15:52:24 -0500
> Howard Lewis Ship <[EMAIL PROTECTED]> a �crit:
> 
> > You should be able to inject a service into itself. It's a proxy that
> > gets injected. Make sure  there weren't any errors in the console.
> >
> >
> > On Sat, 5 Feb 2005 18:35:32 +0100, Olivier Bourgeois
> > <[EMAIL PROTECTED]> wrote:
> > > Hello all,
> > >
> > >         I'm playing with hivemind 1.1-alpha AdapterRegistry and now
> > >         that I got
> > > some simple example working, I'm asking myself a question I can't
> > > find an answer :)
> > >         Is there a way to do- kind of - recursion with the
> > >         AdaptaterRegistry? I
> > > explain myself: suppose I want to create an XmlAdapter service with
> > > this interface :
> > >
> > > public interface XmlAdapter {
> > >         toXml (Object o);
> > > }
> > >
> > > I could define then :
> > >
> > > public class StringAdapter {
> > >         public String toXml (Object o) {
> > >                 String value = (String) o;
> > >                 return value.trim();
> > >         }
> > > }
> > >
> > > This works fine for "converting" a String to XML.
> > > But now suppose I got this object to adapt :
> > >
> > > public class Name {
> > >         private String firstName;
> > >         private String lastName;
> > >         // + getters & setters
> > > }
> > >
> > > A great trick would be to be able to do something like this :
> > >
> > > public class NameAdapter {
> > >         public String toXml (Object o) {
> > >                 Name value = (Name) o;
> > >                 String ret = new String("<Name><FirstName>");
> > >
> > >                 // Here do some trick to get a StringAdapter from
> > >                 the registry
> > >
> > >                 ret.append(stringAdapter.toXml(value.getFirstName()
> > >                 )); ret.append("</FirstName><LastName>");
> > >                 ret.append(stringAdapter.toXml(value.getLastName())
> > >                 ); ret.append("</LastName></Name>");
> > >                 return ret;
> > >         }
> > > }
> > >
> > > Of course I tried to inject the service in
> > > itself but this leads only to nullpointerexception ( well, I
> > > expected something like this anyway...).
> > >
> > > So, is there a way to do this ? Or should I try another way ? ( with
> > > the new Chain service maybe ? )
> > >
> > > thanks in advance for any help/pointers,
> > >
> > > Olivier.
> > >
> > > -------------------------------------------------------------------
> > > -- To unsubscribe, e-mail:
> > > [EMAIL PROTECTED] For additional
> > > commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > Howard M. Lewis Ship
> > Independent J2EE / Open-Source Java Consultant
> > Creator, Jakarta Tapestry
> > Creator, Jakarta HiveMind
> >
> > Professional Tapestry training, mentoring, support
> > and project work.  http://howardlewisship.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to