org.apache.openejb.config.AppModule Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.openejb.config;
import java.util.HashSet;
import org.apache.openejb.config.sys.Resource;
import org.apache.openejb.jee.Application;
import org.apache.openejb.jee.jpa.EntityMappings;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
/**
* @version $Rev: 1176533 $ $Date: 2011-09-27 12:07:38 -0700 (Tue, 27 Sep 2011) $
*/
public class AppModule implements DeploymentModule {
private final Properties properties = new Properties();
private final Application application;
private final ValidationContext validation;
private final List additionalLibraries = new ArrayList();
private final List connectorModules = new ArrayList();
private final List webModules = new ArrayList();
private final List clientModules = new ArrayList();
private final List ejbModules = new ArrayList();
private final List persistenceModules = new ArrayList();
// TODO We could turn this into the Resources JAXB object and support containers and other things as well
private final Collection resources = new HashSet();
private final ClassLoader classLoader;
private EntityMappings cmpMappings;
private final Map altDDs = new HashMap();
private final Set watchedResources = new TreeSet();
private final boolean standaloneModule;
private Set mBeans = new HashSet();
private ID id;
public AppModule(ClassLoader classLoader, String jarLocation) {
this(classLoader, jarLocation, null, false);
}
public AppModule(T module) {
this.standaloneModule = true;
this.classLoader = module.getClassLoader();
this.application = new Application(module.getModuleId());
this.id = new ID(null, application, null, module.getFile(), module.getModuleUri(), this);
this.validation = new ValidationContext(this);
final Class type = module.getClass();
if (type == EjbModule.class) {
getEjbModules().add((EjbModule) module);
} else if (type == ClientModule.class) {
getClientModules().add((ClientModule) module);
} else if (type == ConnectorModule.class) {
getConnectorModules().add((ConnectorModule) module);
} else if (type == WebModule.class) {
getWebModules().add((WebModule) module);
} else if (type == PersistenceModule.class) {
getPersistenceModules().add((PersistenceModule) module);
} else {
throw new IllegalArgumentException("Unknown module type: " + type.getName());
}
}
public Properties getProperties() {
return properties;
}
public AppModule(ClassLoader classLoader, String jarLocation, Application application, boolean standaloneModule) {
this.classLoader = classLoader;
this.application = application;
File file = (jarLocation == null) ? null : new File(jarLocation);
this.id = new ID(null, application, null, file, null, this);
this.validation = new ValidationContext(this);
this.standaloneModule = standaloneModule;
}
public Set getMBeans() {
return mBeans;
}
public void setMBeans(Set mBeans) {
this.mBeans = mBeans;
}
public boolean isStandaloneModule() {
return standaloneModule;
}
public void setStandaloneModule(boolean isStandalone) {
//do nothing
}
public ValidationContext getValidation() {
return validation;
}
public boolean hasWarnings() {
if (validation.hasWarnings()) return true;
for (EjbModule module : ejbModules) {
if (module.getValidation().hasWarnings()) return true;
}
for (ClientModule module : clientModules) {
if (module.getValidation().hasWarnings()) return true;
}
for (ConnectorModule module : connectorModules) {
if (module.getValidation().hasWarnings()) return true;
}
for (WebModule module : webModules) {
if (module.getValidation().hasWarnings()) return true;
}
return false;
}
public boolean hasFailures() {
if (validation.hasFailures()) return true;
for (EjbModule module : ejbModules) {
if (module.getValidation().hasFailures()) return true;
}
for (ClientModule module : clientModules) {
if (module.getValidation().hasFailures()) return true;
}
for (ConnectorModule module : connectorModules) {
if (module.getValidation().hasFailures()) return true;
}
for (WebModule module : webModules) {
if (module.getValidation().hasFailures()) return true;
}
return false;
}
public boolean hasErrors() {
if (validation.hasErrors()) return true;
for (EjbModule module : ejbModules) {
if (module.getValidation().hasErrors()) return true;
}
for (ClientModule module : clientModules) {
if (module.getValidation().hasErrors()) return true;
}
for (ConnectorModule module : connectorModules) {
if (module.getValidation().hasErrors()) return true;
}
for (WebModule module : webModules) {
if (module.getValidation().hasErrors()) return true;
}
return false;
}
public List getValidationContexts() {
List contexts = new ArrayList();
contexts.add(getValidation());
for (EjbModule module : ejbModules) {
contexts.add(module.getValidation());
}
for (ClientModule module : clientModules) {
contexts.add(module.getValidation());
}
for (ConnectorModule module : connectorModules) {
contexts.add(module.getValidation());
}
for (WebModule module : webModules) {
contexts.add(module.getValidation());
}
return contexts;
}
public String getJarLocation() {
return (id.getLocation() != null) ? id.getLocation().getAbsolutePath() : null;
}
public void setModuleId(String moduleId) {
this.id = new ID(null, application, moduleId, id.getLocation(), id.getUri(), this);
}
public String getModuleId() {
return id.getName();
}
public File getFile() {
return id.getLocation();
}
public URI getModuleUri() {
return id.getUri();
}
public Map getAltDDs() {
return altDDs;
}
public ClassLoader getClassLoader() {
return classLoader;
}
public Application getApplication() {
return application;
}
public List getClientModules() {
return clientModules;
}
public List getEjbModules() {
return ejbModules;
}
public List getPersistenceModules() {
return persistenceModules;
}
public List getAdditionalLibraries() {
return additionalLibraries;
}
public EntityMappings getCmpMappings() {
return cmpMappings;
}
public void setCmpMappings(EntityMappings cmpMappings) {
this.cmpMappings = cmpMappings;
}
public List getConnectorModules() {
return connectorModules;
}
public List getWebModules() {
return webModules;
}
public Set getWatchedResources() {
return watchedResources;
}
public Collection getResources() {
return resources;
}
public Collection getDeploymentModule() {
ArrayList modules = new ArrayList();
modules.addAll(ejbModules);
modules.addAll(webModules);
modules.addAll(connectorModules);
modules.addAll(clientModules);
return modules;
}
@Override
public String toString() {
return "AppModule{" +
"moduleId='" + id.getName() + '\'' +
'}';
}
}