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 java.net.URL;
019: import java.util.ArrayList;
020: import java.util.List;
021: import java.util.Map;
022: import java.util.HashMap;
023: import java.util.Collection;
024: import java.util.Set;
025: import java.util.TreeSet;
026: import java.io.File;
027:
028: import org.apache.openejb.jee.jpa.EntityMappings;
029:
030: /**
031: * @version $Rev: 628987 $ $Date: 2008-02-18 20:26:02 -0800 $
032: */
033: public class AppModule implements DeploymentModule {
034:
035: private final ValidationContext validation;
036: private final List<URL> additionalLibraries = new ArrayList<URL>();
037: private final List<ConnectorModule> connectorModules = new ArrayList<ConnectorModule>();
038: private final List<WebModule> webModules = new ArrayList<WebModule>();
039: private final List<ClientModule> clientModules = new ArrayList<ClientModule>();
040: private final List<EjbModule> ejbModules = new ArrayList<EjbModule>();
041: private final List<PersistenceModule> persistenceModules = new ArrayList<PersistenceModule>();
042: private final String jarLocation;
043: private final ClassLoader classLoader;
044: private EntityMappings cmpMappings;
045: private final Map<String, Object> altDDs = new HashMap<String, Object>();
046: private final String moduleId;
047: private final Set<String> watchedResources = new TreeSet<String>();
048:
049: public AppModule(ClassLoader classLoader, String jarLocation) {
050: this .classLoader = classLoader;
051: this .jarLocation = jarLocation;
052: File file = new File(jarLocation);
053: moduleId = file.getName();
054: validation = new ValidationContext(AppModule.class, jarLocation);
055: }
056:
057: public ValidationContext getValidation() {
058: return validation;
059: }
060:
061: public boolean hasWarnings() {
062: if (validation.hasWarnings())
063: return true;
064: for (EjbModule module : ejbModules) {
065: if (module.getValidation().hasWarnings())
066: return true;
067: }
068: for (ClientModule module : clientModules) {
069: if (module.getValidation().hasWarnings())
070: return true;
071: }
072: for (ConnectorModule module : connectorModules) {
073: if (module.getValidation().hasWarnings())
074: return true;
075: }
076: for (WebModule module : webModules) {
077: if (module.getValidation().hasWarnings())
078: return true;
079: }
080: return false;
081: }
082:
083: public boolean hasFailures() {
084: if (validation.hasFailures())
085: return true;
086: for (EjbModule module : ejbModules) {
087: if (module.getValidation().hasFailures())
088: return true;
089: }
090: for (ClientModule module : clientModules) {
091: if (module.getValidation().hasFailures())
092: return true;
093: }
094: for (ConnectorModule module : connectorModules) {
095: if (module.getValidation().hasFailures())
096: return true;
097: }
098: for (WebModule module : webModules) {
099: if (module.getValidation().hasFailures())
100: return true;
101: }
102: return false;
103: }
104:
105: public boolean hasErrors() {
106: if (validation.hasErrors())
107: return true;
108: for (EjbModule module : ejbModules) {
109: if (module.getValidation().hasErrors())
110: return true;
111: }
112: for (ClientModule module : clientModules) {
113: if (module.getValidation().hasErrors())
114: return true;
115: }
116: for (ConnectorModule module : connectorModules) {
117: if (module.getValidation().hasErrors())
118: return true;
119: }
120: for (WebModule module : webModules) {
121: if (module.getValidation().hasErrors())
122: return true;
123: }
124: return false;
125: }
126:
127: public List<ValidationContext> getValidationContexts() {
128: List<ValidationContext> contexts = new ArrayList<ValidationContext>();
129:
130: contexts.add(getValidation());
131:
132: for (EjbModule module : ejbModules) {
133: contexts.add(module.getValidation());
134: }
135: for (ClientModule module : clientModules) {
136: contexts.add(module.getValidation());
137: }
138: for (ConnectorModule module : connectorModules) {
139: contexts.add(module.getValidation());
140: }
141: for (WebModule module : webModules) {
142: contexts.add(module.getValidation());
143: }
144: return contexts;
145: }
146:
147: public String getModuleId() {
148: return moduleId;
149: }
150:
151: public Map<String, Object> getAltDDs() {
152: return altDDs;
153: }
154:
155: public ClassLoader getClassLoader() {
156: return classLoader;
157: }
158:
159: public List<ClientModule> getClientModules() {
160: return clientModules;
161: }
162:
163: public List<EjbModule> getEjbModules() {
164: return ejbModules;
165: }
166:
167: public List<PersistenceModule> getPersistenceModules() {
168: return persistenceModules;
169: }
170:
171: public String getJarLocation() {
172: return jarLocation;
173: }
174:
175: public List<URL> getAdditionalLibraries() {
176: return additionalLibraries;
177: }
178:
179: public EntityMappings getCmpMappings() {
180: return cmpMappings;
181: }
182:
183: public void setCmpMappings(EntityMappings cmpMappings) {
184: this .cmpMappings = cmpMappings;
185: }
186:
187: public List<ConnectorModule> getResourceModules() {
188: return connectorModules;
189: }
190:
191: public List<WebModule> getWebModules() {
192: return webModules;
193: }
194:
195: public Set<String> getWatchedResources() {
196: return watchedResources;
197: }
198:
199: public Collection<DeploymentModule> getDeploymentModule() {
200: ArrayList<DeploymentModule> modules = new ArrayList<DeploymentModule>();
201: modules.addAll(ejbModules);
202: modules.addAll(webModules);
203: modules.addAll(connectorModules);
204: modules.addAll(clientModules);
205: return modules;
206: }
207: }
|