List of usage examples for javax.naming Name getPrefix
public Name getPrefix(int posn);
From source file:com.dattack.naming.AbstractContext.java
@Override public NamingEnumeration<NameClassPair> list(final Name name) throws NamingException { ensureContextNotClosed();//from ww w. j a va 2s . c om if (name == null || name.isEmpty()) { // list all elements final Map<Name, Object> enumStore = new HashMap<Name, Object>(); enumStore.putAll(objectTable); enumStore.putAll(subContexts); return new NameClassPairNamingEnumeration(enumStore); } final Name prefixName = name.getPrefix(1); if (objectTable.containsKey(prefixName)) { throw new NotContextException(String.format("%s cannot be listed", name)); } if (subContexts.containsKey(prefixName)) { return subContexts.get(prefixName).list(name.getSuffix(1)); } throw new NamingException(String.format("The context '%s' can't be found", name)); }
From source file:com.dattack.naming.AbstractContext.java
@Override public Object lookup(final Name name) throws NamingException { ensureContextNotClosed();/*from w w w. j a v a 2 s . c o m*/ /* * Extract from Context Javadoc: If name is empty, returns a new instance of this context (which represents the * same naming context as this context, but its environment may be modified independently and it may be accessed * concurrently). */ if (name.isEmpty()) { try { return this.clone(); } catch (final CloneNotSupportedException e) { // this shouldn't happen, since we are Cloneable throw (NamingException) new OperationNotSupportedException(e.getMessage()).initCause(e); } } if (name.size() > 1) { if (subContexts.containsKey(name.getPrefix(1))) { return subContexts.get(name.getPrefix(1)).lookup(name.getSuffix(1)); } throw new NamingException( String.format("Invalid subcontext '%s' in context '%s'", name.getPrefix(1).toString(), StringUtils.isBlank(getNameInNamespace()) ? "/" : getNameInNamespace())); } Object result = null; // not found if (objectTable.containsKey(name)) { result = objectTable.get(name); } else if (subContexts.containsKey(name)) { result = subContexts.get(name); } else if (env.containsKey(name.toString())) { result = env.get(name.toString()); } return result; }
From source file:org.nuxeo.runtime.test.runner.JndiHelper.java
/** * Unbinds a name from ctx, and removes parents if they are empty * * @param ctx the parent JNDI Context under which the name will be unbound * @param name The name to unbind//from www. java 2s. c o m * @throws NamingException for any error */ public static void unbind(Context ctx, Name name) throws NamingException { ctx.unbind(name); // unbind the end node in the name int sz = name.size(); // walk the tree backwards, stopping at the domain while (--sz > 0) { Name pname = name.getPrefix(sz); try { ctx.destroySubcontext(pname); } catch (NamingException e) { log.error(e, e); break; } } }