List of usage examples for javax.naming Binding getName
public String getName()
From source file:org.picketlink.idm.performance.TestBase.java
public void removeContext(Context mainCtx, String name) throws Exception { Context deleteCtx = (Context) mainCtx.lookup(name); NamingEnumeration subDirs = mainCtx.listBindings(name); while (subDirs.hasMoreElements()) { Binding binding = (Binding) subDirs.nextElement(); String subName = binding.getName(); removeContext(deleteCtx, subName); }/* w ww . j a v a 2s.c o m*/ mainCtx.unbind(name); }
From source file:com.ritchey.naming.InitialContextFactory.java
/** * Get Context that has access to default Namespace. This method won't be * called if a name URL beginning with java: is passed to an InitialContext. * * @see org.mortbay.naming.java.javaURLContextFactory * @param env a <code>Hashtable</code> value * @return a <code>Context</code> value *///from w ww . ja v a2 s.c o m public Context getInitialContext(Hashtable env) { Log.debug("InitialContext loaded"); Context ctx = new localContextRoot(env); Properties properties = new Properties(); try { properties.load(new FileInputStream("build.properties")); } catch (Exception e1) { e1.printStackTrace(); } Context jdbc = null; try { jdbc = ctx.createSubcontext("jdbc"); } catch (NamingException e) { try { jdbc = (Context) ctx.lookup("jdbc"); } catch (NamingException e1) { e1.printStackTrace(); } } Context ldap = null; try { ldap = ctx.createSubcontext("ldap"); } catch (NamingException e) { try { ldap = (Context) ctx.lookup("ldap"); } catch (NamingException e1) { e1.printStackTrace(); } } Log.debug("getInitialContext"); String databaseNames = properties.getProperty("database.jndi.names"); if (databaseNames == null) { Log.warn(new RuntimeException("database.jndi.names is not defined" + " in build.properties as a comma separated list in " + "build.properties")); return ctx; } for (String database : databaseNames.split(" *, *")) { Log.debug("create " + database); try { createDs(database, properties, jdbc); } catch (NamingException e) { e.printStackTrace(); } } try { createLdapStrings(properties, ldap); } catch (NamingException e1) { e1.printStackTrace(); } String url = getValue(false, "picture", null, properties); try { ctx.bind("picture", url); } catch (NamingException ex) { Logger.getLogger(InitialContextFactory.class.getName()).log(Level.SEVERE, null, ex); } try { Log.debug("jdbc initial context = " + ctx.listBindings("jdbc")); NamingEnumeration<Binding> ldapBindings = ctx.listBindings("ldap"); Log.debug("ldap initial context = " + ctx.listBindings("ldap")); while (ldapBindings.hasMore()) { Binding binding = ldapBindings.next(); Log.debug("binding: " + binding.getName()); } } catch (NamingException e) { e.printStackTrace(); } return ctx; }
From source file:catalina.mbeans.GlobalResourcesLifecycleListener.java
/** * Create the MBeans for the interesting global JNDI resources in * the specified naming context./* ww w . j ava 2s . c om*/ * * @param prefix Prefix for complete object name paths * @param context Context to be scanned * * @exception NamingException if a JNDI exception occurs */ protected void createMBeans(String prefix, Context context) throws NamingException { if (debug >= 1) { log("Creating MBeans for Global JNDI Resources in Context '" + prefix + "'"); } NamingEnumeration bindings = context.listBindings(""); while (bindings.hasMore()) { Binding binding = (Binding) bindings.next(); String name = prefix + binding.getName(); Object value = context.lookup(binding.getName()); if (debug >= 2) { log("Checking resource " + name); } if (value instanceof Context) { createMBeans(name + "/", (Context) value); } else if (value instanceof UserDatabase) { try { createMBeans(name, (UserDatabase) value); } catch (Exception e) { log("Exception creating UserDatabase MBeans for " + name, e); } } } }
From source file:hermes.browser.HermesBrowser.java
/** * Initialise the underlying Hermes that we're gonna do all our work with * //from w w w . j a va2 s . c o m * @throws HermesException * @throws NamingException */ public void loadConfig() throws NamingException, HermesException { Properties props = new Properties(); Context oldContext = context; HermesConfig oldConfig = null; props.put(Context.INITIAL_CONTEXT_FACTORY, HermesInitialContextFactory.class.getName()); props.put(Context.PROVIDER_URL, getCurrentConfigURL()); props.put("hermes.loader", JAXBHermesLoader.class.getName()); log.debug("props=" + props); Iterator listeners = null; if (loader != null) { listeners = loader.getConfigurationListeners(); oldConfig = loader.getConfig(); } if (oldConfig != null) { Set naming = new HashSet(); naming.addAll(oldConfig.getNaming()); for (Iterator iter = naming.iterator(); iter.hasNext();) { NamingConfig oldNaming = (NamingConfig) iter.next(); loader.notifyNamingRemoved(oldNaming); } } context = new InitialContext(props); loader = (HermesLoader) context.lookup(HermesContext.LOADER); if (listeners != null) { while (listeners.hasNext()) { loader.addConfigurationListener((HermesConfigurationListener) listeners.next()); } } if (oldContext != null) { for (NamingEnumeration iter = oldContext.listBindings(""); iter.hasMoreElements();) { Binding binding = (Binding) iter.next(); try { if (oldContext.lookup(binding.getName()) instanceof Hermes) { Hermes hermes = (Hermes) oldContext.lookup(binding.getName()); Hermes newHermes = null; try { newHermes = (Hermes) context.lookup(hermes.getId()); } catch (NamingException e) { // NOP } if (newHermes == null) { loader.notifyHermesRemoved(hermes); } } } catch (NamingException ex) { // NOP } } } if (!firstLoad) { closeWatches(); final ArrayList tmpList = new ArrayList(); tmpList.addAll(loader.getConfig().getWatch()); loader.getConfig().getWatch().clear(); for (Iterator iter = tmpList.iterator(); iter.hasNext();) { WatchConfig wConfig = (WatchConfig) iter.next(); createWatch(wConfig); } } setTitle("HermesJMS - " + TextUtils.crumble(getCurrentConfigURL(), 100)); }
From source file:com.jsmartframework.web.manager.BeanHandler.java
private void initJndiMapping() { try {//from ww w .j a v a 2s. c o m 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:com.jsmartframework.web.manager.BeanHandler.java
private void lookupInContext(Context context, String prefix) { try {// w ww . jav a2 s .c om prefix += "/"; NamingEnumeration<Binding> bindList = context.listBindings(""); while (bindList.hasMore()) { Binding bind = bindList.next(); if (bind != null) { if (bind.getObject() instanceof Context) { lookupInContext((Context) bind.getObject(), prefix + bind.getName()); } String[] binds = bind.getName().split("!"); if (binds.length > 1) { try { jndiMapping.put(Class.forName(binds[1]), prefix + binds[0]); } catch (Throwable ex) { LOGGER.log(Level.WARNING, "Class could not be found for EJB mapping: " + ex.getMessage()); } } } } } catch (Throwable ex) { LOGGER.log(Level.WARNING, "Bindings could not be found for EJB context: " + 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); }//from w ww .ja v a 2s. c o m }
From source file:org.apache.catalina.util.ExtensionValidator.java
/** * Runtime validation of a Web Applicaiton. * * This method uses JNDI to look up the resources located under a * <code>DirContext</code>. It locates Web Application MANIFEST.MF * file in the /META-INF/ directory of the application and all * MANIFEST.MF files in each JAR file located in the WEB-INF/lib * directory and creates an <code>ArrayList</code> of * <code>ManifestResorce<code> objects. These objects are then passed * to the validateManifestResources method for validation. * * @param dirContext The JNDI root of the Web Application * @param context The context from which the Logger and path to the * application//from w w w .ja v a2 s .c om * * @return true if all required extensions satisfied */ public static synchronized boolean validateApplication(DirContext dirContext, StandardContext context) throws IOException { String appName = context.getPath(); ArrayList appManifestResources = new ArrayList(); ManifestResource appManifestResource = null; // If the application context is null it does not exist and // therefore is not valid if (dirContext == null) return false; // Find the Manifest for the Web Applicaiton InputStream inputStream = null; try { NamingEnumeration wne = dirContext.listBindings("/META-INF/"); Binding binding = (Binding) wne.nextElement(); if (binding.getName().toUpperCase().equals("MANIFEST.MF")) { Resource resource = (Resource) dirContext.lookup("/META-INF/" + binding.getName()); inputStream = resource.streamContent(); Manifest manifest = new Manifest(inputStream); inputStream.close(); inputStream = null; ManifestResource mre = new ManifestResource( sm.getString("extensionValidator.web-application-manifest"), manifest, ManifestResource.WAR); appManifestResources.add(mre); } } catch (NamingException nex) { // Application does not contain a MANIFEST.MF file } catch (NoSuchElementException nse) { // Application does not contain a MANIFEST.MF file } finally { if (inputStream != null) { try { inputStream.close(); } catch (Throwable t) { // Ignore } } } // Locate the Manifests for all bundled JARs NamingEnumeration ne = null; try { if (dirContext != null) { ne = dirContext.listBindings("WEB-INF/lib/"); } while ((ne != null) && ne.hasMoreElements()) { Binding binding = (Binding) ne.nextElement(); if (!binding.getName().toLowerCase().endsWith(".jar")) { continue; } Resource resource = (Resource) dirContext.lookup("/WEB-INF/lib/" + binding.getName()); Manifest jmanifest = getManifest(resource.streamContent()); if (jmanifest != null) { ManifestResource mre = new ManifestResource(binding.getName(), jmanifest, ManifestResource.APPLICATION); appManifestResources.add(mre); } } } catch (NamingException nex) { // Jump out of the check for this application because it // has no resources } return validateManifestResources(appName, appManifestResources); }
From source file:org.apache.openejb.assembler.classic.Assembler.java
public synchronized void destroy() { try {//from w w w . ja va2 s.co m 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.eclipse.ecr.core.storage.sql.reload.RepositoryReloader.java
public static List<Repository> getRepositories() throws NamingException { List<Repository> list = new LinkedList<Repository>(); InitialContext context = new InitialContext(); // we search both JBoss-like and Glassfish-like prefixes // @see NXCore#getRepository for (String prefix : new String[] { "java:NXRepository", "NXRepository" }) { NamingEnumeration<Binding> bindings; try {/*from w ww . j a v a 2 s . c o m*/ bindings = context.listBindings(prefix); } catch (NamingException e) { continue; } for (NamingEnumeration<Binding> e = bindings; e.hasMore();) { Binding binding = e.nextElement(); String name = binding.getName(); if (binding.isRelative()) { name = prefix + '/' + name; } Object object = context.lookup(name); if (!(object instanceof Repository)) { continue; } list.add((Repository) object); } } return list; }