1.9.30 sync.
[gae.git] / java / src / main / com / google / apphosting / utils / config / WebModule.java
blob6e590543f84dc18814167b9dd3d538e1abe4c330
1 package com.google.apphosting.utils.config;
3 import com.google.common.base.CharMatcher;
5 import java.io.File;
7 /**
8 * Holder for information for a web module extracted from the module's
9 * on disk application directory.
12 public class WebModule {
13 /**
14 * Default value for a module name.
16 public static final String DEFAULT_MODULE_NAME = "default";
18 private final File applicationDirectory;
19 private final AppEngineWebXml appEngineWebXml;
20 private final File appEngineWebXmlFile;
21 private final WebXml webXml;
22 private final File webXmlFile;
23 private final String contextRoot;
25 /**
26 * Returns the server name specified in {@link #getAppEngineWebXml()} or
27 * {@link #DEFAULT_SERVER_NAME} if none is specified.
29 public static String getModuleName(AppEngineWebXml appEngineWebXml) {
30 String module = appEngineWebXml.getModule();
31 if (module == null) {
32 module = appEngineWebXml.getService();
34 if (module == null || CharMatcher.WHITESPACE.matchesAllOf(module)){
35 return "default";
36 } else {
37 return module.trim();
41 WebModule(File applicationDirectory, AppEngineWebXml appEngineWebXml, File appEngineWebXmlFile,
42 WebXml webXml, File webXmlFile, String contextRoot) {
43 this.applicationDirectory = applicationDirectory;
44 this.appEngineWebXml = appEngineWebXml;
45 this.appEngineWebXmlFile = appEngineWebXmlFile;
46 this.webXml = webXml;
47 this.webXmlFile = webXmlFile;
48 this.contextRoot = contextRoot;
51 public File getApplicationDirectory() {
52 return applicationDirectory;
55 public AppEngineWebXml getAppEngineWebXml() {
56 return appEngineWebXml;
59 public File getAppEngineWebXmlFile() {
60 return appEngineWebXmlFile;
63 public WebXml getWebXml() {
64 return webXml;
67 public File getWebXmlFile() {
68 return webXmlFile;
71 public String getContextRoot() {
72 return contextRoot;
75 /**
76 * Returns the module name specified in {@link #getAppEngineWebXml()} or
77 * {@link #DEFAULT_MODULE_NAME} if none is specified.
79 public String getModuleName() {
80 return getModuleName(appEngineWebXml);
83 @Override
84 public int hashCode() {
85 final int prime = 31;
86 int result = 1;
87 result = prime * result + ((appEngineWebXml == null) ? 0 : appEngineWebXml.hashCode());
88 result = prime * result + ((appEngineWebXmlFile == null) ? 0 : appEngineWebXmlFile.hashCode());
89 result =
90 prime * result + ((applicationDirectory == null) ? 0 : applicationDirectory.hashCode());
91 result = prime * result + ((contextRoot == null) ? 0 : contextRoot.hashCode());
92 result = prime * result + ((webXml == null) ? 0 : webXml.hashCode());
93 result = prime * result + ((webXmlFile == null) ? 0 : webXmlFile.hashCode());
94 return result;
97 @Override
98 public boolean equals(Object obj) {
99 if (this == obj) {
100 return true;
102 if (obj == null) {
103 return false;
105 if (getClass() != obj.getClass()) {
106 return false;
108 WebModule other = (WebModule) obj;
109 if (appEngineWebXml == null) {
110 if (other.appEngineWebXml != null) {
111 return false;
113 } else if (!appEngineWebXml.equals(other.appEngineWebXml)) {
114 return false;
116 if (appEngineWebXmlFile == null) {
117 if (other.appEngineWebXmlFile != null) {
118 return false;
120 } else if (!appEngineWebXmlFile.equals(other.appEngineWebXmlFile)) {
121 return false;
123 if (applicationDirectory == null) {
124 if (other.applicationDirectory != null) {
125 return false;
127 } else if (!applicationDirectory.equals(other.applicationDirectory)) {
128 return false;
130 if (contextRoot == null) {
131 if (other.contextRoot != null) {
132 return false;
134 } else if (!contextRoot.equals(other.contextRoot)) {
135 return false;
137 if (webXml == null) {
138 if (other.webXml != null) {
139 return false;
141 } else if (!webXml.equals(other.webXml)) {
142 return false;
144 if (webXmlFile == null) {
145 if (other.webXmlFile != null) {
146 return false;
148 } else if (!webXmlFile.equals(other.webXmlFile)) {
149 return false;
151 return true;
154 @Override
155 public String toString() {
156 return "WebModule: applicationDirectory=" + applicationDirectory
157 + " appEngineWebXml=" + appEngineWebXml
158 + " appEngineWebXmlFile=" + appEngineWebXmlFile
159 + " webXml=" + webXml
160 + " webXmlFile=" + webXmlFile
161 + " contextRoot=" + contextRoot;