+ def parsePriceLists(pricelists: YAMLListNode,
+ resources: List[DSLResource],
+ results: List[DSLPriceList]): List[DSLPriceList] = {
+ pricelists.head match {
+ case YAMLEmptyNode => return List()
+ case _ =>
+ }
+
+ val superName = pricelists.head / Vocabulary.overrides
+ val tmpl = superName match {
+ case y: YAMLStringNode =>
+ results.find(p => p.name.equals(y.string)) match {
+ case Some(x) => x
+ case None => throw new DSLParseException(
+ "Cannot find super pricelist %s".format(superName))
+ }
+ case YAMLEmptyNode => emptyPriceList
+ case _ => throw new DSLParseException(
+ "Super pricelist name %s not a string".format())
+ }
+
+ val pl = constructPriceList(pricelists.head.asInstanceOf[YAMLMapNode],
+ tmpl, resources)
+
+ val tmpresults = results ++ List(pl)
+ List(pl) ++ parsePriceLists(pricelists.tail, resources, tmpresults)
+ }
+
+ def constructPriceList(pl: YAMLMapNode, tmpl: DSLPriceList,
+ resources: List[DSLResource]): DSLPriceList = {
+ val name = pl / Vocabulary.name match {
+ case x: YAMLStringNode => x.string
+ case YAMLEmptyNode => throw new DSLParseException("Policy does not have a name")
+ }
+
+ val overr = pl / Vocabulary.overrides match {
+ case x: YAMLStringNode => Some(x.string)
+ case YAMLEmptyNode => None
+ }
+
+ val prices = resources.map {
+ r =>
+ val algo = pl / r.name match {
+ case x: YAMLStringNode => x.string
+ case y: YAMLIntNode => y.int.toString
+ case z: YAMLDoubleNode => z.double.toString
+ case YAMLEmptyNode => tmpl.equals(emptyPolicy) match {
+ case false => tmpl.prices.getOrElse(r,
+ throw new DSLParseException(("Severe! Superpolicy does not " +
+ "specify an algorithm for resource:%s").format(r.name)))
+ case true => throw new DSLParseException(("Cannot find " +
+ "calculation algorithm for resource %s in either policy %s or a" +
+ " superpolicy").format(r.name, name))
+ }
+ }
+ Map(r -> algo)
+ }.foldLeft(Map[DSLResource, Any]())((x, y) => x ++ y)
+
+ val timeframe = pl / Vocabulary.effective match {
+ case x: YAMLMapNode => parseTimeFrame(x)
+ case YAMLEmptyNode => tmpl.equals(emptyPolicy) match {
+ case false => tmpl.effective
+ case true => throw new DSLParseException(("Cannot find effectivity " +
+ "period for policy %s ").format(name))
+ }
+ }
+ DSLPriceList(name, overr, Map(), timeframe)
+ }
+