1 package com
.google
.apphosting
.utils
.config
;
3 import com
.google
.common
.collect
.ImmutableList
;
8 * Parsed configuration from a dispatch.xml file.
10 public class DispatchXml
{
12 private final List
<DispatchEntry
> dispatchEntries
;
14 public static Builder
builder() {
18 private DispatchXml(List
<DispatchEntry
> dispatchEntries
) {
19 this.dispatchEntries
= dispatchEntries
;
23 * Returns the YAML equivalent of this dispatch.xml file.
25 * @return contents of an equivalent {@code dos.yaml} file.
27 public String
toYaml() {
28 StringBuilder builder
= new StringBuilder("dispatch:\n");
29 for (DispatchEntry entry
: dispatchEntries
) {
30 builder
.append("- url: " + yamlQuote(entry
.getUrl()) + "\n");
31 builder
.append(" module: " + entry
.getModule() + "\n");
33 return builder
.toString();
37 * Surrounds the provided string with single quotes, escaping any single
38 * quotes in the string by replacing them with ''.
40 private String
yamlQuote(String str
) {
41 return "'" + str
.replace("'", "''") + "'";
45 public int hashCode() {
48 result
= prime
* result
+ ((dispatchEntries
== null) ?
0 : dispatchEntries
.hashCode());
53 public boolean equals(Object obj
) {
57 if (!(obj
instanceof DispatchXml
)) {
60 DispatchXml other
= (DispatchXml
) obj
;
61 if (dispatchEntries
== null) {
62 if (other
.dispatchEntries
!= null) {
65 } else if (!dispatchEntries
.equals(other
.dispatchEntries
)) {
72 * Builder for a {@link DispatchXml}.
74 public static class Builder
{
75 private final ImmutableList
.Builder
<DispatchEntry
> dispatchEntriesBuilder
=
76 ImmutableList
.builder();
81 public Builder
addDispatchEntry(DispatchEntry entry
) {
83 dispatchEntriesBuilder
.add(entry
);
87 public DispatchXml
build() {
88 return new DispatchXml(dispatchEntriesBuilder
.build());
93 * Describes a single dispatch entry.
95 public static class DispatchEntry
{
97 private final String url
;
98 private final String module
;
100 /** Create an empty blacklist entry. */
101 public DispatchEntry(String url
, String module
) {
103 this.module
= module
;
106 public String
getUrl() {
110 public String
getModule() {
115 public int hashCode() {
116 final int prime
= 31;
118 result
= prime
* result
+ ((module
== null) ?
0 : module
.hashCode());
119 result
= prime
* result
+ ((url
== null) ?
0 : url
.hashCode());
124 public boolean equals(Object obj
) {
128 if (!(obj
instanceof DispatchEntry
)) {
131 DispatchEntry other
= (DispatchEntry
) obj
;
132 if (module
== null) {
133 if (other
.module
!= null) {
136 } else if (!module
.equals(other
.module
)) {
140 if (other
.url
!= null) {
143 } else if (!url
.equals(other
.url
)) {
149 private void validate() {
151 throw new AppEngineConfigException("Invalid url in dispatch.xml - " + url
);
153 if (module
== null) {
154 throw new AppEngineConfigException("Invalid module in dispatch.xml - " + module
);