You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Mike Pestorich <mm...@hotmail.com> on 2006/02/18 03:07:05 UTC

Re: Injecting service into ASO - POSSIBLE SOLUTION

Phillip,

Thank you very much for the tip. I went ahead and more or less did what you 
suggested and it worked giving something very close to what I originally 
intended (or wanted to do).

Even though this worked, I am still very much interested in what John 
suggested in his ealier post. His comments, if followed, certainly would 
provide something more portable and when I have the time I might look into 
doing something something like that.

Thanks again, you were all very helpful. If anyone is interested this is 
what I ended up with:

===web.xml===

<web-app>
...
  <listener>
    
<listener-class>org.objectstyle.cayenne.conf.WebApplicationContextProvider</listener-class>
  </listener>
...
</web-app>

===hivemodule.xml===

<module id="com.pestorich.tapestry" version="1.0.0">

  <service-point id="DataContextService">
    <create-instance class="DataContextServiceImpl" />
    <interceptor service-id="hivemind.LoggingInterceptor" />
  </service-point>

  <service-point id="SessionFactory">
    <invoke-factory>
      <construct class="SessionFactory" />
    </invoke-factory>
    <interceptor service-id="hivemind.LoggingInterceptor" />
  </service-point>

  <contribution configuration-id="tapestry.state.ApplicationObjects">
    <state-object name="Session" scope="session">
      <invoke-factory object="service:SessionFactory" />
    </state-object>
  </contribution>

</module>

===DataContextService.java===

package com.pestorich.tapestry;

import org.objectstyle.cayenne.access.DataContext;

public interface DataContextService {

    public DataContext getDataContext();

}

===DataContextServiceImpl.java===

package com.pestorich.tapestry;

import org.objectstyle.cayenne.access.DataContext;

public class DataContextServiceImpl implements DataContextService {

	public DataContext getDataContext() {
		return DataContext.getThreadDataContext();
	}
}

===Session.java===

package com.pestorich.tapestry;

import java.io.Serializable;
import org.objectstyle.cayenne.access.DataContext;

public class Session implements Serializable {

    private static final long serialVersionUID = 1L;
    private DataContext _dataContext;

    public Session(DataContext dataContext) {
        _dataContext = dataContext;
    }

    public DataContext getDataContext() {
        return _dataContext;
    }
}

===SessionFactory.java===

package com.pestorich.tapestry;

import org.apache.tapestry.engine.state.StateObjectFactory;
import com.pestorich.tapestry.service.DataContextService;

public class SessionFactory implements StateObjectFactory {

    private DataContextService _dataContextService;

    public void setDataContextService(DataContextService dataContextService) 
{
        _dataContextService = dataContextService;
    }

    public Object createStateObject() {
        return new Session(_dataContextService.getDataContext());
    }
}

>From: spamsucks <sp...@rhoderunner.com>
>Reply-To: "Tapestry users" <ta...@jakarta.apache.org>
>To: Tapestry users <ta...@jakarta.apache.org>
>Subject: Re: Injecting service into ASO
>Date: Fri, 17 Feb 2006 07:59:58 -0500
>
>I am not the authority, but I just solved this error myself.
>
>You cannot pass objects directly to tapestry in hivemind.  In brief, have 
>your DataContextService implement 
>org.apache.tapestry.engine.state.StateObjectFactory and return an instance 
>to itself.   There is a page that I got some help on at 
>http://wiki.apache.org/jakarta-tapestry/Tapestry+Spring+SSO+ASO that while 
>not exactly what you need could help out.
>
>HTH
>Phillip



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org