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].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.