Java Code Examples for javax.naming.Binding#getObject()

The following examples show how to use javax.naming.Binding#getObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationContext.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * List resource paths (recursively), and store all of them in the given
 * Set.
 */
private static void listCollectionPaths(Set<String> set,
        DirContext resources, String path) throws NamingException {

    Enumeration<Binding> childPaths = resources.listBindings(path);
    while (childPaths.hasMoreElements()) {
        Binding binding = childPaths.nextElement();
        String name = binding.getName();
        StringBuilder childPath = new StringBuilder(path);
        if (!"/".equals(path) && !path.endsWith("/"))
            childPath.append("/");
        childPath.append(name);
        Object object = binding.getObject();
        if (object instanceof DirContext) {
            childPath.append("/");
        }
        set.add(childPath.toString());
    }

}
 
Example 2
Source File: ContextMapperCallbackHandlerWithControls.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
public T getObjectFromNameClassPair(final NameClassPair nameClassPair) throws NamingException{
	if (!(nameClassPair instanceof Binding)) {
		throw new IllegalArgumentException("Parameter must be an instance of Binding");
	}

	Binding binding = (Binding) nameClassPair;
	Object object = binding.getObject();
	if (object == null) {
		throw new ObjectRetrievalException("Binding did not contain any object.");
	}
	T result;
	if (nameClassPair instanceof HasControls) {
		result = mapper.mapFromContextWithControls(object, (HasControls) nameClassPair);
	}
	else {
		result = mapper.mapFromContext(object);
	}
	return result;
}
 
Example 3
Source File: ContextMapperCallbackHandlerWithControls.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
public Object getObjectFromNameClassPair(final NameClassPair nameClassPair) {
	if (!(nameClassPair instanceof Binding)) {
		throw new IllegalArgumentException("Parameter must be an instance of Binding");
	}

	Binding binding = (Binding) nameClassPair;
	Object object = binding.getObject();
	if (object == null) {
		throw new ObjectRetrievalException("Binding did not contain any object.");
	}
	Object result = null;
	if (nameClassPair instanceof HasControls) {
		result = mapper.mapFromContextWithControls(object, (HasControls) nameClassPair);
	}
	else {
		result = mapper.mapFromContext(object);
	}
	return result;
}
 
Example 4
Source File: ApplicationContext.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * List resource paths (recursively), and store all of them in the given
 * Set.
 */
private static void listCollectionPaths(Set<String> set,
        DirContext resources, String path) throws NamingException {

    Enumeration<Binding> childPaths = resources.listBindings(path);
    while (childPaths.hasMoreElements()) {
        Binding binding = childPaths.nextElement();
        String name = binding.getName();
        StringBuilder childPath = new StringBuilder(path);
        if (!"/".equals(path) && !path.endsWith("/"))
            childPath.append("/");
        childPath.append(name);
        Object object = binding.getObject();
        if (object instanceof DirContext) {
            childPath.append("/");
        }
        set.add(childPath.toString());
    }

}
 
Example 5
Source File: JndiBinding.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private static JndiBinding createJndiBinding(String path, Binding binding) {
	final String name = getBindingName(path, binding);
	final String className = binding.getClassName();
	final Object object = binding.getObject();
	final String contextPath;
	final String value;
	if (object instanceof Context
			// "javax.naming.Context".equals(className) nécessaire pour le path "comp" dans JBoss 6.0
			|| "javax.naming.Context".equals(className)
			// pour jetty :
			|| object instanceof Reference
					&& "javax.naming.Context".equals(((Reference) object).getClassName())) {
		if (!path.isEmpty()) {
			contextPath = path + '/' + name;
		} else {
			// nécessaire pour jonas 5.1.0
			contextPath = name;
		}
		value = null;
	} else {
		contextPath = null;
		value = formatValue(object);
	}
	return new JndiBinding(name, className, contextPath, value);
}
 
Example 6
Source File: ContextMapperCallbackHandler.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
/**
   * Cast the NameClassPair to a {@link Binding} and pass its object to
   * the ContextMapper.
   * 
   * @param nameClassPair
   *            a Binding instance.
   * @return the Object returned from the mapper.
   * @throws NamingException if an error occurs.
   * @throws ObjectRetrievalException if the object of the nameClassPair is null.
   */
  public T getObjectFromNameClassPair(NameClassPair nameClassPair) throws NamingException {
if (!(nameClassPair instanceof Binding)) {
	throw new IllegalArgumentException("Parameter must be an instance of Binding");
}

Binding binding = (Binding) nameClassPair;
      Object object = binding.getObject();
      if (object == null) {
          throw new ObjectRetrievalException(
                  "Binding did not contain any object.");
      }
      return mapper.mapFromContext(object);
  }
 
