List of usage examples for javax.naming Binding getObject
public Object getObject()
From source file:com.jsmartframework.web.manager.BeanHandler.java
private void initJndiMapping() { try {/*from ww w.ja v a2s . c om*/ String lookupName = CONFIG.getContent().getEjbLookup(); initialContext = new InitialContext(); // For glassfish implementation NamingEnumeration<Binding> bindList = initialContext.listBindings(""); while (bindList.hasMore()) { Binding bind = bindList.next(); if (bind != null && ("java:" + lookupName).equals(bind.getName()) && bind.getObject() instanceof Context) { lookupInContext((Context) bind.getObject(), "java:" + lookupName); } } // For Jboss implementation if (jndiMapping.isEmpty()) { lookupInContext((Context) initialContext.lookup("java:" + lookupName), "java:" + lookupName); } } catch (Exception ex) { LOGGER.log(Level.WARNING, "JNDI for EJB mapping could not be initialized: " + ex.getMessage()); } }
From source file:org.apache.activemq.jndi.JNDITestSupport.java
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); }// w w w. java 2 s. c om }
From source file:org.apache.activemq.jndi.JNDITestSupport.java
/** * Stops all existing ActiveMQConnectionFactory in Context. * * @throws javax.naming.NamingException/*from w w w . j av a2 s . c om*/ */ @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(); } } }
From source file:org.apache.openejb.assembler.classic.Assembler.java
public synchronized void destroy() { try {/* w ww . ja va 2 s.c om*/ EjbTimerServiceImpl.shutdown(); } catch (Exception e) { logger.warning("Unable to shutdown scheduler", e); } logger.debug("Undeploying Applications"); Assembler assembler = this; for (AppInfo appInfo : assembler.getDeployedApplications()) { try { assembler.destroyApplication(appInfo.path); } catch (UndeployException e) { logger.error("Undeployment failed: " + appInfo.path, e); } catch (NoSuchApplicationException e) { } } NamingEnumeration<Binding> namingEnumeration = null; try { namingEnumeration = containerSystem.getJNDIContext().listBindings("openejb/Resource"); } catch (NamingException ignored) { // no resource adapters were created } while (namingEnumeration != null && namingEnumeration.hasMoreElements()) { Binding binding = namingEnumeration.nextElement(); Object object = binding.getObject(); if (object instanceof ResourceAdapter) { ResourceAdapter resourceAdapter = (ResourceAdapter) object; try { logger.info("Stopping ResourceAdapter: " + binding.getName()); if (logger.isDebugEnabled()) { logger.debug("Stopping ResourceAdapter: " + binding.getClassName()); } resourceAdapter.stop(); } catch (Throwable t) { logger.fatal("ResourceAdapter Shutdown Failed: " + binding.getName(), t); } } else if (object instanceof org.apache.commons.dbcp.BasicDataSource) { logger.info("Closing DataSource: " + binding.getName()); try { ((org.apache.commons.dbcp.BasicDataSource) object).close(); } catch (Throwable t) { //Ignore } } else if (logger.isDebugEnabled()) { logger.debug("Not processing resource on destroy: " + binding.getClassName()); } } SystemInstance.get().removeComponent(OpenEjbConfiguration.class); SystemInstance.get().removeComponent(JtaEntityManagerRegistry.class); SystemInstance.get().removeComponent(TransactionSynchronizationRegistry.class); SystemInstance.get().removeComponent(EjbResolver.class); SystemInstance.reset(); }
From source file:org.springframework.ejb.support.JndiEnvironmentBeanDefinitionReader.java
/** * Creates new JNDIBeanFactory/*from ww w . ja v a 2 s . com*/ * @param root likely to be "java:comp/env" */ public JndiEnvironmentBeanDefinitionReader(BeanDefinitionRegistry beanFactory, String root) throws BeansException { // We'll take everything from the NamingContext and dump it in a // Properties object, so that the superclass can efficiently manipulate it // after we've closed the context. HashMap m = new HashMap(); Context initCtx = null; try { initCtx = new InitialContext(); // Parameterize NamingEnumeration bindings = initCtx.listBindings(root); // Orion 1.5.2 doesn't seem to regard anything under a / // as a true subcontext, so we need to search all bindings // Not all that fast, but it doesn't matter while (bindings.hasMore()) { Binding binding = (Binding) bindings.next(); logger.debug("Name: " + binding.getName()); logger.debug("Type: " + binding.getClassName()); logger.debug("Value: " + binding.getObject()); m.put(binding.getName(), binding.getObject()); } bindings.close(); PropertiesBeanDefinitionReader propReader = new PropertiesBeanDefinitionReader(beanFactory); propReader.registerBeanDefinitions(m, BEANS_PREFIX); } catch (NamingException ex) { logger.debug("----- NO PROPERTIES FOUND " + ex); } finally { try { if (initCtx != null) { initCtx.close(); } } catch (NamingException ex) { // IGNORE OR THROW RTE? } } }
From source file:org.springframework.ldap.core.ContextMapperCallbackHandler.java
/** * Cast the NameClassPair to a {@link Binding} and pass its object to * the ContextMapper./*from w ww .ja v a2 s .co m*/ * * @param nameClassPair * a Binding instance. * @return the Object returned from the mapper. */ public Object getObjectFromNameClassPair(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."); } return mapper.mapFromContext(object); }
From source file:org.wso2.carbon.uuf.core.API.java
/** * Returns a map of service implementation class names and instances of all OSGi services for the given service * class name.//from w w w .j a v a 2 s . c o m * * @param serviceClassName service class name * @return a map of implementation class and instances */ public static Map<String, Object> getOSGiServices(String serviceClassName) { try { Context context = new InitialContext(); NamingEnumeration<Binding> enumeration = context.listBindings("osgi:service/" + serviceClassName); Map<String, Object> services = new HashMap<>(); while (enumeration.hasMore()) { Binding binding = enumeration.next(); services.put(binding.getClassName(), binding.getObject()); } return services; } catch (NamingException e) { throw new UUFException( "Cannot create the initial context when calling OSGi service '" + serviceClassName + "'."); } }