Or, just do something like this... <construct class="LegacyCode"> <object>properties:prop1=value1,prop2=value2,prop3=value3</object> </construct>
Essentially, you'd transform your "locator" string (the prop1=value1, etc stuff) into a Properties object using your object provider implementation. -----Original Message----- From: Knut Wannheden [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 25, 2006 6:28 AM To: [email protected] Subject: Re: Injecting java.util.Properties constructor argument type Felix, You could try to implement an object provider for Properties objects. Then you could create your legacy object like this: <construct class="LegacyCode"> <DEFANGED_object>properties:MyProperties</object> </construct> --knut On 4/25/06, Felix Sun <[EMAIL PROTECTED]> wrote: > I have tried to simulate to situation, It seems like the only works in mode > *primitive*, but It works, It may be useful to you. > Is this seems like your Legacy code? and I add exec() method and the > interface for test purpose. > > public class LegacyCode implements Executable{ > private Properties prop; > > public LegacyCode(Properties prop) { > this.prop = prop; > } > > public void exec() { > System.out.println ("This is your properties: " + prop); > > } > } > > write a MyProperties that extends Properties that can get pairs from > configuration-point. > > public class MyProperties extends Properties{ > public void setValues(Map values){ > super.putAll(values); > } > } > > then the hivemind.xml > > <service-point id="LegacyService" interface="Executable"> > <invoke-factory> > <construct class="LegacyCode"> > <DEFANGED_object>service:MyProperties</object> > </construct> > </invoke-factory> > </service-point> > > <service-point id="MyProperties" interface="java.util.Map"> > <invoke-factory model="primitive"> > <construct class="MyProperties"> > <set-configuration property="values" > configuration-id="hivemind.ObjectProviders"/> > </construct> > </invoke-factory> > </service-point> > > though the MyProperties service 's interface is java.util.Map, but I can be > injected to LegacyService by constructor. > because the service mode is *primitive* I think. > > > - Felix Sun > > > On 4/20/06, Eduardo Sherington <[EMAIL PROTECTED]> wrote: > > Hi, > > > > I've just started using Hivemind inside of Tapestry 4.x and I have some > nice > > services defined. I am happy with simple configuration of those services > > using constructor parameter injection and I am happy with services being > > injected with references to other services. > > > > However, I'm really struggling with something that on the face of it is > I'm > > sure blindingly obvious to Hivemind veterans but for a newcomer to the > > project it really isn't obvious at all... > > > > My problem is that I have a legacy class that I have no control over, but > I > > want to use this class as a service. That class has a single constructor > > parameter of type java.util.Properties and this is the ONLY way to set the > > configuration for that class. > > > > What I thought should be easy to do is to define in my hivemind xml > > configuration file some key/attribute values that would get translated to > a > > Properties object and automatically injected for me. > > > > I just have no idea how to do this. > > > > I've been googling for hours, trying to parse the hivemind examples and > test > > cases and to be honest I'm a bit lost! > > > > I know that I could probably wrap that legacy object in one of my own, > > configure my own class and pass the configuration on but I didn't want to > > admit defeat just yet, and I don't really want to duplicate the entire API > > of that legacy object on my own class. > > > > I'd appreciate any pointers or examples anyone could give. > > > > Thanks! > > > > > > > > > --------------------------------------------------------------------- > > 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
