/** * Set the JNDI environment to use for JNDI lookups. * @see org.springframework.jndi.JndiAccessor#setJndiEnvironment */ public void setJndiEnvironment(Properties jndiEnvironment) { this.jndiLocator.setJndiEnvironment(jndiEnvironment); }
/** * Configure a {@code JndiLocatorDelegate} with its "resourceRef" property set to * {@code true}, meaning that all names will be prefixed with "java:comp/env/". * @see #setResourceRef */ public static JndiLocatorDelegate createDefaultResourceRefLocator() { JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); jndiLocator.setResourceRef(true); return jndiLocator; }
/** * Set the JNDI template to use for JNDI lookups. * You can also specify JNDI environment settings via "jndiEnvironment". * @see #setJndiEnvironment */ public void setJndiTemplate(JndiTemplate jndiTemplate) { this.jndiTemplate = (jndiTemplate != null ? jndiTemplate : new JndiTemplate()); }
@Test public void testEmptyStringMeansNullEnvironment() { JndiTemplateEditor je = new JndiTemplateEditor(); je.setAsText(""); JndiTemplate jt = (JndiTemplate) je.getValue(); assertTrue(jt.getEnvironment() == null); }
/** * Set the JNDI template to use for JNDI lookups. * @see org.springframework.jndi.JndiAccessor#setJndiTemplate */ public void setJndiTemplate(JndiTemplate jndiTemplate) { this.jndiLocator.setJndiTemplate(jndiTemplate); }
/** * Set whether the lookup occurs in a Java EE container, i.e. if the prefix * "java:comp/env/" needs to be added if the JNDI name doesn't already * contain it. PersistenceAnnotationBeanPostProcessor's default is "true". * @see org.springframework.jndi.JndiLocatorSupport#setResourceRef */ public void setResourceRef(boolean resourceRef) { this.jndiLocator.setResourceRef(resourceRef); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { Context ctx = (isEligible(invocation.getMethod()) ? this.jndiTemplate.getContext() : null); try { return invocation.proceed(); } finally { this.jndiTemplate.releaseContext(ctx); } }
/** * Execute the given JNDI context callback implementation. * @param contextCallback the JndiCallback implementation to use * @return a result object returned by the callback, or {@code null} * @throws NamingException thrown by the callback implementation * @see #createInitialContext */ @Nullable public <T> T execute(JndiCallback<T> contextCallback) throws NamingException { Context ctx = getContext(); try { return contextCallback.doInContext(ctx); } finally { releaseContext(ctx); } }
@Override public void afterPropertiesSet() throws NamingException { super.afterPropertiesSet(); if (this.lookupOnStartup) { Object object = lookup(); if (this.cache) { this.cachedObject = object; } else { this.targetClass = object.getClass(); } } }
/** * Perform an actual JNDI lookup for the given name via the JndiTemplate. * <p>If the name doesn't begin with "java:comp/env/", this prefix is added * if "resourceRef" is set to "true". * @param jndiName the JNDI name to look up * @return the obtained object * @throws NamingException if the JNDI lookup failed * @see #setResourceRef */ protected Object lookup(String jndiName) throws NamingException { return lookup(jndiName, null); }
/** * Obtain a JNDI context corresponding to this template's configuration. * Called by {@link #execute}; may also be called directly. * <p>The default implementation delegates to {@link #createInitialContext()}. * @return the JNDI context (never {@code null}) * @throws NamingException if context retrieval failed * @see #releaseContext */ public Context getContext() throws NamingException { return createInitialContext(); }
/** * Create a new {@code JndiPropertySource} with the given name * and a {@link JndiLocatorDelegate} configured to prefix any names with * "java:comp/env/". */ public JndiPropertySource(String name) { this(name, JndiLocatorDelegate.createDefaultResourceRefLocator()); }
/** * Set the JNDI environment to use for JNDI lookups. * Creates a JndiTemplate with the given environment settings. * @see #setJndiTemplate */ public void setJndiEnvironment(Properties jndiEnvironment) { this.jndiTemplate = new JndiTemplate(jndiEnvironment); }
/** * Set the JNDI template to use for JNDI lookups. * @see org.springframework.jndi.JndiAccessor#setJndiTemplate */ public void setJndiTemplate(JndiTemplate jndiTemplate) { this.jndiLocator.setJndiTemplate(jndiTemplate); }
/** * Set whether the lookup occurs in a Java EE container, i.e. if the prefix * "java:comp/env/" needs to be added if the JNDI name doesn't already * contain it. PersistenceAnnotationBeanPostProcessor's default is "true". * @see org.springframework.jndi.JndiLocatorSupport#setResourceRef */ public void setResourceRef(boolean resourceRef) { this.jndiLocator.setResourceRef(resourceRef); }
/** * Set the JNDI environment to use for JNDI lookups. * @see org.springframework.jndi.JndiAccessor#setJndiEnvironment */ public void setJndiEnvironment(Properties jndiEnvironment) { this.jndiLocator.setJndiEnvironment(jndiEnvironment); }
@Override public Object lookup(String jndiName) throws NamingException { return super.lookup(jndiName); }
/** * Set the JNDI template to use for JNDI lookups. * @see org.springframework.jndi.JndiAccessor#setJndiTemplate */ public void setJndiTemplate(JndiTemplate jndiTemplate) { this.jndiLocator.setJndiTemplate(jndiTemplate); }
/** * Set whether the lookup occurs in a Java EE container, i.e. if the prefix * "java:comp/env/" needs to be added if the JNDI name doesn't already * contain it. PersistenceAnnotationBeanPostProcessor's default is "true". * @see org.springframework.jndi.JndiLocatorSupport#setResourceRef */ public void setResourceRef(boolean resourceRef) { this.jndiLocator.setResourceRef(resourceRef); }
/** * Set the JNDI environment to use for JNDI lookups. * @see org.springframework.jndi.JndiAccessor#setJndiEnvironment */ public void setJndiEnvironment(Properties jndiEnvironment) { this.jndiLocator.setJndiEnvironment(jndiEnvironment); }