Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.enterprise.deployment;
import com.sun.enterprise.deploy.shared.FileArchive;
import com.sun.enterprise.deployment.annotation.introspection.EjbComponentAnnotationScanner;
import com.sun.enterprise.deployment.archivist.AppClientArchivist;
import com.sun.enterprise.deployment.archivist.ApplicationArchivist;
import com.sun.enterprise.deployment.archivist.EjbArchivist;
import com.sun.enterprise.deployment.deploy.shared.InputJarArchive;
import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper;
import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactory;
import com.sun.enterprise.deployment.node.ApplicationNode;
import com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping;
import com.sun.enterprise.deployment.types.RoleMappingContainer;
import com.sun.enterprise.deployment.util.*;
import com.sun.enterprise.util.LocalStringManagerImpl;
import com.sun.enterprise.util.io.FileUtils;
import org.glassfish.api.deployment.archive.ReadableArchive;
import org.glassfish.deployment.common.DeploymentUtils;
import org.glassfish.resource.common.Resource;
import org.jvnet.hk2.component.Habitat;
import javax.enterprise.deploy.shared.ModuleType;
import javax.persistence.EntityManagerFactory;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Objects of this type encapsulate the data and behaviour of a J2EE
* application.
*
* @author Danny Coward
*/
public class Application extends RootDeploymentDescriptor
implements Roles, RoleMappingContainer {
/**
* default value for the library-directory element
*/
private static final String LIBRARY_DIRECTORY_DEFAULT_VALUE = "lib";
private static final String PERSISTENCE_UNIT_NAME_SEPARATOR = "#";
/**
* Store generated XML dir to be able to get the generated WSDL
*/
private String generatedXMLDir;
// Set of modules in this application
private Set> modules = new HashSet>();
// IASRI 4645310
/**
* unique id for this application
*/
private long uniqueId;
// IASRI 4645310
/**
* represents the virtual status of this application object
*/
private boolean virtual = false;
// IASRI 4662001, 4720955
/**
* represents whether all ejb modules in an application will be pass by
* value or pass by reference
*/
private Boolean passByReference = null;
// table of EJB2.0 CMP descriptors (EntityBeans)
// keyed on their class names
private HashMap cmpDescriptors = null;
// use a String object as lock so it can be serialized as part
// of the Application object
private String cmpDescriptorsLock = new String("cmp descriptors lock");
// flag to indicate that the memory representation of this application
// is not in sync with the disk representation
private boolean isDirty;
// data structure to map roles to users and groups
private SecurityRoleMapper roleMapper;
// IASRI 4648645 - application registration name
/**
* name used to register this application
*/
private String registrationName;
// realm associated with this application
private String realm;
// Physical entity manager factory corresponding to the unit name of
// each application-level persistence unit. Only available at runtime.
private Map entityManagerFactories =
new HashMap();
private Set entityManagerFactoryUnitNames =
new HashSet();
// for i18N
private static LocalStringManagerImpl localStrings =
new LocalStringManagerImpl(Application.class);
private Set appRoles;
private String libraryDirectory;
private List roleMaps = new ArrayList();
private boolean loadedFromApplicationXml = true;
private List resourceList = null;
private boolean isPackagedAsSingleModule = false;
private final Habitat habitat;
public Application(Habitat habitat) {
super("", localStrings.getLocalString(
"enterprise.deployment.application.description",
"Application description"));
this.habitat = habitat;
}
// Create logger object per Java SDK 1.4 to log messages
// introduced Santanu De, Sun Microsystems, March 2002
static Logger _logger = DOLUtils.getDefaultLogger();
/**
* @return the default version of the deployment descriptor
* loaded by this descriptor
*/
public String getDefaultSpecVersion() {
return ApplicationNode.SPEC_VERSION;
}
public boolean isEmpty() {
return modules.isEmpty();
}
/**
* Creates a new application to hold a standalone module
*
* @param name the application name
* @param newModule the standalone module descriptor
* @return the application
*/
public static Application createApplication(Habitat habitat, String name, ModuleDescriptor newModule) {
// create a new empty application
Application application = new Application(habitat);
application.setVirtual(true);
if (name == null && newModule.getDescriptor() != null) {
name = newModule.getDescriptor().getDisplayName();
}
if (name != null) {
application.setDisplayName(name);
application.setName(name);
}
// add the module to it
newModule.setStandalone(true);
newModule.setArchiveUri(name);
if (newModule.getDescriptor() != null) {
newModule.getDescriptor().setApplication(application);
}
application.addModule(newModule);
return application;
}
public void setGeneratedXMLDirectory(String xmlDir) {
generatedXMLDir = xmlDir;
}
/**
* Returns the generated XML directory for this app
*/
public String getGeneratedXMLDirectory() {
return generatedXMLDir;
}
// START OF IASRI 4648645 - application registration name
/**
* Sets the registration name for this application. This name is used
* while deploying the application. The deployment process gurantees
* that this name is unique.
*
* @param appId the registration name used for this application
*/
public void setRegistrationName(String appId) {
// at his point we need to swap our RoleMapper, if we have one...
SecurityRoleMapper roleMapper = null;
try {
roleMapper = getRoleMapper();
} catch (IllegalArgumentException ignore) {
}
if (roleMapper != null) {
SecurityRoleMapperFactory factory = habitat.getComponent(SecurityRoleMapperFactory.class);
if (factory == null) {
throw new IllegalArgumentException(localStrings.getLocalString(
"enterprise.deployment.norolemapperfactorydefine",
"This application has no role mapper factory defined"));
}
factory.removeRoleMapper(getName());
roleMapper.setName(appId);
factory.setRoleMapper(appId, roleMapper);
}
this.registrationName = appId;
}
/**
* Returns the registration name of this application.
*
* @return the registration name of this application
*/
public String getRegistrationName() {
if (registrationName != null) {
return registrationName;
} else {
return getName();
}
}
// END OF IASRI 4648645
/**
* Set the physical entity manager factory for a persistence unit
* within this application.
* This method takes a parameter called persistenceRootUri to support for
* fully-qualified persistence-unit-name syntax within
* persistence-unit-refs and persistence-context-refs. The syntax is similar
* to ejb-link and messge-destination-link. See (EJB 3 core spec: 15.10.2)
*
* @param unitName: Name of the persistence-unit
* @param persistenceRootUri: uri of the root of the persistence.xml
* (excluding META-INF) in which the persistence unit was defined.
* This uri is relative to the top of the .ear.
* @param emf: an entity manager factory.
*/
public void addEntityManagerFactory(
String unitName,
String persistenceRootUri,
EntityManagerFactory emf) {
String fullyQualifiedUnitName = persistenceRootUri +
PERSISTENCE_UNIT_NAME_SEPARATOR + unitName;
// Always allow fully qualified lookup.
entityManagerFactories.put(fullyQualifiedUnitName, emf);
// Allow unqualified lookup, unless there are multiple .ear level
// persistence units declaring the same persistence unit name. In that
// case, only a fully-qualified lookup will work. Note that even
// though the entity manager factory map might contain more than one
// key pointing to the same entity manager factory, the behavior
// of getEntityManagerFactories() is not affected since it returns a Set.
if (entityManagerFactoryUnitNames.contains(unitName)) {
entityManagerFactories.remove(unitName);
} else {
entityManagerFactories.put(unitName, emf);
entityManagerFactoryUnitNames.add(unitName);
}
}
/**
* Retrieve the physical entity manager factory associated with the
* unitName of an application-level persistence unit. Returns null if
* no matching entry is found.
*/
public EntityManagerFactory getEntityManagerFactory
(String unitName, BundleDescriptor declaringModule) {
String lookupString = unitName;
int separatorIndex =
unitName.lastIndexOf(PERSISTENCE_UNIT_NAME_SEPARATOR);
if (separatorIndex != -1) {
String unqualifiedUnitName =
unitName.substring(separatorIndex + 1);
String path = unitName.substring(0, separatorIndex);
String persistenceRootUri = getTargetUri(declaringModule, path);
lookupString = persistenceRootUri +
PERSISTENCE_UNIT_NAME_SEPARATOR + unqualifiedUnitName;
}
return entityManagerFactories.get(lookupString);
}
/**
* Returns the set of physical entity manager factories associated with
* persistence units in this application.
*/
public Set getEntityManagerFactories() {
return new HashSet
(entityManagerFactories.values());
}
/**
* Return the set of roles used in this application. Currently, for release 1.0, it is an
* * aggregation of all the roles in the sub-modules of the application.
*
* @return the Set of roles in the application.
*/
public Set getRoles() {
Set roles = new HashSet();
for (WebBundleDescriptor wbd : getWebBundleDescriptors()) {
if (wbd != null) {
roles.addAll(wbd.getRoles());
}
}
for (EjbBundleDescriptor ejbd : getEjbBundleDescriptors()) {
if (ejbd != null) {
roles.addAll(ejbd.getRoles());
}
}
return roles;
}
/**
* Return the set of com.sun.enterprise.deployment.Role objects
* I have (the ones defined in application xml).
*/
public Set getAppRoles() {
if (this.appRoles == null) {
this.appRoles = new OrderedSet();
}
return this.appRoles;
}
public void addAppRole(SecurityRoleDescriptor descriptor) {
Role role = new Role(descriptor.getName());
role.setDescription(descriptor.getDescription());
getAppRoles().add(role);
}
/**
* Adds a new abstract role
*/
public void addRole(Role role) {
for (WebBundleDescriptor wbd : getWebBundleDescriptors()) {
wbd.addRole(role);
}
for (EjbBundleDescriptor ejbd : getEjbBundleDescriptors()) {
ejbd.addRole(role);
}
}
/**
* Removes the given role.
*/
public void removeRole(Role role) {
getAppRoles().remove(role);
for (WebBundleDescriptor wbd : getWebBundleDescriptors()) {
wbd.removeRole(role);
}
for (EjbBundleDescriptor ejbd : getEjbBundleDescriptors()) {
ejbd.removeRole(role);
}
}
/**
* Return the Set of all reource references that my components have.
*/
public Set getResourceReferenceDescriptors() {
Set resourceReferences = new HashSet();
for (EjbBundleDescriptor ejbd : getEjbBundleDescriptors()) {
resourceReferences.addAll(ejbd.getResourceReferenceDescriptors());
}
return resourceReferences;
}
/**
* Reset the display name of this application.
*
* @param name the display name of the application.
*/
public void setName(String name) {
name = name.replace('/', '-');
name = name.replace('\\', '-'); // for deploying from NT to solaris & vice versa. This will
// need to be cleaned when we clean up the backend for registering apps
super.setName(name);
if (this.getRoleMapper() != null) {
this.getRoleMapper().setName(name);
}
}
public void setLibraryDirectory(String value) {
libraryDirectory = value;
}
/**
* Returns an "intelligent" value for the library directory setting, meaning
* the current value if it has been set to a non-null, non-empty value;
* the default value if the value has never been set, and null if the value
* has been set to empty.
*
* @return String value of the library directory setting
*/
public String getLibraryDirectory() {
if (libraryDirectory != null) {
return (libraryDirectory.length() == 0) ? null : libraryDirectory;
} else {
return LIBRARY_DIRECTORY_DEFAULT_VALUE;
}
}
public String getLibraryDirectoryRawValue() {
return libraryDirectory;
}
/**
* The number of Web Components in this application.
* Current implementation only return the number of servlets
* inside the application, and not the JSPs since we cannot
* get that information from deployment descriptors.
*
* @return the number of Web Components
*/
public int getWebComponentCount() {
int count = 0;
for (WebBundleDescriptor wbd : getWebBundleDescriptors()) {
count = count + wbd.getWebComponentDescriptors().size();
}
return count;
}
public void removeModule(ModuleDescriptor descriptor) {
if (modules.contains(descriptor)) {
if (descriptor.getDescriptor() != null) {
descriptor.getDescriptor().setApplication(null);
}
modules.remove(descriptor);
}
}
public void addModule(ModuleDescriptor descriptor) {
modules.add(descriptor);
if (descriptor.getDescriptor() != null) {
descriptor.getDescriptor().setApplication(this);
}
}
/**
* Obtain a full set of module descriptors
*
* @return the set of bundle descriptors
*/
public Set> getModules() {
return modules;
}
/**
* The number of EJB JARs in this application.
*
* @return the number of EJB JARS
*/
public int getEjbComponentCount() {
int count = 0;
for (EjbBundleDescriptor ejbd : this.getEjbBundleDescriptors()) {
count = count + ejbd.getEjbs().size();
}
return count;
}
public int getRarComponentCount() {
return getBundleDescriptors(ConnectorDescriptor.class).size();
}
/**
* The Vector of EJB references in all subcomponents of this application.
*
* @return The Vector of EJB references
*/
public Vector