1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.geronimo.j2ee.deployment; 18 19 import java.util.jar.JarFile; 20 import java.util.Map; 21 import java.util.HashMap; 22 import java.net.URI; 23 24 import org.apache.xmlbeans.XmlObject; 25 import org.apache.geronimo.kernel.config.ConfigurationModuleType; 26 import org.apache.geronimo.kernel.repository.Environment; 27 import org.apache.geronimo.kernel.repository.Artifact; 28 import org.apache.geronimo.deployment.util.DeploymentUtil; 29 import org.apache.geronimo.gbean.AbstractName; 30 import org.apache.geronimo.j2ee.deployment.annotation.AnnotatedApp; 31 import org.apache.xbean.finder.ClassFinder; 32 33 /** 34 * @version $Rev: 538730 $ $Date: 2007-05-16 14:07:51 -0700 (Wed, 16 May 2007) $ 35 */ 36 public abstract class Module { 37 private final boolean standAlone; 38 39 private final AbstractName moduleName; 40 private final String name; 41 private final Environment environment; 42 private final URI moduleURI; 43 private final JarFile moduleFile; 44 private final String targetPath; 45 private final URI targetPathURI; 46 private final XmlObject vendorDD; 47 private final String namespace; 48 49 private EARContext earContext; 50 private EARContext rootEarContext; 51 private XmlObject specDD; 52 private String originalSpecDD; 53 private AnnotatedApp annotatedApp; 54 private ClassFinder classFinder; 55 56 protected final Map sharedContext = new HashMap(); 57 58 protected Module(boolean standAlone, AbstractName moduleName, Environment environment, JarFile moduleFile, String targetPath, XmlObject specDD, XmlObject vendorDD, String originalSpecDD, String namespace, AnnotatedApp annotatedApp) { 59 assert targetPath != null: "targetPath is null"; 60 assert moduleName != null: "moduleName is null"; 61 62 this.standAlone = standAlone; 63 this.moduleName = moduleName; 64 this.environment = environment; 65 this.moduleFile = moduleFile; 66 this.targetPath = targetPath; 67 this.specDD = specDD; 68 this.vendorDD = vendorDD; 69 this.originalSpecDD = originalSpecDD; 70 this.namespace = namespace; 71 72 if (standAlone) { 73 name = environment.getConfigId().toString(); 74 moduleURI = URI.create(""); 75 } else { 76 name = targetPath; 77 moduleURI = URI.create(targetPath); 78 } 79 80 targetPathURI = URI.create(targetPath + "/"); 81 this.annotatedApp = annotatedApp; 82 } 83 84 public abstract ConfigurationModuleType getType(); 85 86 public String getName() { 87 return name; 88 } 89 90 public boolean isStandAlone() { 91 return standAlone; 92 } 93 94 public AbstractName getModuleName() { 95 return moduleName; 96 } 97 98 public Environment getEnvironment() { 99 return environment; 100 } 101 102 public URI getModuleURI() { 103 return moduleURI; 104 } 105 106 public JarFile getModuleFile() { 107 return moduleFile; 108 } 109 110 public String getTargetPath() { 111 return targetPath; 112 } 113 114 public URI getTargetPathURI() { 115 return targetPathURI; 116 } 117 118 public XmlObject getSpecDD() { 119 return specDD; 120 } 121 122 public XmlObject getVendorDD() { 123 return vendorDD; 124 } 125 126 public String getOriginalSpecDD() { 127 return originalSpecDD; 128 } 129 130 public String getNamespace() { 131 return namespace; 132 } 133 134 public int hashCode() { 135 return name.hashCode(); 136 } 137 138 public boolean equals(Object obj) { 139 if (obj == this) { 140 return true; 141 } 142 if (obj instanceof Module) { 143 Module module = (Module) obj; 144 return name.equals(module.name); 145 } 146 return false; 147 } 148 149 public void close() { 150 DeploymentUtil.close(moduleFile); 151 } 152 153 154 public EARContext getEarContext() { 155 return earContext; 156 } 157 158 public void setEarContext(EARContext earContext) { 159 this.earContext = earContext; 160 } 161 162 public EARContext getRootEarContext() { 163 return rootEarContext; 164 } 165 166 public void setRootEarContext(EARContext rootEarContext) { 167 this.rootEarContext = rootEarContext; 168 } 169 170 public Map getSharedContext() { 171 return sharedContext; 172 } 173 174 public void setSpecDD(XmlObject specDD) { 175 this.specDD = specDD; 176 } 177 178 public void setOriginalSpecDD(String originalSpecDD) { 179 this.originalSpecDD = originalSpecDD; 180 } 181 182 public AnnotatedApp getAnnotatedApp() { 183 return annotatedApp; 184 } 185 186 public void setAnnotatedApp(AnnotatedApp annotatedApp) { 187 this.annotatedApp = annotatedApp; 188 } 189 190 public ClassFinder getClassFinder() { 191 return classFinder; 192 } 193 194 public void setClassFinder(ClassFinder classFinder) { 195 this.classFinder = classFinder; 196 } 197 198 public Artifact[] getConfigId() { 199 if (earContext == null) { 200 throw new NullPointerException("No ear context set"); 201 } 202 if (rootEarContext == null || rootEarContext == earContext || rootEarContext.getConfigID().equals(earContext.getConfigID())) { 203 return new Artifact[] {earContext.getConfigID()}; 204 } 205 return new Artifact[] {rootEarContext.getConfigID(), earContext.getConfigID()}; 206 } 207 208 /** 209 * Given a path in the ear module, return something that will resolve to that location against the eventual configuration 210 * base uri. Currently for all modules except wars that is the original path. If we create separate configurations for 211 * ejb or rar modules, those Module subclasses will need to reimplement this method. 212 * 213 * Example: if a war is myweb.war, and you pass in myweb.war/WEB-INF/lib/foo.jar, you get WEB-INF/lib/foo.jar 214 * if you pass in myFoo.jar, you get ../myFoo.jar 215 * 216 * @param path a path in the ear config, relative to the ear root. 217 * @return a path to the same location, but relative to the configuration this module represents' base uri. 218 */ 219 public String getRelativePath(String path) { 220 return path; 221 } 222 223 }