Last active
August 29, 2015 14:09
-
-
Save luszczynski/575657b9ffe0f82c232f to your computer and use it in GitHub Desktop.
EJB JNDI View with parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Object getEJB(final Class<?> ejbClass) throws Exception { | |
try { | |
InitialContext ctx = new InitialContext(); | |
NamingEnumeration<NameClassPair> globals; | |
NamingEnumeration<NameClassPair> modules; | |
NamingEnumeration<NameClassPair> apps; | |
NameClassPair global; | |
NameClassPair module; | |
NameClassPair app; | |
String beanInterface; | |
globals = ctx.list("java:global"); | |
while (globals.hasMore()) { | |
global = globals.next(); | |
modules = ctx.list("java:global/" + global.getName()); | |
while(modules.hasMore()) { | |
module = modules.next(); | |
apps = ctx.list("java:global/" + global.getName() + "/" + module.getName()); | |
while(apps.hasMore()) { | |
app = apps.next(); | |
beanInterface = app.getClassName(); | |
if (beanInterface != null && beanInterface.equals(ejbClass.getCanonicalName())) { | |
return ctx.lookup("java:global/" + global.getName() + "/" + module.getName() + "/" + app.getName() + "!" + app.getClassName()); | |
} | |
} | |
} | |
} | |
} catch (Exception e) { | |
throw new Exception(e); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment