1 // Copyright 2010 Google Inc. All Rights Reserved.
3 package com
.google
.apphosting
.utils
.config
;
6 import java
.io
.FileReader
;
7 import java
.io
.FileNotFoundException
;
9 import java
.io
.StringReader
;
10 import java
.util
.List
;
11 import net
.sourceforge
.yamlbeans
.YamlException
;
12 import net
.sourceforge
.yamlbeans
.YamlReader
;
15 * Class to parse queue.yaml into a QueueXml object.
18 public class CronYamlReader
{
21 * Wrapper around CronXml to make the JavaBeans properties match the YAML file syntax.
23 public static class CronYaml
{
24 private List
<CronXml
.Entry
> entries
;
26 public List
<CronXml
.Entry
> getCron() {
30 public void setCron(List
<CronXml
.Entry
> entries
) {
31 this.entries
= entries
;
34 public CronXml
toXml() {
35 CronXml xml
= new CronXml();
36 if (entries
!= null) {
37 for (CronXml
.Entry entry
: entries
) {
45 private static final String FILENAME
= "cron.yaml";
46 private String appDir
;
48 public CronYamlReader(String appDir
) {
49 if (appDir
.length() > 0 && appDir
.charAt(appDir
.length() - 1) != File
.separatorChar
) {
50 appDir
+= File
.separatorChar
;
55 public String
getFilename() {
56 return appDir
+ CronYamlReader
.FILENAME
;
59 public CronXml
parse() {
60 if (new File(getFilename()).exists()) {
62 return parse(new FileReader(getFilename()));
63 } catch (FileNotFoundException ex
) {
64 throw new AppEngineConfigException("Cannot find file " + getFilename(), ex
);
70 public static CronXml
parse(Reader yaml
) {
71 YamlReader reader
= new YamlReader(yaml
);
72 reader
.getConfig().setPropertyElementType(CronYaml
.class,
76 CronYaml cronYaml
= reader
.read(CronYaml
.class);
77 if (cronYaml
== null) {
78 throw new AppEngineConfigException("Empty cron configuration.");
80 return cronYaml
.toXml();
81 } catch (YamlException ex
) {
82 throw new AppEngineConfigException(ex
.getMessage(), ex
);
86 public static CronXml
parse(String yaml
) {
87 return parse(new StringReader(yaml
));