PageRenderTime 28ms CodeModel.GetById 19ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/scala/couch/db/Document.scala

http://scouchdb.googlecode.com/
Scala | 43 lines | 34 code | 9 blank | 0 comment | 8 complexity | d48392dff7ba1bb2d1824ad3113b7111 MD5 | raw file
 1package couch.db
 2
 3import couch.json._ 
 4import scala.reflect._
 5
 6object DesignDocument {
 7  val PREFIX = "_design/"
 8  
 9  def extendId(id: String) = 
10    if (id == null || id.length == 0)
11      throw new IllegalArgumentException("invalid id entered:" + id)
12    else PREFIX + id
13}
14
15@BeanInfo
16case class DesignDocument(var _id: String, 
17                          
18                          @JSONProperty("") {val ignoreIfNull = true, val ignore = false } 
19                          _rev: String, 
20                          
21                          @OptionTypeHint(classOf[Map[_,_]])
22                          @JSONTypeHint(classOf[View])
23                          views: Map[String, View]) {
24  if (_id != null) 
25    if (!_id.startsWith(DesignDocument.PREFIX))
26      _id = DesignDocument.extendId(_id)
27  
28  var language = "javascript"
29  
30  private [db] def this() = this(null, null, Map[String, View]())
31  
32  override def toString = {
33    "_id = " + _id + " _rev = " + _rev + " language = " + language + " " + 
34      (views match {
35        case null => ""
36        case v => {
37          v.map(e => 
38            (e._1.toString + ":" + e._2.toString)).mkString(",")
39        }
40      }
41    )
42  }
43}