Skip to content

Commit

Permalink
Refactored WebBundleDescriptors
Browse files Browse the repository at this point in the history
- Target: make unit tests possible

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Mar 19, 2023
1 parent c527e3b commit aa2137e
Show file tree
Hide file tree
Showing 49 changed files with 2,962 additions and 3,448 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -64,8 +64,7 @@
import org.glassfish.security.common.Role;

/**
* Objects of this type encapsulate the data and behaviour of a J2EE
* application.
* Objects of this type encapsulate the data and behaviour of a JEE application.
*
* @author Danny Coward
*/
Expand All @@ -76,6 +75,9 @@ public class Application extends CommonResourceBundleDescriptor
MessageDestinationReferenceContainer {

private static final long serialVersionUID = 1L;
private static final Logger LOG = DOLUtils.getDefaultLogger();
private static final LocalStringManagerImpl I18N = new LocalStringManagerImpl(Application.class);


/**
* default value for the library-directory element
Expand All @@ -102,13 +104,11 @@ public class Application extends CommonResourceBundleDescriptor
*/
private long uniqueId;

// IASRI 4645310
/**
* represents the virtual status of this application object
*/
private boolean virtual;

// IASRI 4662001, 4720955
/**
* represents whether all ejb modules in an application will be pass by
* value or pass by reference
Expand All @@ -122,7 +122,6 @@ public class Application extends CommonResourceBundleDescriptor
// data structure to map roles to users and groups
private transient SecurityRoleMapper roleMapper;

// IASRI 4648645 - application registration name
/**
* name used to register this application
*/
Expand Down Expand Up @@ -165,9 +164,6 @@ public class Application extends CommonResourceBundleDescriptor
private final Set<EntityManagerFactoryReferenceDescriptor> entityManagerFactoryReferences = new HashSet<>();
private final Set<EntityManagerReferenceDescriptor> entityManagerReferences = new HashSet<>();

// for i18N
private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(Application.class);

private Set<Role> appRoles;

private String libraryDirectory;
Expand All @@ -181,19 +177,12 @@ public class Application extends CommonResourceBundleDescriptor

private final Set<ApplicationParam> applicationParams = new HashSet<>();

private static final ServiceLocator habitat = Globals.getDefaultHabitat();

private Application() {
super("", localStrings.getLocalString(
super("", I18N.getLocalString(
"enterprise.deployment.application.description",
"Application description"));
}

// 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
Expand All @@ -209,10 +198,11 @@ public boolean isEmpty() {
return modules.isEmpty();
}


/**
* Creates a new application to hold a standalone module
*
* @param name the application name
* @param name the application name
* @param newModule the standalone module descriptor
* @return the application
*/
Expand Down Expand Up @@ -246,13 +236,15 @@ public static Application createVirtualApplication(String name, ModuleDescriptor
return application;
}

/**
* @return a new empty application
*/
public static Application createApplication() {
// create a new empty application
Application retVal = habitat.create(Application.class);
habitat.inject(retVal);
habitat.postConstruct(retVal);

return retVal; // new Application();
ServiceLocator locator = Globals.getStaticBaseServiceLocator();
Application application = locator.create(Application.class);
locator.inject(application);
locator.postConstruct(application);
return application;
}

/**
Expand Down Expand Up @@ -291,7 +283,7 @@ public EjbReferenceDescriptor getEjbReference(String name) {
return er;
}
}
throw new IllegalArgumentException(localStrings.getLocalString(
throw new IllegalArgumentException(I18N.getLocalString(
"enterprise.deployment.exceptionapphasnoejbrefbyname",
"This app [{0}] has no ejb reference by the name of [{1}] ", new Object[]{getName(), name}));
}
Expand Down Expand Up @@ -327,7 +319,7 @@ public ServiceReferenceDescriptor getServiceReferenceByName(String name) {
}
}
throw new IllegalArgumentException(
localStrings.getLocalString("enterprise.deployment.exceptionapphasnoservicerefbyname",
I18N.getLocalString("enterprise.deployment.exceptionapphasnoservicerefbyname",
"This app [{0}] has no service reference by the name of [{1}]",
new Object[] {getRegistrationName(), name}));
}
Expand Down Expand Up @@ -363,7 +355,7 @@ public MessageDestinationReferenceDescriptor getMessageDestinationReferenceByNam
return mdr;
}
}
throw new IllegalArgumentException(localStrings.getLocalString("exceptionapphasnomsgdestrefbyname",
throw new IllegalArgumentException(I18N.getLocalString("exceptionapphasnomsgdestrefbyname",
"This app [{0}] has no message destination reference by the name of [{1}]",
new Object[] {getRegistrationName(), name}));
}
Expand Down Expand Up @@ -399,7 +391,7 @@ public ResourceEnvReferenceDescriptor getResourceEnvReferenceByName(String name)
return jdr;
}
}
throw new IllegalArgumentException(localStrings.getLocalString(
throw new IllegalArgumentException(I18N.getLocalString(
"enterprise.deployment.exceptionapphasnoresourceenvrefbyname",
"This app {0} has no resource environment reference by the name of {1}",
new Object[] {getRegistrationName(), name}));
Expand Down Expand Up @@ -440,7 +432,7 @@ public ResourceReferenceDescriptor getResourceReferenceByName(String name) {
return next;
}
}
throw new IllegalArgumentException(localStrings.getLocalString(
throw new IllegalArgumentException(I18N.getLocalString(
"enterprise.deployment.exceptionapphasnoresourcerefbyname",
"This app {0} has no resource reference by the name of {1}",
new Object[]{getRegistrationName(), name}));
Expand All @@ -457,7 +449,7 @@ public EnvironmentProperty getEnvironmentPropertyByName(String name) {
return ev;
}
}
throw new IllegalArgumentException(localStrings.getLocalString(
throw new IllegalArgumentException(I18N.getLocalString(
"enterprise.deployment.exceptionapphasnoenvpropertybyname",
"This app {0} has no environment property by the name of {1}",
new Object[]{getRegistrationName(), name}));
Expand Down Expand Up @@ -505,7 +497,7 @@ public EntityManagerFactoryReferenceDescriptor getEntityManagerFactoryReferenceB
}
}
throw new IllegalArgumentException(
localStrings.getLocalString("enterprise.deployment.exceptionapphasnoentitymgrfactoryrefbyname",
I18N.getLocalString("enterprise.deployment.exceptionapphasnoentitymgrfactoryrefbyname",
"This app {0} has no entity manager factory reference by the name of {1}",
new Object[] {getRegistrationName(), name}));
}
Expand Down Expand Up @@ -536,7 +528,7 @@ public EntityManagerReferenceDescriptor getEntityManagerReferenceByName(String n
}
}
throw new IllegalArgumentException(
localStrings.getLocalString("enterprise.deployment.exceptionapphasnoentitymgrrefbyname",
I18N.getLocalString("enterprise.deployment.exceptionapphasnoentitymgrrefbyname",
"This app {0} has no entity manager reference by the name of {1}",
new Object[] {getRegistrationName(), name}));
}
Expand Down Expand Up @@ -613,15 +605,16 @@ public String getGeneratedXMLDirectory() {
public void setRegistrationName(String appId) {

// at his point we need to swap our RoleMapper, if we have one...
SecurityRoleMapper roleMapper = null;
SecurityRoleMapper roleMapper;
try {
roleMapper = getRoleMapper();
} catch (IllegalArgumentException ignore) {
roleMapper = null;
}

if (roleMapper != null) {
if (securityRoleMapperFactory == null) {
throw new IllegalArgumentException(localStrings.getLocalString(
throw new IllegalArgumentException(I18N.getLocalString(
"enterprise.deployment.norolemapperfactorydefine",
"This application has no role mapper factory defined"));
}
Expand Down Expand Up @@ -927,7 +920,7 @@ public String getTargetUri(BundleDescriptor origin, String relativeTargetUri) {
URI resolvedUri = originUri.resolve(relativeTargetUri);
return resolvedUri.getPath();
} catch (URISyntaxException use) {
_logger.log(Level.FINE, "origin " + origin + " has invalid syntax", use);
LOG.log(Level.FINE, "origin " + origin + " has invalid syntax", use);
return null;
}
}
Expand Down Expand Up @@ -1065,7 +1058,7 @@ public EjbDescriptor getEjbByName(String ejbName) {
return ejbd.getEjbByName(ejbName);
}
}
throw new IllegalArgumentException(localStrings.getLocalString(
throw new IllegalArgumentException(I18N.getLocalString(
"enterprise.deployment.exceptionapphasnobeannamed", "This application has no beans of name {0}", ejbName));
}

Expand Down Expand Up @@ -1166,18 +1159,17 @@ public Set<BundleDescriptor> getBundleDescriptorsOfType(ArchiveType bundleType)
*/
public Set<BundleDescriptor> getBundleDescriptors() {
Set<BundleDescriptor> bundleSet = new OrderedSet<>();
for (ModuleDescriptor<BundleDescriptor> aModule : getModules()) {
for (ModuleDescriptor<BundleDescriptor> aModule : getModules()) {
BundleDescriptor bundleDesc = aModule.getDescriptor();
if (bundleDesc != null) {
if (bundleDesc == null) {
DOLUtils.getDefaultLogger().fine("Null descriptor for module " + aModule.getArchiveUri());
} else {
bundleSet.add(bundleDesc);
for (RootDeploymentDescriptor rd :
bundleDesc.getExtensionsDescriptors()) {
for (RootDeploymentDescriptor rd : bundleDesc.getExtensionsDescriptors()) {
if (rd instanceof BundleDescriptor) {
bundleSet.add((BundleDescriptor)rd);
bundleSet.add((BundleDescriptor) rd);
}
}
} else {
DOLUtils.getDefaultLogger().fine("Null descriptor for module " + aModule.getArchiveUri());
}
}
return bundleSet;
Expand Down Expand Up @@ -1268,17 +1260,17 @@ public boolean isUniqueIdSet() {
* @param id unique id for this application
*/
public void setUniqueId(long id) {
_logger.log(Level.FINE, "[Application] " + getName() + " , uid: " + id);
LOG.log(Level.FINE, "[Application] " + getName() + " , uid: " + id);
this.uniqueId = id;

EjbDescriptor[] descs = getSortedEjbDescriptors();

for (int i = 0; i < descs.length; i++) {
// Maximum of 2^16 beans max per application
descs[i].setUniqueId((id | i));
if (_logger.isLoggable(Level.FINE)) {
if (LOG.isLoggable(Level.FINE)) {
String module = descs[i].getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri();
_logger.log(Level.FINE, "Ejb " + module + ":" + descs[i].getName() + " id = " +
LOG.log(Level.FINE, "Ejb " + module + ":" + descs[i].getName() + " id = " +
descs[i].getUniqueId());
}
}
Expand Down Expand Up @@ -1380,7 +1372,7 @@ public boolean hasRuntimeInformation() {
public SecurityRoleMapper getRoleMapper() {
if (this.roleMapper == null) {
if (securityRoleMapperFactory == null) {
_logger.log(Level.FINE, "SecurityRoleMapperFactory NOT set.");
LOG.log(Level.FINE, "SecurityRoleMapperFactory NOT set.");
} else {
this.roleMapper = securityRoleMapperFactory.getRoleMapper(this.getName());
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -453,8 +453,8 @@ public InjectionInfo getInjectionInfoByClass(Class<?> clazz, JndiNameEnvironment
String postConstructMethodName = postConstructDesc == null ? null : postConstructDesc.getLifecycleCallbackMethod();
LifecycleCallbackDescriptor preDestroyDesc = getPreDestroyDescriptorByClass(className, jndiNameEnv);
String preDestroyMethodName = preDestroyDesc == null ? null : preDestroyDesc.getLifecycleCallbackMethod();
injectionInfo = new InjectionInfo(className, postConstructMethodName, preDestroyMethodName,
getInjectableResourcesByClass(className, jndiNameEnv));
List<InjectionCapable> resourcesByClass = getInjectableResourcesByClass(className, jndiNameEnv);
injectionInfo = new InjectionInfo(className, postConstructMethodName, preDestroyMethodName, resourcesByClass);

// store it in the cache and return
injectionInfos.put(key, injectionInfo);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,7 +17,9 @@

package com.sun.enterprise.deployment;

import java.util.Vector;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.glassfish.api.naming.SimpleJndiName;
import org.glassfish.deployment.common.Descriptor;
Expand All @@ -27,33 +29,30 @@
*/
public class CommonResourceValidator {

private Descriptor descriptor;
private final Descriptor descriptor;
private final SimpleJndiName jndiName;
private Vector<String> scope;
private final List<String> scope;

public CommonResourceValidator(Descriptor descriptor, SimpleJndiName jndiName, Vector<String> scope) {
this.setDescriptor(descriptor);
this.jndiName = jndiName;
this.setScope(scope);
public CommonResourceValidator(Descriptor descriptor, SimpleJndiName jndiName, String scope) {
this.descriptor = descriptor;
this.jndiName = Objects.requireNonNull(jndiName, "jndiName");
this.scope = new ArrayList<>();
this.scope.add(scope);
}

public Descriptor getDescriptor() {
return descriptor;
}

public void setDescriptor(Descriptor descriptor) {
this.descriptor = descriptor;
}

public SimpleJndiName getJndiName() {
return jndiName;
}

public Vector<String> getScope() {
public List<String> getScope() {
return scope;
}

public void setScope(Vector<String> scope) {
this.scope = scope;
public void addScope(String scope) {
this.scope.add(scope);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -20,6 +20,7 @@
import com.sun.enterprise.deployment.util.DOLUtils;

import java.sql.Connection;
import java.util.Objects;
import java.util.Properties;
import java.util.logging.Level;

Expand Down Expand Up @@ -337,9 +338,7 @@ public boolean equals(Object object) {

@Override
public int hashCode() {
int result = 17;
result = 37 * result + getName().hashCode();
return result;
return Objects.hash(getName());
}

public void addDataSourcePropertyDescriptor(ResourcePropertyDescriptor propertyDescriptor){
Expand Down

0 comments on commit aa2137e

Please sign in to comment.