001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.j2ee.deployment;
017:
018: import java.util.jar.JarFile;
019: import java.util.Map;
020: import java.util.HashMap;
021: import java.net.URI;
022:
023: import org.apache.xmlbeans.XmlObject;
024: import org.apache.geronimo.kernel.config.ConfigurationModuleType;
025: import org.apache.geronimo.kernel.repository.Environment;
026: import org.apache.geronimo.kernel.repository.Artifact;
027: import org.apache.geronimo.deployment.util.DeploymentUtil;
028: import org.apache.geronimo.gbean.AbstractName;
029: import org.apache.geronimo.j2ee.deployment.annotation.AnnotatedApp;
030: import org.apache.xbean.finder.ClassFinder;
031:
032: /**
033: * @version $Rev: 538730 $ $Date: 2007-05-16 14:07:51 -0700 (Wed, 16 May 2007) $
034: */
035: public abstract class Module {
036: private final boolean standAlone;
037:
038: private final AbstractName moduleName;
039: private final String name;
040: private final Environment environment;
041: private final URI moduleURI;
042: private final JarFile moduleFile;
043: private final String targetPath;
044: private final URI targetPathURI;
045: private final XmlObject vendorDD;
046: private final String namespace;
047:
048: private EARContext earContext;
049: private EARContext rootEarContext;
050: private XmlObject specDD;
051: private String originalSpecDD;
052: private AnnotatedApp annotatedApp;
053: private ClassFinder classFinder;
054:
055: protected final Map sharedContext = new HashMap();
056:
057: protected Module(boolean standAlone, AbstractName moduleName,
058: Environment environment, JarFile moduleFile,
059: String targetPath, XmlObject specDD, XmlObject vendorDD,
060: String originalSpecDD, String namespace,
061: AnnotatedApp annotatedApp) {
062: assert targetPath != null : "targetPath is null";
063: assert moduleName != null : "moduleName is null";
064:
065: this .standAlone = standAlone;
066: this .moduleName = moduleName;
067: this .environment = environment;
068: this .moduleFile = moduleFile;
069: this .targetPath = targetPath;
070: this .specDD = specDD;
071: this .vendorDD = vendorDD;
072: this .originalSpecDD = originalSpecDD;
073: this .namespace = namespace;
074:
075: if (standAlone) {
076: name = environment.getConfigId().toString();
077: moduleURI = URI.create("");
078: } else {
079: name = targetPath;
080: moduleURI = URI.create(targetPath);
081: }
082:
083: targetPathURI = URI.create(targetPath + "/");
084: this .annotatedApp = annotatedApp;
085: }
086:
087: public abstract ConfigurationModuleType getType();
088:
089: public String getName() {
090: return name;
091: }
092:
093: public boolean isStandAlone() {
094: return standAlone;
095: }
096:
097: public AbstractName getModuleName() {
098: return moduleName;
099: }
100:
101: public Environment getEnvironment() {
102: return environment;
103: }
104:
105: public URI getModuleURI() {
106: return moduleURI;
107: }
108:
109: public JarFile getModuleFile() {
110: return moduleFile;
111: }
112:
113: public String getTargetPath() {
114: return targetPath;
115: }
116:
117: public URI getTargetPathURI() {
118: return targetPathURI;
119: }
120:
121: public XmlObject getSpecDD() {
122: return specDD;
123: }
124:
125: public XmlObject getVendorDD() {
126: return vendorDD;
127: }
128:
129: public String getOriginalSpecDD() {
130: return originalSpecDD;
131: }
132:
133: public String getNamespace() {
134: return namespace;
135: }
136:
137: public int hashCode() {
138: return name.hashCode();
139: }
140:
141: public boolean equals(Object obj) {
142: if (obj == this ) {
143: return true;
144: }
145: if (obj instanceof Module) {
146: Module module = (Module) obj;
147: return name.equals(module.name);
148: }
149: return false;
150: }
151:
152: public void close() {
153: DeploymentUtil.close(moduleFile);
154: }
155:
156: public EARContext getEarContext() {
157: return earContext;
158: }
159:
160: public void setEarContext(EARContext earContext) {
161: this .earContext = earContext;
162: }
163:
164: public EARContext getRootEarContext() {
165: return rootEarContext;
166: }
167:
168: public void setRootEarContext(EARContext rootEarContext) {
169: this .rootEarContext = rootEarContext;
170: }
171:
172: public Map getSharedContext() {
173: return sharedContext;
174: }
175:
176: public void setSpecDD(XmlObject specDD) {
177: this .specDD = specDD;
178: }
179:
180: public void setOriginalSpecDD(String originalSpecDD) {
181: this .originalSpecDD = originalSpecDD;
182: }
183:
184: public AnnotatedApp getAnnotatedApp() {
185: return annotatedApp;
186: }
187:
188: public void setAnnotatedApp(AnnotatedApp annotatedApp) {
189: this .annotatedApp = annotatedApp;
190: }
191:
192: public ClassFinder getClassFinder() {
193: return classFinder;
194: }
195:
196: public void setClassFinder(ClassFinder classFinder) {
197: this .classFinder = classFinder;
198: }
199:
200: public Artifact[] getConfigId() {
201: if (earContext == null) {
202: throw new NullPointerException("No ear context set");
203: }
204: if (rootEarContext == null
205: || rootEarContext == earContext
206: || rootEarContext.getConfigID().equals(
207: earContext.getConfigID())) {
208: return new Artifact[] { earContext.getConfigID() };
209: }
210: return new Artifact[] { rootEarContext.getConfigID(),
211: earContext.getConfigID() };
212: }
213:
214: /**
215: * Given a path in the ear module, return something that will resolve to that location against the eventual configuration
216: * base uri. Currently for all modules except wars that is the original path. If we create separate configurations for
217: * ejb or rar modules, those Module subclasses will need to reimplement this method.
218: *
219: * 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
220: * if you pass in myFoo.jar, you get ../myFoo.jar
221: *
222: * @param path a path in the ear config, relative to the ear root.
223: * @return a path to the same location, but relative to the configuration this module represents' base uri.
224: */
225: public String getRelativePath(String path) {
226: return path;
227: }
228:
229: }
|