Permalink
Browse files

Merge branch 'irc_wip_290' of github.com:lift/framework into irc_wip_290

  • Loading branch information...
2 parents 77ce071 + 95bbf60 commit 6530d0a9981c1db9605a6b5e3188868d30d65c76 @nafg nafg committed May 17, 2011
Showing with 1,869 additions and 1,065 deletions.
  1. +14 −6 core/actor/src/main/scala/net/liftweb/actor/LAPinger.scala
  2. +7 −5 core/json-ext/src/test/scala/net/liftweb/json/ext/JsonBoxSerializerSpec.scala
  3. +1 −0 core/json/README.md
  4. +22 −13 core/json/src/main/scala/net/liftweb/json/Extraction.scala
  5. +95 −54 core/json/src/main/scala/net/liftweb/json/Meta.scala
  6. +104 −0 core/json/src/main/scala/net/liftweb/json/ScalaSig.scala
  7. +12 −0 core/json/src/test/scala/net/liftweb/json/ExtractionExamplesSpec.scala
  8. +10 −2 core/json/src/test/scala/net/liftweb/json/SerializationExamples.scala
  9. +2 −2 core/json/src/test/scala/net/liftweb/json/XmlBugs.scala
  10. +1 −1 core/json/src/test/scala/net/liftweb/json/XmlExamples.scala
  11. +80 −0 core/util/src/main/scala/net/liftweb/util/BasicTypesHelpers.scala
  12. +1 −57 core/util/src/main/scala/net/liftweb/util/BindHelpers.scala
  13. +1 −0 core/util/src/main/scala/net/liftweb/util/Schedule.scala
  14. +19 −15 core/util/src/main/scala/net/liftweb/util/SoftReferenceCache.scala
  15. +8 −0 core/util/src/test/scala/net/liftweb/util/BindHelpersSpec.scala
  16. +1 −1 liftsh
  17. +1 −1 liftsh.cmd
  18. +133 −96 persistence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/CustomSerializersSpec.scala
  19. +16 −10 persistence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/MongoFieldSpec.scala
  20. +12 −2 persistence/mongodb/src/main/scala/net/liftweb/mongodb/Mongo.scala
  21. +55 −9 persistence/mongodb/src/test/scala/net/liftweb/mongodb/MongoSpec.scala
  22. +1 −1 persistence/proto/src/main/scala/net/liftweb/proto/ProtoRules.scala
  23. +111 −13 persistence/proto/src/main/scala/net/liftweb/proto/ProtoUser.scala
  24. +25 −7 persistence/record/src/main/scala/net/liftweb/record/MetaRecord.scala
  25. +24 −19 persistence/record/src/test/scala/net/liftweb/record/FieldSpec.scala
  26. +2 −2 project/build.properties
  27. +15 −15 project/build/LiftFrameworkProject.scala
  28. +1 −1 project/plugins/Plugins.scala
  29. BIN project/{sbt-launch-0.7.5.jar → sbt-launch-0.7.7.jar}
  30. +118 −81 web/webkit/src/main/scala/net/liftweb/http/LiftRules.scala
  31. +516 −352 web/webkit/src/main/scala/net/liftweb/http/LiftScreen.scala
  32. +203 −181 web/webkit/src/main/scala/net/liftweb/http/LiftServlet.scala
  33. +130 −47 web/webkit/src/main/scala/net/liftweb/http/Vars.scala
  34. +128 −72 web/wizard/src/main/scala/net/liftweb/wizard/Wizard.scala
