本文整理了Java中javax.naming.Context.rebind()
方法的一些代码示例,展示了Context.rebind()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.rebind()
方法的具体详情如下:
包路径:javax.naming.Context
类名称:Context
方法名:rebind
暂无
代码示例来源:origin: apache/shiro
public Object doInContext(Context ctx) throws NamingException {
ctx.rebind(name, object);
return null;
}
});
代码示例来源:origin: wildfly/wildfly
@Override
protected void doOperation(String name, Object object) throws NamingException {
localContext.rebind(name, object);
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public void rebind(String name, Object obj) throws NamingException {
context.rebind(name, obj);
}
代码示例来源:origin: wildfly/wildfly
@Override
public void rebind(Name name, Object obj) throws NamingException {
context.rebind(name, obj);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Rebind the given object to the current JNDI context, using the given name.
* Overwrites any existing binding.
* @param name the JNDI name of the object
* @param object the object to rebind
* @throws NamingException thrown by JNDI
*/
public void rebind(final String name, final Object object) throws NamingException {
if (logger.isDebugEnabled()) {
logger.debug("Rebinding JNDI object with name [" + name + "]");
}
execute(ctx -> {
ctx.rebind(name, object);
return null;
});
}
代码示例来源:origin: org.springframework/spring-context
/**
* Rebind the given object to the current JNDI context, using the given name.
* Overwrites any existing binding.
* @param name the JNDI name of the object
* @param object the object to rebind
* @throws NamingException thrown by JNDI
*/
public void rebind(final String name, final Object object) throws NamingException {
if (logger.isDebugEnabled()) {
logger.debug("Rebinding JNDI object with name [" + name + "]");
}
execute(ctx -> {
ctx.rebind(name, object);
return null;
});
}
代码示例来源:origin: wildfly/wildfly
@Override
public void rebind(final String name, final Object obj) throws NamingException {
CNCtxFactory.INSTANCE.getInitialContext(environment).rebind(name, obj);
}
代码示例来源:origin: wildfly/wildfly
@Override
public void rebind(final Name name, final Object obj) throws NamingException {
CNCtxFactory.INSTANCE.getInitialContext(environment).rebind(name, obj);
}
代码示例来源:origin: apache/geode
private static void validateAndBindDataSource(Context context, String jndiName,
DataSource dataSource) throws NamingException, DataSourceCreateException {
try (Connection connection = dataSource.getConnection()) {
} catch (SQLException sqlEx) {
closeDataSource(dataSource);
throw new DataSourceCreateException(
"Failed to connect to \"" + jndiName + "\". See log for details", sqlEx);
}
context.rebind("java:/" + jndiName, dataSource);
dataSourceMap.put(jndiName, dataSource);
if (logger.isDebugEnabled()) {
logger.debug("Bound java:/" + jndiName + " to Context");
}
}
代码示例来源:origin: wildfly/wildfly
/**
* Context.rebind() requires that all intermediate contexts and the target context (that named by
* all but terminal atomic component of the name) must already exist, otherwise
* NameNotFoundException is thrown. This method behaves similar to Context.rebind(), but creates
* intermediate contexts, if necessary.
*/
public static void rebind(final Context c, final String jndiName, final Object o) throws NamingException {
Context context = c;
String name = jndiName;
int idx = jndiName.lastIndexOf('/');
if (idx != -1) {
context = JNDIUtil.createContext(c, jndiName.substring(0, idx));
name = jndiName.substring(idx + 1);
}
boolean failed = false;
try {
context.rebind(name, o);
} catch (Exception ignored) {
failed = true;
}
if (failed) {
context.bind(name, o);
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public void rebind(final Name name, final Object obj) throws NamingException {
Assert.checkNotNullParam("name", name);
final ReparsedName reparsedName = reparse(name);
ContextResult result = getProviderContext(reparsedName.getUrlScheme());
if(result.oldStyle) {
result.context.rebind(name, obj);
} else {
result.context.rebind(reparsedName.getName(), obj);
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public void rebind(final String name, final Object obj) throws NamingException {
Assert.checkNotNullParam("name", name);
final ReparsedName reparsedName = reparse(getNameParser().parse(name));
ContextResult result = getProviderContext(reparsedName.getUrlScheme());
if(result.oldStyle) {
result.context.rebind(name, obj);
} else {
result.context.rebind(reparsedName.getName(), obj);
}
}
代码示例来源:origin: wildfly/wildfly
/**
* Rebind val to name in ctx, and make sure that all intermediate contexts exist
*
* @param ctx the parent JNDI Context under which value will be bound
* @param name the name relative to ctx where value will be bound
* @param value the value to bind.
* @throws NamingException for any error
*/
public static void rebind(final Context ctx, final Name name, final Object value) throws NamingException {
final int size = name.size();
final String atom = name.get(size - 1);
final Context parentCtx = createSubcontext(ctx, name.getPrefix(size - 1));
parentCtx.rebind(atom, value);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testRebind() throws Exception {
Object o = new Object();
String name = "foo";
final Context context = mock(Context.class);
JndiTemplate jt = new JndiTemplate() {
@Override
protected Context createInitialContext() {
return context;
}
};
jt.rebind(name, o);
verify(context).rebind(name, o);
verify(context).close();
}
代码示例来源:origin: apache/geode
@Test
public void mapDataSourceWithGetConnectionSuccessClosesConnectionAndRebinds() throws Exception {
Map<String, String> inputs = new HashMap<>();
Context context = mock(Context.class);
DataSource dataSource = mock(DataSource.class);
Connection connection = mock(Connection.class);
when(dataSource.getConnection()).thenReturn(connection);
DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
when(dataSourceFactory.getSimpleDataSource(any())).thenReturn(dataSource);
inputs.put("type", "SimpleDataSource");
String jndiName = "myJndiBinding";
inputs.put("jndi-name", jndiName);
JNDIInvoker.mapDatasource(inputs, null, dataSourceFactory, context);
verify(connection).close();
verify(context).rebind((String) any(), same(dataSource));
}
}
代码示例来源:origin: apache/geode
@Test
public void mapDataSourceWithGetConnectionExceptionThrowsDataSourceCreateException()
throws Exception {
Map<String, String> inputs = new HashMap<>();
Context context = mock(Context.class);
DataSource dataSource = mock(DataSource.class);
SQLException exception = mock(SQLException.class);
doThrow(exception).when(dataSource).getConnection();
DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
when(dataSourceFactory.getSimpleDataSource(any())).thenReturn(dataSource);
inputs.put("type", "SimpleDataSource");
String jndiName = "myJndiBinding";
inputs.put("jndi-name", jndiName);
Throwable thrown =
catchThrowable(() -> JNDIInvoker.mapDatasource(inputs, null, dataSourceFactory, context));
assertThat(thrown).isInstanceOf(DataSourceCreateException.class)
.hasMessage("Failed to connect to \"" + jndiName + "\". See log for details");
verify(context, never()).rebind((String) any(), any());
}
代码示例来源:origin: wildfly/wildfly
public void rebind(Name name, Object object) throws NamingException {
final ParsedName parsedName = parse(name);
final Context namespaceContext = findContext(name, parsedName);
if (namespaceContext == null)
super.rebind(parsedName.remaining(), object);
else
namespaceContext.rebind(parsedName.remaining(), object);
}
代码示例来源:origin: spring-projects/spring-framework
context1.rebind("myinteger", i);
String s = "";
context2.bind("mystring", s);
代码示例来源:origin: wildfly/wildfly
/**
* Converts the "Name" name into a NameComponent[] object and
* performs the rebind operation. Uses callBindOrRebind. Throws an
* invalid name exception if the name is empty. We must have a name
* to rebind the object to even if we are working within the current
* context.
*
* @param name string
* @param obj Object to be bound.
* @throws NamingException See callBindOrRebind
*/
public void rebind(Name name, java.lang.Object obj)
throws NamingException {
if (name.size() == 0) {
throw IIOPLogger.ROOT_LOGGER.invalidEmptyName();
}
NameComponent[] path = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.nameToCosName(name);
try {
callBindOrRebind(path, name, obj, true);
} catch (CannotProceedException e) {
javax.naming.Context cctx = getContinuationContext(e);
cctx.rebind(e.getRemainingName(), obj);
}
}
代码示例来源:origin: wildfly/wildfly
public void rebind(final Name name, final Object obj) throws NamingException {
Assert.checkNotNullParam("name", name);
if (name.isEmpty()) {
throw log.invalidEmptyName();
}
if (name instanceof CompositeName) {
final String first = name.get(0);
final Name firstName = getNativeNameParser().parse(first);
if (name.size() == 1) {
rebindNative(firstName, obj);
return;
}
final Object next = lookup(firstName);
if (next instanceof Context) {
final Context context = (Context) next;
try {
context.rebind(name.getSuffix(1), obj);
} finally {
NamingUtils.safeClose(context);
}
} else {
throw log.notContextInCompositeName(first);
}
} else {
rebindNative(name, obj);
}
}
内容来源于网络,如有侵权,请联系作者删除!