App Engine Python SDK version 1.8.4
[gae.git] / java / src / main / com / google / apphosting / utils / config / EarInfo.java
blobc862412324a1cc6c4ce08b31726e60026094a41a
1 package com.google.apphosting.utils.config;
3 import com.google.common.collect.ImmutableList;
4 import com.google.common.collect.ImmutableMap;
6 import java.io.File;
7 import java.util.List;
8 import java.util.Map;
9 import java.util.logging.Logger;
11 /**
12 * Holder for information from an EAR directory.
15 public class EarInfo {
16 private static final Logger LOGGER = Logger.getLogger(EarInfo.class.getName());
18 private final File earDirectory;
19 private final AppEngineApplicationXml appEngineApplicationXml;
20 private final ApplicationXml applicationXml;
21 private final List<WebModule> webModules;
22 private final Map<String, WebModule> moduleMap;
24 EarInfo(File earDirectory, AppEngineApplicationXml appEngineApplicationXml,
25 ApplicationXml applicationXml, List<WebModule> webModules)
26 throws AppEngineConfigException{
27 this.earDirectory = earDirectory;
28 this.appEngineApplicationXml = appEngineApplicationXml;
29 this.applicationXml = applicationXml;
30 this.webModules = ImmutableList.copyOf(webModules.iterator());
32 ImmutableMap.Builder<String, WebModule> builder = ImmutableMap.builder();
33 for (WebModule webModule : webModules) {
34 builder.put(webModule.getModuleName(), webModule);
36 try {
37 moduleMap = builder.build();
38 } catch (IllegalArgumentException iae) {
39 if (iae.getMessage().startsWith("duplicate key: ")) {
40 String msg = "Invalid EAR - Duplicate module name";
41 LOGGER.info(msg);
42 throw new AppEngineConfigException(msg, iae);
43 } else {
44 throw iae;
49 public File getEarDirectory() {
50 return earDirectory;
53 public ApplicationXml getApplicationXml() {
54 return applicationXml;
57 public AppEngineApplicationXml getAppengineApplicationXml() {
58 return appEngineApplicationXml;
61 public List<WebModule> getWebModules() {
62 return webModules;
65 WebModule getWebModule(String moduleName) {
66 return moduleMap.get(moduleName);
69 @Override
70 public int hashCode() {
71 final int prime = 31;
72 int result = 1;
73 result = prime * result
74 + ((appEngineApplicationXml == null) ? 0 : appEngineApplicationXml.hashCode());
75 result = prime * result + ((applicationXml == null) ? 0 : applicationXml.hashCode());
76 result = prime * result + ((earDirectory == null) ? 0 : earDirectory.hashCode());
77 result = prime * result + ((webModules == null) ? 0 : webModules.hashCode());
78 return result;
81 @Override
82 public boolean equals(Object obj) {
83 if (this == obj) {
84 return true;
86 if (obj == null) {
87 return false;
89 if (getClass() != obj.getClass()) {
90 return false;
92 EarInfo other = (EarInfo) obj;
93 if (appEngineApplicationXml == null) {
94 if (other.appEngineApplicationXml != null) {
95 return false;
97 } else if (!appEngineApplicationXml.equals(other.appEngineApplicationXml)) {
98 return false;
100 if (applicationXml == null) {
101 if (other.applicationXml != null) {
102 return false;
104 } else if (!applicationXml.equals(other.applicationXml)) {
105 return false;
107 if (earDirectory == null) {
108 if (other.earDirectory != null) {
109 return false;
111 } else if (!earDirectory.equals(other.earDirectory)) {
112 return false;
114 if (webModules == null) {
115 if (other.webModules != null) {
116 return false;
118 } else if (!webModules.equals(other.webModules)) {
119 return false;
121 return true;
124 @Override
125 public String toString() {
126 return "EarInfo: earDirectory=" + earDirectory
127 + " appEngineApplicationXml=" + appEngineApplicationXml
128 + " applicationXml=" + applicationXml
129 + " webModules=" + webModules;