PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/scalate-guice/src/main/scala/org/fusesource/scalate/guice/RichBuilder.scala

http://github.com/scalate/scalate
Scala | 60 lines | 25 code | 13 blank | 22 comment | 0 complexity | 09e15c15696f525db613ded5713d545a MD5 | raw file
 1/**
 2 * Copyright (C) 2009-2011 the original author or authors.
 3 * See the notice.md file distributed with this work for additional
 4 * information regarding copyright ownership.
 5 *
 6 * Licensed under the Apache License, Version 2.0 (the "License");
 7 * you may not use this file except in compliance with the License.
 8 * You may obtain a copy of the License at
 9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18package org.fusesource.scalate.guice
19
20import _root_.com.google.inject.Key
21import _root_.com.google.inject.servlet.ServletModule
22import _root_.javax.servlet.http.HttpServlet
23
24/**
25 * This helper class provides a workaround for using 'with' in the Guice Servlet DSL
26 *
27 * @version $Revision : 1.1 $
28 */
29
30class RichBuilder(builder: ServletModule.ServletKeyBindingBuilder) {
31
32  def by[T <: HttpServlet](servletKey: Class[T]): Unit = { builder.`with`(servletKey) }
33
34  def by[T <: HttpServlet](
35    servletKey: Class[T], params: java.util.Map[String, String]): Unit = { builder.`with`(servletKey, params) }
36
37  def by[T <: HttpServlet](servletKey: Key[T]): Unit = { builder.`with`(servletKey) }
38
39  def by[T <: HttpServlet, S](
40    servletKey: Key[T],
41    params: java.util.Map[String, String]): Unit = { builder.`with`(servletKey, params) }
42
43  def withClass[T <: HttpServlet](servletKey: Class[T]): Unit = {
44    builder.`with`(servletKey)
45  }
46
47  def withClass[T <: HttpServlet](
48    servletKey: Class[T],
49    params: java.util.Map[String, String]): Unit = { builder.`with`(servletKey, params) }
50
51  def withClass[T <: HttpServlet](servletKey: Key[T]): Unit = {
52    builder.`with`(servletKey)
53  }
54
55  def withClass[T <: HttpServlet](
56    servletKey: Key[T],
57    params: java.util.Map[String, String]): Unit = { builder.`with`(servletKey, params) }
58
59}
60