private void unbindFromRelevantContext(String jndiName) throws NamingException { String relativeJndiName = jndiName; Context ctx = this.javaEEComponent.getContext(); if (jndiName.trim().startsWith("java:comp/")) { relativeJndiName = jndiName.trim().substring("java:comp/".length()); ctx = this.javaEEComponent.getContext(); } else if (jndiName.trim().startsWith("java:module/")) { relativeJndiName = jndiName.trim().substring("java:module/".length()); ctx = this.javaEEComponent.getModule().getContext(); } else if (jndiName.trim().startsWith("java:app/")) { relativeJndiName = jndiName.trim().substring("java:app/".length()); ctx = this.javaEEComponent.getModule().getApplication().getContext(); } else if (jndiName.trim().startsWith("java:global/")) { relativeJndiName = jndiName.trim().substring("java:global/".length()); if (this.javaGlobalContext == null) { logger.debug( "java:global context not set on Switchboard: " + this.id + " will do a manual lookup of java:global context"); ctx = (Context) new InitialContext().lookup("java:global/"); } else { ctx = this.javaGlobalContext; } } logger.debug("Switchboard " + this.id + " unbinding ENC resource from jndi name: " + jndiName); Util.unbind(ctx, relativeJndiName); }
@PostConstruct public void postConstruct(InvocationContext ctx) throws Exception { log.debug("postConstruct " + ctx); Class<?> businessInterfaces[]; InterceptorContainer container = (InterceptorContainer) ctx.getTarget(); Local local = container.getAnnotation(Local.class); if (local != null) businessInterfaces = local.value(); else if (container.getBeanClass().getInterfaces().length == 1) businessInterfaces = new Class<?>[] {container.getBeanClass().getInterfaces()[0]}; else throw new IllegalArgumentException("TODO"); // TODO: determine JNDI name String jndiName = container.getBeanClass().getSimpleName() + "/local"; log.debug("jndiName = " + jndiName); Object proxy = Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), businessInterfaces, new LocalProxy(container)); Util.createSubcontext(new InitialContext(), container.getBeanClass().getSimpleName()); NonSerializableFactory.rebind(new InitialContext(), jndiName, proxy); ctx.proceed(); }