本文整理汇总了Java中javax.naming.NameNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java NameNotFoundException类的具体用法?Java NameNotFoundException怎么用?Java NameNotFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NameNotFoundException类属于javax.naming包,在下文中一共展示了NameNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRDNS
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* TestCase: get our local address and reverse look it up
*/
@Test
public void testRDNS() throws Exception {
InetAddress localhost = getLocalIPAddr();
try {
String s = DNS.reverseDns(localhost, null);
LOG.info("Local reverse DNS hostname is " + s);
} catch (NameNotFoundException | CommunicationException e) {
if (!localhost.isLinkLocalAddress() || localhost.isLoopbackAddress()) {
//these addresses probably won't work with rDNS anyway, unless someone
//has unusual entries in their DNS server mapping 1.0.0.127 to localhost
LOG.info("Reverse DNS failing as due to incomplete networking", e);
LOG.info("Address is " + localhost
+ " Loopback=" + localhost.isLoopbackAddress()
+ " Linklocal=" + localhost.isLinkLocalAddress());
}
}
}
示例2: unbind
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Unbinds the named object. Removes the terminal atomic name in name
* from the target context--that named by all but the terminal atomic
* part of name.
* <p>
* This method is idempotent. It succeeds even if the terminal atomic
* name is not bound in the target context, but throws
* NameNotFoundException if any of the intermediate contexts do not exist.
*
* @param name the name to bind; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NamingException if a naming exception is encountered
*/
@Override
public void unbind(String name)
throws NamingException {
File file = file(name);
if (file == null)
throw new NameNotFoundException(
sm.getString("resources.notFound", name));
if (!file.delete())
throw new NamingException
(sm.getString("resources.unbindFailed", name));
}
示例3: rename
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Binds a new name to the object bound to an old name, and unbinds the
* old name. Both names are relative to this context. Any attributes
* associated with the old name become associated with the new name.
* Intermediate contexts of the old name are not changed.
*
* @param oldName the name of the existing binding; may not be empty
* @param newName the name of the new binding; may not be empty
* @exception NameAlreadyBoundException if newName is already bound
* @exception NamingException if a naming exception is encountered
*/
@Override
public void rename(String oldName, String newName)
throws NamingException {
File file = file(oldName);
if (file == null)
throw new NameNotFoundException
(sm.getString("resources.notFound", oldName));
File newFile = new File(base, newName);
if (!file.renameTo(newFile)) {
throw new NamingException(sm.getString("resources.renameFail",
oldName, newName));
}
}
示例4: list
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are
* not included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
@Override
public NamingEnumeration<NameClassPair> list(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextEnumeration(bindings.values().iterator());
}
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name, name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).list(name.getSuffix(1));
}
示例5: listBindings
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the
* objects bound to them. The contents of any subcontexts are not
* included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the bindings in this context.
* Each element of the enumeration is of type Binding.
* @exception NamingException if a naming exception is encountered
*/
@Override
public NamingEnumeration<Binding> listBindings(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextBindingsEnumeration(bindings.values().iterator(), this);
}
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name, name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).listBindings(name.getSuffix(1));
}
示例6: validateLdapProperties_NameNotFoundException
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Bug 9280 - in case a NameNotFoundException probably the base DN is wrong
* so throw a suitable exception.
*/
@Test(expected = ValidationException.class)
public void validateLdapProperties_NameNotFoundException() throws Exception {
final String baseDN = "baseDN";
final Properties props = new Properties();
props.put(SettingType.LDAP_BASE_DN.name(), baseDN);
final LdapConnector connector = new LdapConnector(ldapAccess, props);
final String extCause = "some external cause";
when(
ldapAccess.dnSearch(any(Properties.class), anyString(),
anyString())).thenThrow(
new NameNotFoundException(extCause));
try {
connector.validateLdapProperties(new VOUserDetails());
} catch (ValidationException e) {
assertEquals(ReasonEnum.LDAP_BASE_DN_INVALID, e.getReason());
assertEquals(baseDN, e.getMessageParams()[0]);
// verify(asb.sessionCtx, times(1)).setRollbackOnly();
throw e;
}
}
示例7: lookup
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Look up the object with the given name in the current JNDI context.
* @param name the JNDI name of the object
* @return object found (cannot be {@code null}; if a not so well-behaved
* JNDI implementations returns null, a NamingException gets thrown)
* @throws NamingException if there is no object with the given
* name bound to JNDI
*/
public Object lookup(final String name) throws NamingException {
if (logger.isDebugEnabled()) {
logger.debug("Looking up JNDI object with name [" + name + "]");
}
return execute(new JndiCallback<Object>() {
@Override
public Object doInContext(Context ctx) throws NamingException {
Object located = ctx.lookup(name);
if (located == null) {
throw new NameNotFoundException(
"JNDI object with [" + name + "] not found: JNDI implementation returned null");
}
return located;
}
});
}
示例8: list
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are
* not included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration list(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextEnumeration(bindings.values().iterator());
}
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).list(name.getSuffix(1));
}
示例9: listBindings
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the
* objects bound to them. The contents of any subcontexts are not
* included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the bindings in this context.
* Each element of the enumeration is of type Binding.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration listBindings(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextBindingsEnumeration(bindings.values().iterator(), this);
}
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).listBindings(name.getSuffix(1));
}
示例10: list
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are
* not included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration list(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextEnumeration(bindings.elements());
}
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).list(name.getSuffix(1));
}
示例11: listBindings
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the
* objects bound to them. The contents of any subcontexts are not
* included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the bindings in this context.
* Each element of the enumeration is of type Binding.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration listBindings(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextBindingsEnumeration(bindings.elements());
}
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).listBindings(name.getSuffix(1));
}
示例12: testRDNS
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* TestCase: get our local address and reverse look it up
*/
@Test
public void testRDNS() throws Exception {
InetAddress localhost = getLocalIPAddr();
try {
String s = DNS.reverseDns(localhost, null);
LOG.info("Local revers DNS hostname is " + s);
} catch (NameNotFoundException e) {
if (!localhost.isLinkLocalAddress() || localhost.isLoopbackAddress()) {
//these addresses probably won't work with rDNS anyway, unless someone
//has unusual entries in their DNS server mapping 1.0.0.127 to localhost
LOG.info("Reverse DNS failing as due to incomplete networking", e);
LOG.info("Address is " + localhost
+ " Loopback=" + localhost.isLoopbackAddress()
+ " Linklocal=" + localhost.isLinkLocalAddress());
}
}
}
示例13: list
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are not
* included.
* <p>
* If a binding is added to or removed from this context, its effect on an
* enumeration previously returned is undefined.
*
* @param name
* the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type
* NameClassPair.
* @exception NamingException
* if a naming exception is encountered
*/
@Override
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextEnumeration(bindings.values().iterator());
}
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name, name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).list(name.getSuffix(1));
}
示例14: listBindings
import javax.naming.NameNotFoundException; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the objects
* bound to them. The contents of any subcontexts are not included.
* <p>
* If a binding is added to or removed from this context, its effect on an
* enumeration previously returned is undefined.
*
* @param name
* the name of the context to list
* @return an enumeration of the bindings in this context. Each element of
* the enumeration is of type Binding.
* @exception NamingException
* if a naming exception is encountered
*/
@Override
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextBindingsEnumeration(bindings.values().iterator(), this);
}
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name, name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).listBindings(name.getSuffix(1));
}
示例15: testLookupFails
import javax.naming.NameNotFoundException; //导入依赖的package包/类
@Test
public void testLookupFails() throws Exception {
NameNotFoundException ne = new NameNotFoundException();
String name = "foo";
final Context context = mock(Context.class);
given(context.lookup(name)).willThrow(ne);
JndiTemplate jt = new JndiTemplate() {
@Override
protected Context createInitialContext() {
return context;
}
};
try {
jt.lookup(name);
fail("Should have thrown NamingException");
}
catch (NameNotFoundException ex) {
// Ok
}
verify(context).close();
}