Thanks, I think I misunderstood the usage of FactoryModuleBuilder. In terms of this case, I want to inject the some xml document instances in Singleton scope. I tried to use a common provider, But the provider doesn't accept any parameter.
On Jan 27, 7:43 am, Fred Faber <[email protected]> wrote: > Hello, > > You really don't need a FactoryModuleBuilder here; you have an interface > and an implementing class. > > Simply bind the implementation to the interface: > bind(XMLDocumentFactory.class).to(XMLDocumentFactoryImpl.class); > > -Fred > > On Tue, Jan 25, 2011 at 11:08 PM, Michael <[email protected]> wrote: > > Hi, > > > I want to get some different XML document instances from the injector > > according to the parameter(file name). > > > Curretnly I am looking the API of FactoryModuleBuilder, And trying to > > use @Assisted annotation to do this. But it failed. > > > Bellowed are the codes: > > > -----------------------Factory Class------------------------- > > > @ImplementedBy(XMLDocumentFactoryImpl.class) > > public interface XMLDocumentFactory { > > > org.jdom.Document getDocument(@Assisted String fileName); > > } > > > -----------------------Implemented Factory class------------- > > > public class XMLDocumentFactoryImpl implements XMLDocumentFactory{ > > > org.jdom.Document getDocument(@Assisted String fileName){ > > Document doc = null; > > try{ > > ... > > doc = SAXBuilder.build(fileName); > > ... > > }Catch(Exception e){ > > ... > > } > > > return doc; > > } > > } > > > -----------------------Module class-------------------------- > > > install(new PropertyModule()); > > install(new FactoryModuleBuilder().build(XMLDocumentFactory.class)); > > > -----------------------Action Class-------------------------- > > > public class SomeAction{ > > @Inject @Named("xml.user") private String fileName; > > @Inject private XMLDocumentFactory factory; > > > public String execute() throws Exception{ > > org.jdom.Document t = factory.getDocument(this.fileName); > > } > > } > > > I could not enter the getDocument method of implemented factory class, > > Then got exception. > > Can anyone show me the correct way of doing this please? Many thanks! > > > -- > > You received this message because you are subscribed to the Google Groups > > "google-guice" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<google-guice%[email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
