For the record, here's my ugly-ass workaround, depending upon the fact
that cleanupFunc is called to obtain the cleanup function at the same
time that the default value is set.

import javax.naming.InitialContext
import net.liftweb.util.{Can,Full,Log}
import net.liftweb.http.RequestVar

object JNDIResource {
  val context = new InitialContext()
}

import JNDIResource._

abstract class JNDIResource[T](val name: String) extends
RequestVar[T](context.lookup(name).asInstanceOf[T]) {

  // This is way too dependent upon an implementation detail of the superclass.
  override def cleanupFunc : Can[() => Unit] = {
    Log.debug("Initializing JNDI resource " + name + "(" + this.is + ")")
    initialize(this.is) //this will result in a recursive call, but
the the order of operations is such that it will take the other
branch.

    Full(() => {
        Log.debug("Releasing JNDI resource " + name + "(" + this.is + ")")
        dispose(this.is)
      })
  }

  /**
   * Subclasses should override this method to provide initialization
of the resource
   */
  protected def initialize(resource : T) {
  }

  /**
   * Subclasses should override this method to provide cleanup on the resource
   */
  protected def dispose(resource: T) {
  }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to