本文整理汇总了Java中javax.naming.NoInitialContextException.setRootCause方法的典型用法代码示例。如果您正苦于以下问题:Java NoInitialContextException.setRootCause方法的具体用法?Java NoInitialContextException.setRootCause怎么用?Java NoInitialContextException.setRootCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.NoInitialContextException
的用法示例。
在下文中一共展示了NoInitialContextException.setRootCause方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: simulateBuilderLessNamingManager
import javax.naming.NoInitialContextException; //导入方法依赖的package包/类
/**
* Builds {@link InitialContextFactory} from passed requested (
* {@link String}) class name
*
* @param requestedFactory
* @return {@link InitialContextFactory}
* @throws NoInitialContextException
*/
private InitialContextFactory simulateBuilderLessNamingManager(String requestedFactory)
throws NoInitialContextException {
InitialContextFactory factory;
Class<?> requestedClass;
try {
requestedClass = ClassUtils.initClassForName(requestedFactory);
Object instance = ClassUtils.instantiate(requestedClass);
factory = ObjectUtils.cast(instance, InitialContextFactory.class);
} catch (IOException ex) {
NoInitialContextException nex = new NoInitialContextException(COULD_NOT_FIND_ERROR);
nex.setRootCause(ex);
throw nex;
}
return factory;
}
示例2: testSerializable_Simple
import javax.naming.NoInitialContextException; //导入方法依赖的package包/类
/**
* Test serialize NoInitialContextException: write a
* NoInitialContextException object into a byte array, and read from it. The
* two objects should be equal.
*/
public void testSerializable_Simple() throws ClassNotFoundException,
IOException, InvalidNameException {
NoInitialContextException exception = new NoInitialContextException(
"Test exception Serializable: NoInitialContextException");
exception.setRemainingName(new CompositeName(
"www.apache.org/foundation"));
exception.setResolvedName(new CompositeName(
"http://www.apache.org/index.html"));
exception.setResolvedObj("This is a string object.");
exception.setRootCause(new NullPointerException("null pointer"));
// write to byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(exception);
byte[] buffer = baos.toByteArray();
oos.close();
baos.close();
// read from byte array
ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
ObjectInputStream ois = new ObjectInputStream(bais);
NoInitialContextException exception2 = (NoInitialContextException) ois
.readObject();
ois.close();
bais.close();
assertEquals(exception.getExplanation(), exception2.getExplanation());
assertEquals(exception.getResolvedObj(), exception2.getResolvedObj());
assertEquals(exception.getRemainingName(), exception2
.getRemainingName());
assertEquals(exception.getResolvedName(), exception2.getResolvedName());
assertEquals(exception.getRootCause().getMessage(), exception2
.getRootCause().getMessage());
assertEquals(exception.getRootCause().getClass(), exception2
.getRootCause().getClass());
}
示例3: testSerializable_compatibility
import javax.naming.NoInitialContextException; //导入方法依赖的package包/类
/**
* Test InvalidNameException serialization compatibility
*/
public void testSerializable_compatibility() throws InvalidNameException,
ClassNotFoundException, IOException {
ObjectInputStream ois = new ObjectInputStream(
getClass()
.getClassLoader()
.getResourceAsStream(
"/serialization/javax/naming/NoInitialContextException.ser"));
NoInitialContextException exception2 = (NoInitialContextException) ois
.readObject();
ois.close();
NoInitialContextException exception = new NoInitialContextException(
"Test exception Serializable: NoInitialContextException");
exception.setRemainingName(new CompositeName("www.apache.org/foundation"));
exception.setResolvedName(new CompositeName(
"http://www.apache.org/index.html"));
exception.setResolvedObj("This is a string object.");
exception.setRootCause(new NullPointerException("null pointer"));
assertEquals(exception.getExplanation(), exception2.getExplanation());
assertEquals(exception.getResolvedObj(), exception2.getResolvedObj());
assertEquals(exception.getRemainingName(), exception2
.getRemainingName());
assertEquals(exception.getResolvedName(), exception2.getResolvedName());
assertEquals(exception.getRootCause().getMessage(), exception2
.getRootCause().getMessage());
assertEquals(exception.getRootCause().getClass(), exception2
.getRootCause().getClass());
}
示例4: getInitialContext
import javax.naming.NoInitialContextException; //导入方法依赖的package包/类
/**
* Creates the initial context. If the initial object factory builder has
* been set with {@link #setObjectFactoryBuilder(ObjectFactoryBuilder)},
* the work is delegated to this builder. Otherwise, the method searches
* for the property Context.INITIAL_CONTEXT_FACTORY first in the passed
* table and then in the system properties. The value of this property is
* uses as a class name to install the context factory. The corresponding
* class must exist, be public and have the public parameterless constructor.
*
* @param environment the properties, used to create the context.
*
* @return the created context
*
* @throws NoInitialContextException if the initial builder is not set,
* the property Context.INITIAL_CONTEXT_FACTORY is missing of the
* class, named by this property, cannot be instantiated.
* @throws NamingException if throws by the context factory
*/
public static Context getInitialContext (Hashtable<?, ?> environment)
throws NamingException
{
InitialContextFactory icf = null;
if (icfb != null)
icf = icfb.createInitialContextFactory(environment);
else
{
String java_naming_factory_initial = null;
if (environment != null)
java_naming_factory_initial
= (String) environment.get (Context.INITIAL_CONTEXT_FACTORY);
if (java_naming_factory_initial == null)
java_naming_factory_initial =
System.getProperty (Context.INITIAL_CONTEXT_FACTORY);
if (java_naming_factory_initial == null)
throw new
NoInitialContextException ("Can't find property: "
+ Context.INITIAL_CONTEXT_FACTORY);
try
{
icf = (InitialContextFactory)Class.forName
(java_naming_factory_initial, true,
Thread.currentThread().getContextClassLoader())
.newInstance ();
}
catch (Exception exception)
{
NoInitialContextException e
= new NoInitialContextException
("Can't load InitialContextFactory class: "
+ java_naming_factory_initial);
e.setRootCause(exception);
throw e;
}
}
return icf.getInitialContext (environment);
}
示例5: getInitialContext
import javax.naming.NoInitialContextException; //导入方法依赖的package包/类
/**
* Creates the initial context. If the initial object factory builder has
* been set with {@link #setObjectFactoryBuilder(ObjectFactoryBuilder)},
* the work is delegated to this builder. Otherwise, the method searches
* for the property Context.INITIAL_CONTEXT_FACTORY first in the passed
* table and then in the system properties. The value of this property is
* uses as a class name to install the context factory. The corresponding
* class must exist, be public and have the public parameterless constructor.
*
* @param environment the properties, used to create the context.
*
* @return the created context
*
* @throws NoInitialContextException if the initial builder is not set,
* the property Context.INITIAL_CONTEXT_FACTORY is missing of the
* class, named by this property, cannot be instantiated.
* @throws NamingException if throws by the context factory
*/
public static Context getInitialContext (Hashtable<?, ?> environment)
throws NamingException
{
InitialContextFactory icf = null;
if (icfb != null)
icf = icfb.createInitialContextFactory(environment);
else
{
String java_naming_factory_initial = null;
if (environment != null)
java_naming_factory_initial
= (String) environment.get (Context.INITIAL_CONTEXT_FACTORY);
if (java_naming_factory_initial == null)
java_naming_factory_initial =
System.getProperty (Context.INITIAL_CONTEXT_FACTORY);
if (java_naming_factory_initial == null)
throw new
NoInitialContextException ("Can't find property: "
+ Context.INITIAL_CONTEXT_FACTORY);
try
{
icf = (InitialContextFactory)Class.forName
(java_naming_factory_initial, true,
Thread.currentThread().getContextClassLoader())
.newInstance ();
}
catch (Exception exception)
{
NoInitialContextException e
= new NoInitialContextException
("Can't load InitialContextFactory class: "
+ java_naming_factory_initial);
e.setRootCause(exception);
throw e;
}
}
return icf.getInitialContext (environment);
}