javax.naming.Binding类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(197)

本文整理了Java中javax.naming.Binding类的一些代码示例,展示了Binding类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Binding类的具体详情如下:
包路径:javax.naming.Binding
类名称:Binding

Binding介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

public static void tearDownRecursively(final Context c) throws Exception {
 for (NamingEnumeration<Binding> ne = c.listBindings(""); ne.hasMore(); ) {
   Binding b = ne.next();
   String name = b.getName();
   Object object = b.getObject();
   if (object instanceof Context) {
    JNDIUtil.tearDownRecursively((Context) object);
   }
   c.unbind(name);
 }
}

代码示例来源:origin: apache/geode

checkIsDestroyed();
Name parsedName = getParsedName(name);
if (parsedName.size() == 0) {
 Vector bindings = new Vector();
 Iterator iterat = ctxMaps.keySet().iterator();
 while (iterat.hasNext()) {
  String bindingName = (String) iterat.next();
  bindings.addElement(new Binding(bindingName, ctxMaps.get(bindingName)));
 Object subContext = ctxMaps.get(parsedName.get(0));
 if (subContext instanceof Context) {
  Name nextLayer = nameParser.parse("");
  if (parsedName.size() > 1) {
   nextLayer = parsedName.getSuffix(1);
  return ((Context) subContext).list(nextLayer);
 if (subContext == null && !ctxMaps.containsKey(parsedName.get(0))) {
  throw new NameNotFoundException(
    String.format("Name %s not found", name));
 } else {
  throw new NotContextException(String.format("Expected Context but found %s",
    subContext));

代码示例来源:origin: apache/geode

public static Map<String, String> getBindingNamesRecursively(Context ctx) throws Exception {
  Map<String, String> result = new HashMap<>();
  NamingEnumeration<Binding> enumeration = ctx.listBindings("");

  while (enumeration.hasMore()) {
   Binding binding = enumeration.next();
   String name = binding.getName();
   String separator = name.endsWith(":") ? "" : "/";
   Object o = binding.getObject();
   if (o instanceof Context) {
    Map<String, String> innerBindings = getBindingNamesRecursively((Context) o);
    innerBindings.forEach((k, v) -> result.put(name + separator + k, v));
   } else {
    result.put(name, binding.getClassName());
   }
  }

  return result;
 }
}

代码示例来源:origin: wildfly/wildfly

protected List<NameClassPair> found(final ContextNode contextNode) throws NamingException {
  final List<NameClassPair> nameClassPairs = new ArrayList<NameClassPair>();
  for (TreeNode childNode : contextNode.children.values()) {
    final Binding binding = childNode.binding;
    nameClassPairs.add(new NameClassPair(binding.getName(), binding.getClassName(), true));
  }
  return nameClassPairs;
}

代码示例来源:origin: stackoverflow.com

// call groovy expressions from Java code
Binding binding = new Binding();
binding.setVariable("foo", new Integer(2));
GroovyShell shell = new GroovyShell(binding);

Object value = shell.evaluate(groovyScript);

代码示例来源:origin: org.eclipse.jetty/jetty-jndi

if (cname.size() == 0)
String firstComponent = cname.get(0);
Object ctx = null;
    throw new NameNotFoundException ();
  ctx = binding.getObject();
      ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
      throw new NamingException (e.getMessage());
  throw new NotContextException();
return ((Context)ctx).listBindings (cname.getSuffix(1));

代码示例来源:origin: jboss.web/jbossweb

private Object nextElementInternal() throws NamingException {
  NamingEntry entry = (NamingEntry) iterator.next();
  
  // If the entry is a reference, resolve it
  if (entry.type == NamingEntry.REFERENCE
      || entry.type == NamingEntry.LINK_REF) {
    try {
      // A lookup will resolve the entry
      ctx.lookup(new CompositeName(entry.name));
    } catch (NamingException e) {
      throw e;
    } catch (Exception e) {
      NamingException ne = new NamingException(e.getMessage());
      ne.initCause(e);
      throw ne;
    }
  }
  
  return new Binding(entry.name, entry.value.getClass().getName(), 
            entry.value, true);
}

代码示例来源:origin: org.eclipse.jetty/jetty-jndi

Context c = (Context)ctx.lookup (name);
NameParser parser = c.getNameParser("");
NamingEnumeration enm = ctx.listBindings(name);
while (enm.hasMore())
  if (b.getObject() instanceof Context)
    map.putAll(flattenBindings (c, b.getName()));
    Name compoundName = parser.parse (c.getNameInNamespace());
    compoundName.add(b.getName());
    map.put (compoundName.toString(), b.getObject());

代码示例来源:origin: spring-projects/spring-framework

assertTrue("Correct DataSource registered", context1.lookup("java:comp/env/jdbc/myds") == ds);
assertTrue("Correct Object registered", context1.lookup("myobject") == obj);
while (bindingEnum.hasMoreElements()) {
  Binding binding = (Binding) bindingEnum.nextElement();
  bindingMap.put(binding.getName(), binding);
assertTrue("Correct jdbc subcontext", bindingMap.get("jdbc").getObject() instanceof Context);
assertTrue("Correct jdbc subcontext", SimpleNamingContext.class.getName().equals(bindingMap.get("jdbc").getClassName()));
Context jdbcContext = (Context) context3.lookup("jdbc");
while (subBindingEnum.hasMoreElements()) {
  Binding binding = (Binding) subBindingEnum.nextElement();
  subBindingMap.put(binding.getName(), binding);
assertTrue("Correct DataSource registered", ds.equals(subBindingMap.get("myds").getObject()));
assertTrue("Correct DataSource registered", StubDataSource.class.getName().equals(subBindingMap.get("myds").getClassName()));
assertTrue("Correct DataSource registered", ds.equals(subBindingMap.get("mydsX").getObject()));
assertTrue("Correct DataSource registered", StubDataSource.class.getName().equals(subBindingMap.get("mydsX").getClassName()));
assertTrue("Correct Integer registered", i.equals(bindingMap.get("myinteger").getObject()));
assertTrue("Correct Integer registered", Integer.class.getName().equals(bindingMap.get("myinteger").getClassName()));
assertTrue("Correct String registered", s.equals(bindingMap.get("mystring").getObject()));
assertTrue("Correct String registered", String.class.getName().equals(bindingMap.get("mystring").getClassName()));
context1.createSubcontext("jdbc").bind("sub/subds", ds);

代码示例来源:origin: crashub/crash

@Override
 public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
  if (name == "") {
   List<Binding> l = new ArrayList<Binding>();
   l.add(new Binding("String", "Bar", ""));
   l.add(new Binding("ArrayList", "Bar", new ArrayList()));
   return new Bindings(l);
  } else {
   throw new NamingException();
  }
 }
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server

public Binding next()
  throws NamingException
{
  Binding b = (Binding)_delegate.next();
  return new Binding (b.getName(), b.getClassName(), b.getObject(), true);
}

代码示例来源:origin: apache/geode

for (NamingEnumeration en = c.listBindings(name); en.hasMore();) {
 Binding b = (Binding) en.next();
 if (b.getName().equals("datasource")) {
  assertEquals(b.getObject(), dataSourceContext);
  datasourceFoundFlg = true;
  Context nextCon = (Context) b.getObject();
  for (NamingEnumeration en1 = nextCon.listBindings(""); en1.hasMore();) {
   Binding b1 = (Binding) en1.next();
   if (b1.getName().equals("sub41")) {
    assertEquals(b1.getObject(), obj1);
    datasourceO1FoundFlg = true;
   } else if (b1.getName().equals("sub43")) {
    assertNull(b1.getObject());
    datasourceNullFoundFlg = true;
 } else if (b.getName().equals("sub42")) {
  assertEquals(b.getObject(), obj2);
  o2FoundFlg = true;

代码示例来源:origin: com.googlecode.mycontainer/mycontainer-kernel

@SuppressWarnings("unchecked")
public NamingEnumeration<Binding> listBindings(Name name)
    throws NamingException {
  if (name.isEmpty()) {
    List<Binding> bindings = new ArrayList<Binding>();
    for (Map.Entry<String, Object> entry : elements.entrySet()) {
      Binding binding = new Binding(entry.getKey(), entry.getValue());
      bindings.add(binding);
    }
    return new MyNamingEnumeration<Binding>(bindings.iterator());
  }
  Object obj = lookup(name);
  if (!(obj instanceof Context)) {
    throw new NamingException("Name is not context: " + name);
  }
  Context context = (Context) obj;
  NamingEnumeration<Binding> listBindings = context.listBindings("");
  return listBindings;
}

代码示例来源:origin: org.jvnet.hudson.winstone/winstone

public Object next() throws NamingException {
  if (this.nameEnumeration == null)
    throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES
        .getString("WinstoneBindingEnumeration.AlreadyClosed"));
  String name = (String) this.nameEnumeration.nextElement();
  Object value = this.bindings.get(name);
  try {
    value = NamingManager.getObjectInstance(value, new CompositeName()
        .add(name), this.context, this.contextEnvironment);
  } catch (Throwable err) {
    NamingException errNaming = new NamingException(
        ContainerJNDIManager.JNDI_RESOURCES
            .getString("WinstoneBindingEnumeration.FailedToGetInstance"));
    errNaming.setRootCause(err);
    throw errNaming;
  }
  return new Binding(name, value);
}

代码示例来源:origin: EvoSuite/evosuite

@Override
public void rename(String oldName, String newName) throws NamingException {
  if(oldName==null || newName == null) {
    throw new NamingException("Null name");
  }
  if(bindings.containsKey(newName)) {
    throw new NameAlreadyBoundException("Already bounded object for: "+newName);
  }
  if(!bindings.containsKey(oldName)) {
    throw new NamingException("No "+oldName+" is bounded");
  }
  Binding r = bindings.remove(oldName);
  Binding n = new Binding(newName, r.getObject());
  bindings.put(newName, n);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-dataconnectivity

public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
   Log.getLogger().entering(getClass().getName(), "listBindings", name); //NOI18N
  if (name.size() == 0) {
    Vector v = new Vector();
    for (Iterator i = bindings.keySet().iterator(); i.hasNext();) {
      String key = (String)i.next();
      Object obj = bindings.get(key);
      if (obj instanceof Subcontext) {
        obj = ((Subcontext)obj).subcontext;
      }
      v.add(new Binding(key, obj, true));
    }
    return new DesignTimeNamingEnumeration(v.elements());
  } else {
    Object obj = lookup(name);
    if (!(obj instanceof Context)) {
      throw new NameNotFoundException(name.toString());
      } else {
      return ((Context)obj).listBindings(new CompositeName());
    }
  }
   
   
}

代码示例来源:origin: EvoSuite/evosuite

@Override
public Object lookup(String name) throws NamingException {
  if(name==null) {
    throw new NamingException("Null name");
  }
  /*
    We need to keep track of what the SUT has tried to look up,
    so we can generate in the next generations
   */
  TestDataJavaEE.getInstance().accessLookUpContextName(name);
  Binding b =  bindings.get(name);
  if(b == null) {
    return null;
  } else {
    return b.getObject();
  }
}

代码示例来源:origin: wildfly/wildfly

protected Object foundReferenceInsteadOfContext(final BindingNode bindingNode) throws NamingException {
    final Name remainingName = targetName.getSuffix(bindingNode.fullName.size());
    final Object boundObject = bindingNode.binding.getObject();
    checkReferenceForContinuation(remainingName, boundObject);
    return new ResolveResult(boundObject, remainingName);
  }
}

代码示例来源:origin: wildfly/wildfly

obj = NamingManager.getObjectInstance(obj, cname, _ctx, _env);
} catch (NamingException e) {
  throw e;
} catch (Exception e) {
  NamingException ne = IIOPLogger.ROOT_LOGGER.errorGeneratingObjectViaFactory();
  ne.setRootCause(e);
  throw ne;
javax.naming.Binding jbndg = new javax.naming.Binding(cnameStr, obj);
jbndg.setNameInNamespace(fullName);
return jbndg;

代码示例来源:origin: spring-projects/spring-framework

@Override
  protected Binding createObject(String strippedName, Object obj) {
    return new Binding(strippedName, obj);
  }
}

相关文章