public void destroySubcontext(Name name) throws NamingException { if (name.size() == 0) throw new NamingException(L.l("can't destroy root subcontext")); AbstractModel model = _model; int i = 0; for (; i + 1 < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } value = dereference(value, null, model); if (value instanceof Context) { ((Context) value).destroySubcontext(name.getSuffix(i + 1)); return; } else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } String first = name.get(i); model.unbind(first); }
public void rebind(Name name, Object obj) throws NamingException { if (name.size() == 0) throw new NamingException(L.l("can't bind root")); AbstractModel model = _model; int i = 0; for (; i + 1 < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } value = dereference(value, null, model); if (value instanceof Context) { ((Context) value).bind(name.getSuffix(i + 1), obj); return; } else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } String first = name.get(i); if (obj == null) obj = NullValue.NULL; model.bind(first, getReference(model, obj)); }
public void rename(Name name, Name newName) throws NamingException { if (name.size() == 1) { if (newName.size() != 1) { throw new OperationNotSupportedException( "Renaming to a Name with more components not supported: " + newName); } rename(name.get(0), newName.get(0)); } else { // > 1 component with 1st one being URL // URLs must be identical; cannot deal with diff URLs if (!urlEquals(name.get(0), newName.get(0))) { throw new OperationNotSupportedException( "Renaming using different URLs as first components not supported: " + name + " " + newName); } Context ctx = getContinuationContext(name); try { ctx.rename(name.getSuffix(1), newName.getSuffix(1)); } finally { ctx.close(); } } }
@Test public void shouldParsePowerApiScheme() throws Exception { final Name name = context.getNameParser(SUBCONTEXT_REF).parse(SUBCONTEXT_REF); assertFalse("Name must not be null", name.isEmpty()); assertEquals( "First part of complex context name should be subcontext", "subcontext", name.get(0)); assertEquals("Second part of complex context name should be object", "object", name.get(1)); }
/** Lists the names for the context. */ public NamingEnumeration list(Name name) throws NamingException { AbstractModel model = _model; if (name == null) { return new QNameClassEnumeration(create(model, _env), model.list()); } for (int i = 0; i < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } value = dereference(value, null, model); if (value instanceof Context) return ((Context) value).list(name.getSuffix(i + 1)); else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } return new QNameClassEnumeration(create(model, _env), model.list()); }
/** Looks up an object with the given parsed JNDI name, but don't dereference the final object. */ public Object lookupLink(Name name) throws NamingException { if (name == null) return create(_model, _env); AbstractModel model = _model; for (int i = 0; i < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } if (i + 1 == name.size()) { if (value == NullValue.NULL) return null; else if (value != null) return value; else throw new NameNotFoundException(getFullPath(name)); } value = dereference(value, null, model); if (value instanceof Context) return ((Context) value).lookupLink(name.getSuffix(i + 1)); else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } return create(getFullPath(name), model, _env); }
private Object lookupImpl(Name name) throws NamingException { if (log.isLoggable(Level.FINEST)) log.finest(L.l("JNDI lookup `{0}'", name)); if (name == null) return create(_model, _env); AbstractModel model = _model; for (int i = 0; i < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } value = dereference(value, null, model); if (i + 1 == name.size()) { return value; } else if (value instanceof Context) { return ((Context) value).lookup(name.getSuffix(i + 1)); } else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } return create(getFullPath(name), model, _env); }
/** * Gets the context in which to continue the operation. This method is called when this context is * asked to process a multicomponent Name in which the first component is a URL. Treat the first * component like a junction: resolve it and then use NamingManager.getContinuationContext() to * get the target context in which to operate on the remainder of the name (n.getSuffix(1)). */ protected Context getContinuationContext(Name n) throws NamingException { Object obj = lookup(n.get(0)); CannotProceedException cpe = new CannotProceedException(); cpe.setResolvedObj(obj); cpe.setEnvironment(myEnv); return NamingManager.getContinuationContext(cpe); }
public NameParser getNameParser(Name name) throws NamingException { if (name.size() == 0) return new QNameParser(this); Object obj = lookupSingleObject(name.get(0)); if (obj instanceof Context) return ((Context) obj).getNameParser(name.getSuffix(1)); else return new QNameParser(this); }
protected final String getAtom(String dn) { // need to strip off all but lowest component of dn // so that is relative to current context (currentDN) try { Name parsed = new LdapName(dn); return parsed.get(parsed.size() - 1); } catch (NamingException e) { return dn; } }
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException { if (name.size() == 1) { return createSubcontext(name.get(0), attrs); } else { DirContext ctx = getContinuationDirContext(name); try { return ctx.createSubcontext(name.getSuffix(1), attrs); } finally { ctx.close(); } } }
public NameParser getNameParser(Name name) throws NamingException { if (name.size() == 1) { return getNameParser(name.get(0)); } else { Context ctx = getContinuationContext(name); try { return ctx.getNameParser(name.getSuffix(1)); } finally { ctx.close(); } } }
public Object lookupLink(Name name) throws NamingException { if (name.size() == 1) { return lookupLink(name.get(0)); } else { Context ctx = getContinuationContext(name); try { return ctx.lookupLink(name.getSuffix(1)); } finally { ctx.close(); } } }
public Context createSubcontext(Name name) throws NamingException { if (name.size() == 1) { return createSubcontext(name.get(0)); } else { Context ctx = getContinuationContext(name); try { return ctx.createSubcontext(name.getSuffix(1)); } finally { ctx.close(); } } }
public void bind(Name name, Object obj, Attributes attrs) throws NamingException { if (name.size() == 1) { bind(name.get(0), obj, attrs); } else { DirContext ctx = getContinuationDirContext(name); try { ctx.bind(name.getSuffix(1), obj, attrs); } finally { ctx.close(); } } }
public NamingEnumeration listBindings(Name name) throws NamingException { if (name.size() == 1) { return listBindings(name.get(0)); } else { Context ctx = getContinuationContext(name); try { return ctx.listBindings(name.getSuffix(1)); } finally { ctx.close(); } } }
public DirContext getSchemaClassDefinition(Name name) throws NamingException { if (name.size() == 1) { return getSchemaClassDefinition(name.get(0)); } else { DirContext ctx = getContinuationDirContext(name); try { return ctx.getSchemaClassDefinition(name.getSuffix(1)); } finally { ctx.close(); } } }
public void rebind(Name name, Object obj) throws NamingException { if (name.size() == 1) { rebind(name.get(0), obj); } else { Context ctx = getContinuationContext(name); try { ctx.rebind(name.getSuffix(1), obj); } finally { ctx.close(); } } }
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException { if (name.size() == 1) { return getAttributes(name.get(0), attrIds); } else { DirContext ctx = getContinuationDirContext(name); try { return ctx.getAttributes(name.getSuffix(1), attrIds); } finally { ctx.close(); } } }
public void destroySubcontext(Name name) throws NamingException { if (name.size() == 1) { destroySubcontext(name.get(0)); } else { Context ctx = getContinuationContext(name); try { ctx.destroySubcontext(name.getSuffix(1)); } finally { ctx.close(); } } }
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException { if (name.size() == 1) { modifyAttributes(name.get(0), mods); } else { DirContext ctx = getContinuationDirContext(name); try { ctx.modifyAttributes(name.getSuffix(1), mods); } finally { ctx.close(); } } }
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes) throws NamingException { if (name.size() == 1) { return search(name.get(0), matchingAttributes); } else { DirContext ctx = getContinuationDirContext(name); try { return ctx.search(name.getSuffix(1), matchingAttributes); } finally { ctx.close(); } } }
public NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons) throws NamingException { if (name.size() == 1) { return search(name.get(0), filter, cons); } else { DirContext ctx = getContinuationDirContext(name); try { return ctx.search(name.getSuffix(1), filter, cons); } finally { ctx.close(); } } }