@@ -25,19 +25,23 @@ import java.util.concurrent._
*/
object LAPinger {
- /** The underlying <code>java.util.concurrent.ScheduledExecutor</code> */
+ /**The underlying <code>java.util.concurrent.ScheduledExecutor</code> */
private var service = Executors.newSingleThreadScheduledExecutor(TF)
/**
* Re-create the underlying <code>SingleThreadScheduledExecutor</code>
*/
- def restart: Unit = synchronized { if ((service eq null) || service.isShutdown)
- service = Executors.newSingleThreadScheduledExecutor(TF) }
+ def restart: Unit = synchronized {
+ if ((service eq null) || service.isShutdown)
+ service = Executors.newSingleThreadScheduledExecutor(TF)
+ }
/**
* Shut down the underlying <code>SingleThreadScheduledExecutor</code>
*/
- def shutdown: Unit = synchronized { service.shutdown }
+ def shutdown: Unit = synchronized {
+ service.shutdown
+ }
/**
* Schedules the sending of a message to occur after the specified delay.
@@ -47,7 +51,9 @@ object LAPinger {
*/
def schedule[T](to: SpecializedLiftActor[T], msg: T, delay: Long): ScheduledFuture[Unit] = {
val r = new Callable[Unit] {
- def call: Unit = { to ! msg }
+ def call: Unit = {
+ to ! msg
+ }
}
try {
service.schedule(r, delay, TimeUnit.MILLISECONDS)
@@ -65,10 +71,12 @@ case class PingerException(msg: String, e: Throwable) extends RuntimeException(m
private object TF extends ThreadFactory {
val threadFactory = Executors.defaultThreadFactory()
- def newThread(r: Runnable) : Thread = {
+
+ def newThread(r: Runnable): Thread = {
val d: Thread = threadFactory.newThread(r)
d setName "ActorPinger"
d setDaemon true
+ d setContextClassLoader null
d
}
}
@@ -35,19 +35,21 @@ object JsonBoxSerializerSpec extends Specification("JsonBoxSerializer Specificat
parse("""{"name":"joe"}""").extract[Person] mustEqual Person("joe", Empty, Empty)
}
- "Extract boxed age" in {
- parse("""{"name":"joe", "age":12}""").extract[Person] mustEqual Person("joe", Full(12), Empty)
+ "Extract boxed thing" in {
+ parse("""{"name":"joe", "thing": "rog", "age":12}""").extract[Person] mustEqual Person("joe", Full(12), Empty, Full("rog"))
}
+
+
"Extract boxed mother" in {
val json = """{"name":"joe", "age":12, "mother": {"name":"ann", "age":53}}"""
val p = parse(json).extract[Person]
p mustEqual Person("joe", Full(12), Full(Person("ann", Full(53), Empty)))
- (for { a1 <- p.age; m <-p.mother; a2 <- m.age } yield a1+a2) mustEqual Full(65)
+ (for { a1 <- p.age; m <-p.mother; a2 <- m.age } yield a1+a2) mustEqual Some(65)
}
"Render with age" in {
- swrite(Person("joe", Full(12), Empty)) mustEqual """{"name":"joe","age":12,"mother":null}"""
+ swrite(Person("joe", Full(12), Empty)) mustEqual """{"name":"joe","age":12,"mother":null,"thing":null}"""
}
"Serialize failure" in {
@@ -68,5 +70,5 @@ object JsonBoxSerializerSpec extends Specification("JsonBoxSerializer Specificat
case class SomeException(msg: String) extends Exception
-case class Person(name: String, age: Box[Int], mother: Box[Person])
+case class Person(name: String, age: Option[Int], mother: Box[Person], thing: Box[String] = Empty)
View
@@ -61,6 +61,7 @@ Download following jars:
* http://scala-tools.org/repo-releases/net/liftweb/lift-json/XXX/lift-json-XXX.jar
* http://mirrors.ibiblio.org/pub/mirrors/maven2/com/thoughtworks/paranamer/paranamer/2.1/paranamer-2.1.jar
+* scalap (Only for Scala-2.9 compatible versions)
Extras
------
@@ -34,13 +34,17 @@ object Extraction {
* @see net.liftweb.json.JsonAST.JValue#extract
* @throws MappingException is thrown if extraction fails
*/
- def extract[A](json: JValue)(implicit formats: Formats, mf: Manifest[A]): A =
+ def extract[A](json: JValue)(implicit formats: Formats, mf: Manifest[A]): A = {
+ def allTypes(mf: Manifest[_]): List[Class[_]] = mf.erasure :: (mf.typeArguments flatMap allTypes)
+
try {
- extract0(json, mf.erasure, mf.typeArguments.map(_.erasure)).asInstanceOf[A]
+ val types = allTypes(mf)
+ extract0(json, types.head, types.tail).asInstanceOf[A]
} catch {
case e: MappingException => throw e
case e: Exception => throw new MappingException("unknown error", e)
}
+ }
/** Extract a case class from JSON.
* @see net.liftweb.json.JsonAST.JValue#extract
@@ -79,7 +83,7 @@ object Extraction {
case x: Option[_] => x.flatMap[JValue] { y => Some(decompose(y)) }.getOrElse(JNothing)
case x =>
val constructorArgs = primaryConstructorArgs(x.getClass)
- constructorArgs.collect { case (name, _, _) if Reflection.hasDeclaredField(x.getClass, name) =>
+ constructorArgs.collect { case (name, _) if Reflection.hasDeclaredField(x.getClass, name) =>
val f = x.getClass.getDeclaredField(name)
f.setAccessible(true)
JField(unmangleName(name), decompose(f get x))
@@ -179,13 +183,14 @@ object Extraction {
private def extract0(json: JValue, clazz: Class[_], typeArgs: Seq[Class[_]])
(implicit formats: Formats): Any = {
- val mapping =
- if (clazz == classOf[List[_]] || clazz == classOf[Set[_]] || clazz.isArray)
- Col(clazz, mappingOf(typeArgs(0)))
- else if (clazz == classOf[Map[_, _]])
- Dict(mappingOf(typeArgs(1)))
+ def mkMapping(clazz: Class[_], typeArgs: Seq[Class[_]])(implicit formats: Formats): Meta.Mapping = {
+ if (clazz == classOf[List[_]] || clazz == classOf[Set[_]] || clazz.isArray)
+ Col(clazz, mkMapping(typeArgs.head, typeArgs.tail))
+ else if (clazz == classOf[Map[_, _]])
+ Dict(mkMapping(typeArgs.tail.head, typeArgs.tail.tail))
else mappingOf(clazz, typeArgs)
- extract0(json, mapping)
+ }
+ extract0(json, mkMapping(clazz, typeArgs))
}
def extract(json: JValue, target: TypeInfo)(implicit formats: Formats): Any =
@@ -210,7 +215,7 @@ object Extraction {
case o: JObject =>
formats.fieldSerializer(a.getClass).map { serializer =>
val constructorArgNames =
- Reflection.constructorArgs(constructor, formats.parameterNameReader).map(_._1).toSet
+ Reflection.constructorArgs(a.getClass, constructor, formats.parameterNameReader, None).map(_._1).toSet
val jsonFields = o.obj.map { f =>
val JField(n, v) = (serializer.deserializer orElse Map(f -> f))(f)
(n, (n, v))
@@ -222,7 +227,11 @@ object Extraction {
fieldsToSet.foreach { case (name, typeInfo) =>
jsonFields.get(name).foreach { case (n, v) =>
val typeArgs = typeInfo.parameterizedType
- .map(_.getActualTypeArguments.map(_.asInstanceOf[Class[_]]).toList)
+ .map(_.getActualTypeArguments.map(_.asInstanceOf[Class[_]]).toList.zipWithIndex
+ .map { case (t, idx) =>
+ if (t == classOf[java.lang.Object]) ScalaSigReader.readField(name, a.getClass, idx)
+ else t
+ })
val value = extract0(v, typeInfo.clazz, typeArgs.getOrElse(Nil))
Reflection.setField(a, n, value)
}
@@ -322,8 +331,8 @@ object Extraction {
if (x == null) None else Some(x)
} else x
} catch {
- case MappingException(msg, _) =>
- if (optional) None else fail("No usable value for " + path + "\n" + msg)
+ case e @ MappingException(msg, _) =>
+ if (optional) None else fail("No usable value for " + path + "\n" + msg, e)
}
}
Oops, something went wrong.

0 comments on commit 6530d0a

Please sign in to comment.