NamingEntry ne = NamingEntryUtil.lookupNamingEntry(scope, name); bound = NamingEntryUtil.bindToENC(scope, name, nameInEnvironment); bound = NamingEntryUtil.bindToENC(scope, name, nameInEnvironment); if (bound) return; bound = NamingEntryUtil.bindToENC(null, name, nameInEnvironment); if (bound) return; NamingEntry defaultNE = NamingEntryUtil.lookupNamingEntry(context.getServer(), nameInEnvironment); if (defaultNE==null) defaultNE = NamingEntryUtil.lookupNamingEntry(null, nameInEnvironment);
public static Context getContextForScope(Object scope) throws NamingException { InitialContext ic = new InitialContext(); NameParser parser = ic.getNameParser(""); Name name = parser.parse(""); if (scope != null) { name.add(canonicalizeScope(scope)); } return (Context)ic.lookup(name); }
/** * Get all NameEntries of a certain type in the given naming * environment scope (server-wide names or context-specific names) * * @param scope * @param clazz the type of the entry * @return all NameEntries of a certain type in the given naming environment scope (server-wide names or context-specific names) * @throws NamingException */ public static List<Object> lookupNamingEntries (Object scope, Class<?> clazz) throws NamingException { try { Context scopeContext = getContextForScope(scope); Context namingEntriesContext = (Context)scopeContext.lookup(NamingEntry.__contextName); ArrayList<Object> list = new ArrayList<Object>(); lookupNamingEntries(list, namingEntriesContext, clazz); return list; } catch (NameNotFoundException e) { return Collections.emptyList(); } }
/** * Find a NamingEntry in the given scope. * * @param scope the object scope * @param jndiName the jndi name * @return the naming entry for the given scope * @throws NamingException if unable to lookup naming entry */ public static NamingEntry lookupNamingEntry (Object scope, String jndiName) throws NamingException { NamingEntry entry = null; try { Name scopeName = getNameForScope(scope); InitialContext ic = new InitialContext(); NameParser parser = ic.getNameParser(""); Name namingEntryName = makeNamingEntryName(parser, jndiName); scopeName.addAll(namingEntryName); entry = (NamingEntry)ic.lookup(scopeName); } catch (NameNotFoundException ee) { } return entry; }
public void handleClass (Class<?> clazz) { Resource resource = (Resource)clazz.getAnnotation(Resource.class); if (resource != null) { String name = resource.name(); String mappedName = resource.mappedName(); if (name==null || name.trim().equals("")) throw new IllegalStateException ("Class level Resource annotations must contain a name (Common Annotations Spec Section 2.3)"); try { if (!org.eclipse.jetty.plus.jndi.NamingEntryUtil.bindToENC(_context, name,mappedName)) if (!org.eclipse.jetty.plus.jndi.NamingEntryUtil.bindToENC(_context.getServer(), name,mappedName)) throw new IllegalStateException("No resource at "+(mappedName==null?name:mappedName)); } catch (NamingException e) { LOG.warn(e); } } }
Context envCtx = (Context)ic.lookup("java:comp/env"); Object scope = null; List<Object> list = NamingEntryUtil.lookupNamingEntries(scope, EnvEntry.class); Iterator<Object> itor = list.iterator(); while (itor.hasNext()) Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee); list = NamingEntryUtil.lookupNamingEntries(scope, EnvEntry.class); itor = list.iterator(); while (itor.hasNext()) Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee); list = NamingEntryUtil.lookupNamingEntries(scope, EnvEntry.class); itor = list.iterator(); while (itor.hasNext()) Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee);
public static Context getContextForNamingEntries (Object scope) throws NamingException { Context scopeContext = getContextForScope(scope); return (Context)scopeContext.lookup(NamingEntry.__contextName); }
public static Name makeNamingEntryName (NameParser parser, NamingEntry namingEntry) throws NamingException { return makeNamingEntryName(parser, (namingEntry==null?null:namingEntry.getJndiName())); }
/** * Link a name in a webapp's java:/comp/evn namespace to a pre-existing * resource. The pre-existing resource can be either in the webapp's * naming environment, or in the container's naming environment. Webapp's * environment takes precedence over the server's namespace. * * @param scope the scope of the lookup * @param asName the name to bind as * @param mappedName the name from the environment to link to asName * @throws NamingException */ public static boolean bindToENC (Object scope, String asName, String mappedName) throws NamingException { if (asName==null||asName.trim().equals("")) throw new NamingException ("No name for NamingEntry"); if (mappedName==null || "".equals(mappedName)) mappedName=asName; NamingEntry entry = lookupNamingEntry (scope, mappedName); if (entry == null) return false; entry.bindToENC(asName); return true; }
public static Object lookup(Object scope, String jndiName) throws NamingException { Name scopeName = getNameForScope(scope); InitialContext ic = new InitialContext(); NameParser parser = ic.getNameParser(""); scopeName.addAll(parser.parse(jndiName)); return ic.lookup(scopeName); }
/** * Build up a list of NamingEntry objects that are of a specific type. * * @param list * @param context * @param clazz * @return * @throws NamingException */ private static List<Object> lookupNamingEntries (List<Object> list, Context context, Class<?> clazz) throws NamingException { try { NamingEnumeration<Binding> nenum = context.listBindings(""); while (nenum.hasMoreElements()) { Binding binding = nenum.next(); if (binding.getObject() instanceof Context) lookupNamingEntries (list, (Context)binding.getObject(), clazz); else if (clazz.isInstance(binding.getObject())) list.add(binding.getObject()); } } catch (NameNotFoundException e) { __log.debug("No entries of type "+clazz.getName()+" in context="+context); } return list; }
/** * Find a NamingEntry in the given scope. * * @param scope * @param jndiName * @return the naming entry for the given scope * @throws NamingException */ public static NamingEntry lookupNamingEntry (Object scope, String jndiName) throws NamingException { NamingEntry entry = null; try { Name scopeName = getNameForScope(scope); InitialContext ic = new InitialContext(); NameParser parser = ic.getNameParser(""); Name namingEntryName = makeNamingEntryName(parser, jndiName); scopeName.addAll(namingEntryName); entry = (NamingEntry)ic.lookup(scopeName); } catch (NameNotFoundException ee) { } return entry; }
public void handleClass (Class<?> clazz) { Resource resource = (Resource)clazz.getAnnotation(Resource.class); if (resource != null) { String name = resource.name(); String mappedName = resource.mappedName(); if (name==null || name.trim().equals("")) throw new IllegalStateException ("Class level Resource annotations must contain a name (Common Annotations Spec Section 2.3)"); try { if (!org.eclipse.jetty.plus.jndi.NamingEntryUtil.bindToENC(_context, name,mappedName)) if (!org.eclipse.jetty.plus.jndi.NamingEntryUtil.bindToENC(_context.getServer(), name,mappedName)) throw new IllegalStateException("No resource at "+(mappedName==null?name:mappedName)); } catch (NamingException e) { LOG.warn(e); } } }
Context envCtx = (Context)ic.lookup("java:comp/env"); Object scope = null; List<Object> list = NamingEntryUtil.lookupNamingEntries(scope, EnvEntry.class); Iterator<Object> itor = list.iterator(); while (itor.hasNext()) Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee); list = NamingEntryUtil.lookupNamingEntries(scope, EnvEntry.class); itor = list.iterator(); while (itor.hasNext()) Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee); list = NamingEntryUtil.lookupNamingEntries(scope, EnvEntry.class); itor = list.iterator(); while (itor.hasNext()) Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee);
public static Context getContextForNamingEntries (Object scope) throws NamingException { Context scopeContext = getContextForScope(scope); return (Context)scopeContext.lookup(NamingEntry.__contextName); }
public static Name makeNamingEntryName (NameParser parser, NamingEntry namingEntry) throws NamingException { return makeNamingEntryName(parser, (namingEntry==null?null:namingEntry.getJndiName())); }
/** * Link a name in a webapp's java:/comp/evn namespace to a pre-existing * resource. The pre-existing resource can be either in the webapp's * naming environment, or in the container's naming environment. Webapp's * environment takes precedence over the server's namespace. * * @param scope the scope of the lookup * @param asName the name to bind as * @param mappedName the name from the environment to link to asName * @throws NamingException */ public static boolean bindToENC (Object scope, String asName, String mappedName) throws NamingException { if (asName==null||asName.trim().equals("")) throw new NamingException ("No name for NamingEntry"); if (mappedName==null || "".equals(mappedName)) mappedName=asName; NamingEntry entry = lookupNamingEntry (scope, mappedName); if (entry == null) return false; entry.bindToENC(asName); return true; }
public static Object lookup(Object scope, String jndiName) throws NamingException { Name scopeName = getNameForScope(scope); InitialContext ic = new InitialContext(); NameParser parser = ic.getNameParser(""); scopeName.addAll(parser.parse(jndiName)); return ic.lookup(scopeName); }
/** * Build up a list of NamingEntry objects that are of a specific type. * * @param list * @param context * @param clazz * @return * @throws NamingException */ private static List<Object> lookupNamingEntries (List<Object> list, Context context, Class<?> clazz) throws NamingException { try { NamingEnumeration<Binding> nenum = context.listBindings(""); while (nenum.hasMoreElements()) { Binding binding = nenum.next(); if (binding.getObject() instanceof Context) lookupNamingEntries (list, (Context)binding.getObject(), clazz); else if (clazz.isInstance(binding.getObject())) list.add(binding.getObject()); } } catch (NameNotFoundException e) { __log.debug("No entries of type "+clazz.getName()+" in context="+context); } return list; }