Example 7
Source File: ManagerServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * List the resources of the given context.
 * @param writer Writer to render to
 * @param prefix Path for recursion
 * @param namingContext The naming context for lookups
 * @param type Fully qualified class name of the resource type of interest,
 *  or <code>null</code> to list resources of all types
 * @param smClient i18n support for current client's locale
 */
protected void printResources(PrintWriter writer, String prefix,
                              javax.naming.Context namingContext,
                              String type,
                              StringManager smClient) {
    try {
        NamingEnumeration<Binding> items = namingContext.listBindings("");
        while (items.hasMore()) {
            Binding item = items.next();
            Object obj = item.getObject();
            if (obj instanceof javax.naming.Context) {
                printResources(writer, prefix + item.getName() + "/",
                        (javax.naming.Context) obj, type, smClient);
            } else {
                if (type != null && (obj == null ||
                        !IntrospectionUtils.isInstance(obj.getClass(), type))) {
                    continue;
                }
                writer.print(prefix + item.getName());
                writer.print(':');
                writer.print(item.getClassName());
                // Do we want a description if available?
                writer.println();
            }
        }
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log("ManagerServlet.resources[" + type + "]", t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }
}
 
Example 8
Source File: JndiTreeBrowser.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void runOnTree(final JndiNodeWorker worker) throws NamingException {
    final NamingEnumeration<Binding> ne = context.listBindings(ROOT);
    while (ne.hasMoreElements()) {
        final Binding current = ne.next();
        final Object obj = current.getObject();
        worker.doWork(path, current.getName(), obj);
        if (obj instanceof Context) {
            runOnJndiTree((Context) obj, worker,
                path + '/' + current.getName());
        }
    }
}
 
Example 9
Source File: Debug.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static void contextToMap(final Context context, final String baseName, final Map<String, Object> results) throws NamingException {
    final NamingEnumeration<Binding> namingEnumeration = context.listBindings("");
    while (namingEnumeration.hasMoreElements()) {
        final Binding binding = namingEnumeration.nextElement();
        final String name = binding.getName();
        final String fullName = baseName + name;
        final Object object = binding.getObject();
        results.put(fullName, object);
        if (object instanceof Context) {
            contextToMap((Context) object, fullName + "/", results);
        }
    }
}
 
Example 10
Source File: JNDIUtil.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
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);
   }
}
 
Example 11
Source File: JNDITestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Stops all existing ActiveMQConnectionFactory in Context.
 *
 * @throws javax.naming.NamingException
 */
@Override
protected void tearDown() throws NamingException, JMSException {
   NamingEnumeration<Binding> iter = context.listBindings("");
   while (iter.hasMore()) {
      Binding binding = iter.next();
      Object connFactory = binding.getObject();
      if (connFactory instanceof ActiveMQConnectionFactory) {
         // ((ActiveMQConnectionFactory) connFactory).stop();
      }
   }
}
 
Example 12
Source File: JNDITestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void assertBinding(Binding binding) throws NamingException {
   Object object = binding.getObject();
   assertTrue("Should have got a child context but got: " + object, object instanceof Context);

   Context childContext = (Context) object;
   NamingEnumeration<Binding> iter = childContext.listBindings("");
   while (iter.hasMore()) {
      Binding destinationBinding = iter.next();
      LOG.info("Found destination: " + destinationBinding.getName());
      Object destination = destinationBinding.getObject();
      assertTrue("Should have a Destination but got: " + destination, destination instanceof Destination);
   }
}
 
Example 13
Source File: ContextTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all entries from the specified context, including subcontexts.
 * 
 * @param context context ot clear
 */
private void clearContext(Context context)
throws NamingException {
  
  for (NamingEnumeration e = context.listBindings(""); e
  .hasMoreElements();) {
    Binding binding = (Binding) e.nextElement();
    if (binding.getObject() instanceof Context) {
      clearContext((Context) binding.getObject());
    }
    context.unbind(binding.getName());
  }
  
}
 
Example 14
Source File: ManagerServlet.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * List the resources of the given context.
 */
