Skip to content

Commit

Permalink
Simplified usages of changePrefix
Browse files Browse the repository at this point in the history
Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Nov 14, 2022
1 parent 2bad373 commit 41ce2ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public Object lookup(String name) throws NamingException {
try {
// Translate the java:app name into the equivalent java:global name so that
// the lookup will be resolved by the server.
obj = ic.lookup(JNDI_CTX_JAVA_GLOBAL + appName + "/" + fullName.removePrefix(JNDI_CTX_JAVA_APP));
obj = ic.lookup(JNDI_CTX_JAVA_GLOBAL + appName + "/" + fullName.removePrefix());
} catch (NamingException e) {
logger.log(Level.FINE, "Trying global version of java:app ejb lookup", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@

import static org.glassfish.api.naming.SimpleJndiName.JNDI_CTX_JAVA_APP;
import static org.glassfish.api.naming.SimpleJndiName.JNDI_CTX_JAVA_APP_ENV;
import static org.glassfish.api.naming.SimpleJndiName.JNDI_CTX_JAVA_COMPONENT_ENV;
import static org.glassfish.api.naming.SimpleJndiName.JNDI_CTX_JAVA_COMPONENT;
import static org.glassfish.api.naming.SimpleJndiName.JNDI_CTX_JAVA_COMPONENT_ENV;
import static org.glassfish.api.naming.SimpleJndiName.JNDI_CTX_JAVA_GLOBAL;
import static org.glassfish.api.naming.SimpleJndiName.JNDI_CTX_JAVA_MODULE;

Expand Down Expand Up @@ -313,11 +313,11 @@ private SimpleJndiName getJavaGlobalJndiNamePrefix(EjbDescriptor ejbDescriptor)

if (appName != null) {
javaGlobalPrefix.append(appName);
javaGlobalPrefix.append("/");
javaGlobalPrefix.append('/');
}

javaGlobalPrefix.append(modName);
javaGlobalPrefix.append("/");
javaGlobalPrefix.append('/');
javaGlobalPrefix.append(ejbName);

return new SimpleJndiName(javaGlobalPrefix.toString());
Expand Down Expand Up @@ -547,8 +547,7 @@ private void parseResources(EjbReferenceDescriptor ejbRef, JndiNameEnvironment e
// Intentionally or not, this resolves the java:app mapped names
// Seems suspicious as the corresponding java:global case is handled in the getRemoteEjbJndiName function call
String appName = DOLUtils.getApplicationName(application);
String newPrefix = JNDI_CTX_JAVA_GLOBAL + appName + "/";
jndiName = new SimpleJndiName(newPrefix + ejbRefJndiName.removePrefix(JNDI_CTX_JAVA_APP));
jndiName = ejbRefJndiName.changePrefix(JNDI_CTX_JAVA_GLOBAL + appName + '/');
validationRequired = true;
} else {
SimpleJndiName remoteJndiName = getRemoteEjbJndiName(ejbRef);
Expand Down Expand Up @@ -686,29 +685,12 @@ private void storeInNamespace(SimpleJndiName name, JndiNameEnvironment env, AppR
* @return The logical JNDI name which has a java: prefix
*/
private SimpleJndiName getLogicalJNDIName(SimpleJndiName rawName, JndiNameEnvironment env) {
SimpleJndiName logicalJndiName = rawNameToLogicalJndiName(rawName);
SimpleJndiName jndiName = rawName.hasJavaPrefix() ? rawName : rawName.changePrefix(JNDI_CTX_JAVA_COMPONENT_ENV);
boolean treatComponentAsModule = DOLUtils.getTreatComponentAsModule(env);
if (treatComponentAsModule && logicalJndiName.isJavaComponent()) {
return logicalCompJndiNameToModule(logicalJndiName);
if (treatComponentAsModule && jndiName.isJavaComponent()) {
return jndiName.changePrefix(JNDI_CTX_JAVA_MODULE);
}
return logicalJndiName;
}


/**
* Convert name from java:comp/xxx to java:module/xxx.
*/
private SimpleJndiName logicalCompJndiNameToModule(SimpleJndiName logicalCompName) {
SimpleJndiName tail = logicalCompName.removePrefix(JNDI_CTX_JAVA_COMPONENT);
return new SimpleJndiName(JNDI_CTX_JAVA_MODULE + tail);
}


/**
* Attach default prefix - java:comp/env/.
*/
private SimpleJndiName rawNameToLogicalJndiName(SimpleJndiName rawName) {
return rawName.hasJavaPrefix() ? rawName : new SimpleJndiName(JNDI_CTX_JAVA_COMPONENT_ENV + rawName);
return jndiName;
}


Expand Down Expand Up @@ -742,19 +724,19 @@ private SimpleJndiName convertModuleOrAppJNDIName(SimpleJndiName jndiName, JndiN
if (jndiName.isJavaApp()) {
if (appName != null) {
javaGlobalName.append(appName);
javaGlobalName.append("/");
javaGlobalName.append('/');
}

// Replace java:app/ with the fully-qualified global portion
javaGlobalName.append(jndiName.removePrefix(JNDI_CTX_JAVA_APP));
} else if (jndiName.isJavaModule()) {
if (appName != null) {
javaGlobalName.append(appName);
javaGlobalName.append("/");
javaGlobalName.append('/');
}

javaGlobalName.append(moduleName);
javaGlobalName.append("/");
javaGlobalName.append('/');
javaGlobalName.append(jndiName.removePrefix(JNDI_CTX_JAVA_MODULE));
} else {
return new SimpleJndiName("");
Expand Down Expand Up @@ -987,7 +969,6 @@ private void noValidation() {

private static class AppResources {
List<AppResource> myResources;

JNDINamespace myNamespace;

private AppResources() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ public Object resolveEjbReference(EjbReferenceDescriptor ejbRefDesc, Context con
SimpleJndiName remoteJndiName = ejbRefDesc.getJndiName();

String appName = (String) context.lookup(JNDI_CTX_JAVA_APP + "AppName");
String newPrefix = JNDI_CTX_JAVA_GLOBAL + appName + "/";
String globalLookup = newPrefix + remoteJndiName.removePrefix(JNDI_CTX_JAVA_APP);
String globalLookup = remoteJndiName.changePrefix(JNDI_CTX_JAVA_GLOBAL + appName + '/').toString();
jndiObj = context.lookup(globalLookup);
resolved = true;
} else {
Expand Down

0 comments on commit 41ce2ef

Please sign in to comment.