[jboss-user] [JBoss Seam] - Re: @PersistenceContext in a SFSB created by a factory

Newlukai do-not-reply at jboss.com
Tue Aug 7 08:54:27 EDT 2007


So I have to change the @Factory method to
upDownload = Component.getInstance("upDownload");
? But, the component "upDownload" isn't yet instantiated, so Seam would look up for "upDownload" and since the @Name is missing on UpDownloadDatabase it would just find the @Factory in UpDownloadFactory. I'm sure I've accidentally ignored something but for me it looks like this would be a recursive call, isn't it?

On the other side, when I call Component.getInstance() it isn't possible to switch the implementation via components.xml anymore?!?

A workaround would be sth like this:

@Name("upDownloadFactory")
  | @Scope(ScopeType.APPLICATION)
  | @Startup
  | public class UpDownloadFactory implements Serializable {
  |   private String className;
  |   
  |   @Out(required=false)
  |   private UpDownload upDownload;
  |   
  |   @Factory(value="upDownload", scope=ScopeType.SESSION, autoCreate=true)
  |   public UpDownload getUpDownload() {
  |     if(upDownload == null) {
  |       try {
  |         if(className == null || className.equals("")) {
  |           className = "Database";
  |         }
  |         upDownload = (UpDownload) Component.getInstance("upDownload"+className);
  |         ... and so on ...
  |         }
  | 
  |         return upDownload;
  |     }
  | 
  |   public void setClassName(String className) {
  |     this.className = className;
  |   }
  | }

@Scope(ScopeType.SESSION)
  | @Stateful
  | @Name("upDownloadDatabase")
  | public class UpDownloadDatabase implements UpDownload, Serializable {
  |   @PersistenceContext(unitName = "aresDatabase")
  |   private transient EntityManager em;
  |   
  |   public boolean upload(UpDownloadFileinfo fileInfo) {
  |     ... do the upload with em ...
  |   }
  | 
  |   public List<UpDownloadFileinfo> getAttachedFiles(long testactionID) {
  |     ... show a list of attached files ...
  |   }
  | 
  |   @Remove @Destroy
  |   public void destroy() {
  |   }
  | }


@Scope(ScopeType.SESSION)
  | @Stateful
  | @Name("upDownloadFilesystem")
  | public class UpDownloadFilesystem implements UpDownload, Serializable {
  |   public boolean upload(UpDownloadFileinfo fileInfo) {
  |     ... do the upload with em ...
  |   }
  | 
  |   public List<UpDownloadFileinfo> getAttachedFiles(long testactionID) {
  |     ... show a list of attached files ...
  |   }
  | 
  |   @Remove @Destroy
  |   public void destroy() {
  |   }
  | }

Would that be possible?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071584#4071584

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071584



More information about the jboss-user mailing list