protected void printResources(PrintWriter writer, String prefix,
                              javax.naming.Context namingContext,
                              String type, Class<?> clazz,
                              StringManager smClient) {

    try {
        NamingEnumeration<Binding> items = namingContext.listBindings("");
        while (items.hasMore()) {
            Binding item = items.next();
            if (item.getObject() instanceof javax.naming.Context) {
                printResources
                    (writer, prefix + item.getName() + "/",
                     (javax.naming.Context) item.getObject(), type, clazz,
                     smClient);
            } else {
                if ((clazz != null) &&
                    (!(clazz.isInstance(item.getObject())))) {
                    continue;
                }
                writer.print(prefix + item.getName());
                writer.print(':');
                writer.print(item.getClassName());
                // Do we want a description if available?
                writer.println();
            }
        }
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log("ManagerServlet.resources[" + type + "]", t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
Example 15
Source File: ContextTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all entries from the specified context, including subcontexts.
 * 
 * @param context context ot clear
 */
private void clearContext(Context context)
throws NamingException {
  
  for (NamingEnumeration e = context.listBindings(""); e
  .hasMoreElements();) {
    Binding binding = (Binding) e.nextElement();
    if (binding.getObject() instanceof Context) {
      clearContext((Context) binding.getObject());
    }
    context.unbind(binding.getName());
  }
  
}
 
Example 16
Source File: ManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * List the resources of the given context.
 */
protected void printResources(PrintWriter writer, String prefix,
                              javax.naming.Context namingContext,
                              String type, Class<?> clazz,
                              StringManager smClient) {

    try {
        NamingEnumeration<Binding> items = namingContext.listBindings("");
        while (items.hasMore()) {
            Binding item = items.next();
            if (item.getObject() instanceof javax.naming.Context) {
                printResources
                    (writer, prefix + item.getName() + "/",
                     (javax.naming.Context) item.getObject(), type, clazz,
                     smClient);
            } else {
                if ((clazz != null) &&
                    (!(clazz.isInstance(item.getObject())))) {
                    continue;
                }
                writer.print(prefix + item.getName());
                writer.print(':');
                writer.print(item.getClassName());
                // Do we want a description if available?
                writer.println();
            }
        }
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log("ManagerServlet.resources[" + type + "]", t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
Example 17
Source File: ContextTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private void verifyListBindings(Context c, String name,
    Object obj1, Object obj2) throws NamingException {
  
  boolean datasourceFoundFlg = false;
  boolean o2FoundFlg = false;
  boolean datasourceO1FoundFlg = false;
  boolean datasourceNullFoundFlg = false;
  
  // List bindings for the specified context
  for (NamingEnumeration en = c.listBindings(name); en
  .hasMore();) {
    Binding b = (Binding) en.next();
    if (b.getName().equals("datasource")) {
      assertEquals(b.getObject(), datasourceCtx);
      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")) {
          // check for null object
          assertNull(b1.getObject());
          datasourceNullFoundFlg = true;
        }
      }
    }
    else if (b.getName().equals("sub42")) {
      assertEquals(b.getObject(), obj2);
      o2FoundFlg = true;
    }
  }
  if (!(datasourceFoundFlg && o2FoundFlg
      && datasourceO1FoundFlg && datasourceNullFoundFlg)) {
    fail();
  }
}
 
Example 18
Source File: ContextTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private void verifyListBindings(Context c, String name,
    Object obj1, Object obj2) throws NamingException {
  
  boolean datasourceFoundFlg = false;
  boolean o2FoundFlg = false;
  boolean datasourceO1FoundFlg = false;
  boolean datasourceNullFoundFlg = false;
  
  // List bindings for the specified context
  for (NamingEnumeration en = c.listBindings(name); en
  .hasMore();) {
    Binding b = (Binding) en.next();
    if (b.getName().equals("datasource")) {
      assertEquals(b.getObject(), datasourceCtx);
      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")) {
          // check for null object
          assertNull(b1.getObject());
          datasourceNullFoundFlg = true;
        }
      }
    }
    else if (b.getName().equals("sub42")) {
      assertEquals(b.getObject(), obj2);
      o2FoundFlg = true;
    }
  }
  if (!(datasourceFoundFlg && o2FoundFlg
      && datasourceO1FoundFlg && datasourceNullFoundFlg)) {
    fail();
  }
}