/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/**
* This is both a {@link Startup} service as well as our implementation of
* {@link InitialContextFactoryBuilder}. When GlassFish starts up, this
* startup service configures NamingManager with appropriate builder by calling
* {@link javax.naming.spi.NamingManager#setInitialContextFactoryBuilder}.
* Once the builder is setup, when ever new InitialContext() is called,
* builder can either instantiate {@link SerialInitContextFactory}, which is our
* implementation of {@link InitialContextFactory}, or any user specified
* InitialContextFactory class. While loading user specified class, it first
* uses Thread's context class loader and then CommonClassLoader.
*
* @author Sanjeeb.Sahoo@Sun.COM
*/
public class GlassFishNamingBuilder implements InitialContextFactoryBuilder, Startup, PostConstruct, PreDestroy
{
/**
* We use a naming builder in order to enable use of JNDI in OSGi context, because the builder gives us
* desired hooks to create appserver specific initial context without having to rely on thread's
* context class loader which is a unknown quantity in osgi environment. Use of a builder can lead to some
* probelamatic scenarios as discussed in issue #11997, so we allow user to disable it if they want. Having such
* configuration option is more of a workaround than a fix, but I have not been able to find a better solution
* so far.
*/
private static final String ALLOW_JNDI_FROM_OSGI = "com.sun.enterprise.naming.allowJndiLookupFromOSGi";
public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment) throws NamingException
{
if (environment != null)
{
// As per the documentation of Context.INITIAL_CONTEXT_FACTORY,
// it represents a fully qualified class name.
{
try
{
}
catch (Exception e)
{
"Cannot instantiate class: " + className);
ne.setRootCause(e);
throw ne;
}
}
}
// default case
return new SerialInitContextFactory();
}
{
}
{
try {
} catch (ClassNotFoundException e) {
// Not a significant error. Try with common class loader instead.
// Try using CommonClassLoader.
try {
} catch (ClassNotFoundException e2) {
_logger.logp(Level.WARNING, "GlassFishNamingBuilder", "loadClass", "Failed to load {0} using CommonClassLoader", new Object[]{className});
throw e2;
}
}
throw e;
}
}
public void postConstruct()
{
try
{
{
try
{
{
{
if (isUsingBuilder()) {
}
return null; //Nothing to return
}
});
}
catch (PrivilegedActionException e)
{
throw (NamingException) e.getCause();
}
}
else
{
if (isUsingBuilder()) {
}
}
}
catch (NamingException e)
{
throw new RuntimeException(e);
}
}
public void preDestroy()
{
if (isUsingBuilder()) {
}
return null;
}
});
} else {
if (isUsingBuilder()) {
}
}
}
private void resetInitialContextFactoryBuilder()
{
try
{
f.setAccessible(true);
}
catch (NoSuchFieldException e)
{
throw new RuntimeException(e);
}
catch (IllegalAccessException e)
{
throw new RuntimeException(e); // TODO(Sahoo): Proper Exception Handling
}
}
private boolean ifIbmJava6() {
return System.getProperty("java.vendor", "").equals("IBM Corporation") && System.getProperty("java.version").equals("1.6.0");
}
/**
* @return true if we are using NamingBuilder, else false.
*/
// We are using a system property, because NamingBuilder is a JDK wide singleton.
}
}