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.openejb.config;
017:
018: import org.apache.openejb.jee.WebApp;
019: import org.apache.openejb.jee.TldTaglib;
020: import org.apache.openejb.jee.Webservices;
021:
022: import java.util.Map;
023: import java.util.HashMap;
024: import java.util.List;
025: import java.util.ArrayList;
026: import java.util.Set;
027: import java.util.TreeSet;
028: import java.io.File;
029:
030: /**
031: * @version $Rev: 602803 $ $Date: 2007-12-10 00:07:48 -0800 $
032: */
033: public class WebModule implements WsModule {
034: private final ValidationContext validation;
035: private final Map<String, Object> altDDs = new HashMap<String, Object>();
036:
037: private WebApp webApp;
038: private Webservices webservices;
039: private String host;
040: private String contextRoot;
041: private ClassLoader classLoader;
042: private String jarLocation;
043: private final String moduleId;
044: private final List<TldTaglib> taglibs = new ArrayList<TldTaglib>();
045: private final Set<String> watchedResources = new TreeSet<String>();
046:
047: public WebModule(WebApp webApp, String contextRoot,
048: ClassLoader classLoader, String jarLocation, String moduleId) {
049: this .webApp = webApp;
050: if (contextRoot == null) {
051: contextRoot = jarLocation.substring(jarLocation
052: .lastIndexOf('/'));
053: if (contextRoot.endsWith(".unpacked")) {
054: contextRoot = contextRoot.substring(0, contextRoot
055: .length()
056: - ".unpacked".length());
057: }
058: if (contextRoot.endsWith(".war")) {
059: contextRoot = contextRoot.substring(0, contextRoot
060: .length()
061: - ".war".length());
062: }
063: }
064: if (contextRoot.startsWith("/"))
065: contextRoot = contextRoot.substring(1);
066: this .contextRoot = contextRoot;
067: this .classLoader = classLoader;
068: this .jarLocation = jarLocation;
069:
070: if (webApp != null)
071: webApp.setContextRoot(contextRoot);
072:
073: if (moduleId == null) {
074: if (webApp != null && webApp.getId() != null) {
075: moduleId = webApp.getId();
076: } else {
077: File file = new File(jarLocation);
078: moduleId = file.getName();
079: if (moduleId.endsWith(".unpacked")) {
080: moduleId = moduleId.substring(0, moduleId.length()
081: - ".unpacked".length());
082: }
083: }
084: }
085:
086: this .moduleId = moduleId;
087: validation = new ValidationContext(WebModule.class, jarLocation);
088: }
089:
090: public ValidationContext getValidation() {
091: return validation;
092: }
093:
094: public String getModuleId() {
095: return moduleId;
096: }
097:
098: public Map<String, Object> getAltDDs() {
099: return altDDs;
100: }
101:
102: public WebApp getWebApp() {
103: return webApp;
104: }
105:
106: public void setWebApp(WebApp webApp) {
107: this .webApp = webApp;
108: if (webApp != null)
109: webApp.setContextRoot(contextRoot);
110: }
111:
112: public Webservices getWebservices() {
113: return webservices;
114: }
115:
116: public void setWebservices(Webservices webservices) {
117: this .webservices = webservices;
118: }
119:
120: public ClassLoader getClassLoader() {
121: return classLoader;
122: }
123:
124: public void setClassLoader(ClassLoader classLoader) {
125: this .classLoader = classLoader;
126: }
127:
128: public String getJarLocation() {
129: return jarLocation;
130: }
131:
132: public void setJarLocation(String jarLocation) {
133: this .jarLocation = jarLocation;
134: }
135:
136: public String getContextRoot() {
137: return contextRoot;
138: }
139:
140: public void setContextRoot(String contextRoot) {
141: if (webApp != null)
142: webApp.setContextRoot(contextRoot);
143: this .contextRoot = contextRoot;
144: }
145:
146: public String getHost() {
147: return host;
148: }
149:
150: public void setHost(String host) {
151: this .host = host;
152: }
153:
154: public List<TldTaglib> getTaglibs() {
155: return taglibs;
156: }
157:
158: public Set<String> getWatchedResources() {
159: return watchedResources;
160: }
161: }
|