javax.naming.Name Java Examples
The following examples show how to use
javax.naming.Name.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapUtils.java From spring-ldap with Apache License 2.0 | 6 votes |
/** * Remove the supplied path from the beginning the specified * <code>Name</code> if the name instance starts with * <code>path</code>. Useful for stripping base path suffix from a * <code>Name</code>. The original Name will not be affected. * * @param dn the dn to strip from. * @param pathToRemove the path to remove from the beginning the dn instance. * @return an LdapName instance that is a copy of the original name with the * specified path stripped from its beginning. * @since 2.0 */ public static LdapName removeFirst(Name dn, Name pathToRemove) { Assert.notNull(dn, "dn must not be null"); Assert.notNull(pathToRemove, "pathToRemove must not be null"); LdapName result = newLdapName(dn); LdapName path = returnOrConstructLdapNameFromName(pathToRemove); if(path.size() == 0 || !dn.startsWith(path)) { return result; } for(int i = 0; i < path.size(); i++) { try { result.remove(0); } catch (InvalidNameException e) { throw convertLdapException(e); } } return result; }
Example #2
Source File: WARDirContext.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Enumerates the names bound in the named context, along with the * objects bound to them. The contents of any subcontexts are not * included. * <p> * If a binding is added to or removed from this context, its effect on * an enumeration previously returned is undefined. * * @param strName the name of the context to list * @return an enumeration of the bindings in this context. * Each element of the enumeration is of type Binding. * @exception NamingException if a naming exception is encountered */ @Override protected List<NamingEntry> doListBindings(String strName) throws NamingException { Name name = getEscapedJndiName(strName); if (name.isEmpty()) return list(entries); Entry entry = treeLookup(name); if (entry == null) return null; return list(entry); }
Example #3
Source File: ResolveResult.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Adds components to the end of remaining name. * * @param name The components to add. Can be null. * @see #getRemainingName * @see #setRemainingName * @see #appendRemainingComponent */ public void appendRemainingName(Name name) { // System.out.println("appendingRemainingName: " + name.toString()); // Exception e = new Exception(); // e.printStackTrace(); if (name != null) { if (this.remainingName != null) { try { this.remainingName.addAll(name); } catch (InvalidNameException e) { // ignore; shouldn't happen for composite name } } else { this.remainingName = (Name)(name.clone()); } } }
Example #4
Source File: ResolveResult.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Adds components to the end of remaining name. * * @param name The components to add. Can be null. * @see #getRemainingName * @see #setRemainingName * @see #appendRemainingComponent */ public void appendRemainingName(Name name) { // System.out.println("appendingRemainingName: " + name.toString()); // Exception e = new Exception(); // e.printStackTrace(); if (name != null) { if (this.remainingName != null) { try { this.remainingName.addAll(name); } catch (InvalidNameException e) { // ignore; shouldn't happen for composite name } } else { this.remainingName = (Name)(name.clone()); } } }
Example #5
Source File: EjbFactory.java From tomee with Apache License 2.0 | 6 votes |
@Override public Object getObjectInstance(final Object object, final Name name, final Context context, final Hashtable environment) throws Exception { // ignore non ejb-refs if (!(object instanceof EjbRef)) { return null; } // lookup the value Object value = super.getObjectInstance(object, name, context, environment); // if this is an external reference, copy it into the local class loader if (NamingUtil.isPropertyTrue((Reference) object, NamingUtil.EXTERNAL)) { value = copy(value); } // done return value; }
Example #6
Source File: LdifScriptTest.java From scriptella-etl with Apache License 2.0 | 5 votes |
/** * Tests add entry * */ public void testModifyAdd() throws NamingException { final Entry e = readEntry( "dn: cn=ldap,dc=scriptella\n" + "cn: ldap\n" + "objectClass: top\n" + "objectClass: driver\n" + "envVars:"); DirContext mock = new ProxyAdapter<DirContext>(DirContext.class) { public String getNameInNamespace() { return "dc=scriptella"; } public DirContext createSubcontext(Name name, Attributes attrs) throws InvalidNameException { assertEquals(newName("cn=ldap"), name); BasicAttributes exp = new BasicAttributes(true); exp.put("cn", "ldap"); final BasicAttribute oc = new BasicAttribute("objectClass"); oc.add("top"); oc.add("driver"); exp.put(oc); exp.put("envVars", null); assertEquals(exp, attrs); modified=true; return null; } }.getProxy(); LdifScript.modify(mock, e); assertTrue("DirContext was not modified", modified); }
Example #7
Source File: ContinuationDirContext.java From JDKSourceCode1.8 with MIT License | 5 votes |
protected DirContextStringPair getTargetContext(String name) throws NamingException { if (cpe.getResolvedObj() == null) throw (NamingException)cpe.fillInStackTrace(); Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env); if (ctx instanceof DirContext) return new DirContextStringPair((DirContext)ctx, name); if (ctx instanceof Resolver) { Resolver res = (Resolver)ctx; ResolveResult rr = res.resolveToClass(name, DirContext.class); // Reached a DirContext; return result. DirContext dctx = (DirContext)rr.getResolvedObj(); Name tmp = rr.getRemainingName(); String remains = (tmp != null) ? tmp.toString() : ""; return (new DirContextStringPair(dctx, remains)); } // Resolve all the way using lookup(). This may allow the operation // to succeed if it doesn't require the penultimate context. Object ultimate = ctx.lookup(name); if (ultimate instanceof DirContext) { return (new DirContextStringPair((DirContext)ultimate, "")); } throw (NamingException)cpe.fillInStackTrace(); }
Example #8
Source File: DefaultInitialContextTest.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test bind method. * * @throws Exception when an error occurs. */ @Test public void testBind3() throws Exception { DefaultInitialContext context = new DefaultInitialContext(); Name name = new CompositeName("name"); context.bind(name, "value"); assertNotNull(context.lookup(name)); assertThrows(NameAlreadyBoundException.class, () -> context.bind(name, "value")); }
Example #9
Source File: DistinguishedName.java From spring-ldap with Apache License 2.0 | 5 votes |
public Name addAll(int arg0, Name name) throws InvalidNameException { DistinguishedName distinguishedName = null; try { distinguishedName = (DistinguishedName) name; } catch (ClassCastException e) { throw new InvalidNameException("Invalid name type"); } names.addAll(arg0, distinguishedName.getNames()); return this; }
Example #10
Source File: DistinguishedName.java From spring-ldap with Apache License 2.0 | 5 votes |
public Name add(int index, String string) throws InvalidNameException { try { names.add(index, new LdapRdn(string)); } catch (BadLdapGrammarException e) { throw new InvalidNameException("Failed to parse rdn '" + string + "'"); } return this; }
Example #11
Source File: NamingContext.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Creates and binds a new context. Creates a new context with the given * name and binds it in the target context (that named by all but * terminal atomic component of the name). All intermediate contexts and * the target context must already exist. * * @param name the name of the context to create; may not be empty * @return the newly created context * @exception NameAlreadyBoundException if name is already bound * @exception javax.naming.directory.InvalidAttributesException if creation * of the sub-context requires specification of mandatory attributes * @exception NamingException if a naming exception is encountered */ @Override public Context createSubcontext(Name name) throws NamingException { if (!checkWritable()) { return null; } NamingContext newContext = new NamingContext(env, this.name); bind(name, newContext); newContext.setExceptionOnFailedWrite(getExceptionOnFailedWrite()); return newContext; }
Example #12
Source File: ContinuationDirContext.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public NamingEnumeration<SearchResult> search(Name name, String filterExpr, Object[] args, SearchControls cons) throws NamingException { DirContextNamePair res = getTargetContext(name); return res.getDirContext().search(res.getName(), filterExpr, args, cons); }
Example #13
Source File: NonSerializableFactory.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable<?, ?> env) throws Exception { Reference ref = (Reference) obj; RefAddr addr = ref.get("nns"); String key = (String) addr.getContent(); return NonSerializableFactory.getWrapperMap().get(key); }
Example #14
Source File: ContinuationDirContext.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { DirContextNamePair res = getTargetContext(name); return res.getDirContext().search(res.getName(), matchingAttributes, attributesToReturn); }
Example #15
Source File: ContinuationDirContext.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { DirContextNamePair res = getTargetContext(name); return res.getDirContext().search(res.getName(), matchingAttributes, attributesToReturn); }
Example #16
Source File: LdapTestUtils.java From spring-ldap with Apache License 2.0 | 5 votes |
/** * Clear the directory sub-tree starting with the node represented by the * supplied distinguished name. * * @param contextSource the ContextSource to use for getting a DirContext. * @param name the distinguished name of the root node. * @throws NamingException if anything goes wrong removing the sub-tree. */ public static void clearSubContexts(ContextSource contextSource, Name name) throws NamingException { DirContext ctx = null; try { ctx = contextSource.getReadWriteContext(); clearSubContexts(ctx, name); } finally { try { ctx.close(); } catch (Exception e) { // Never mind this } } }
Example #17
Source File: ContinuationDirContext.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public NamingEnumeration<SearchResult> search(Name name, String filterExpr, Object[] args, SearchControls cons) throws NamingException { DirContextNamePair res = getTargetContext(name); return res.getDirContext().search(res.getName(), filterExpr, args, cons); }
Example #18
Source File: ContinuationDirContext.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void bind(Name name, Object obj, Attributes attrs) throws NamingException { DirContextNamePair res = getTargetContext(name); res.getDirContext().bind(res.getName(), obj, attrs); }
Example #19
Source File: HeadTail.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public Name getHead() { return this.head; }
Example #20
Source File: DirContextAdapter.java From spring-ldap with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public NamingEnumeration<Binding> listBindings(Name name) throws NamingException { throw new UnsupportedOperationException(NOT_IMPLEMENTED); }
Example #21
Source File: IvmContext.java From tomee with Apache License 2.0 | 4 votes |
public Object lookupLink(final Name name) throws NamingException { return lookupLink(name.toString()); }
Example #22
Source File: left_LmiInitialContext_1.5.java From gumtree-spoon-ast-diff with Apache License 2.0 | 4 votes |
public void rebind(Name name, Object obj) throws NamingException { rebind(name.toString(), obj); }
Example #23
Source File: JNDIContext.java From tomee with Apache License 2.0 | 4 votes |
@Override public NamingEnumeration<Binding> listBindings(final Name name) throws NamingException { return listBindings(name.toString()); }
Example #24
Source File: ContinuationDirContext.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void bind(Name name, Object obj, Attributes attrs) throws NamingException { DirContextNamePair res = getTargetContext(name); res.getDirContext().bind(res.getName(), obj, attrs); }
Example #25
Source File: LdapName.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * Adds the components of a name -- in order -- at a specified position * within this name. Components of this LDAP name at or after the * index (if any) of the first new component are shifted up * (away from index 0) to accommodate the new components. * * @param suffix The non-null components to add. * @param posn The index at which to add the new component. * Must be in the range [0,size()]. * * @return The updated name (not a new instance). * * @throws InvalidNameException if <tt>suffix</tt> is not a valid LDAP * name, or if the addition of the components would violate the * syntax rules of this LDAP name. * @throws IndexOutOfBoundsException * If posn is outside the specified range. */ public Name addAll(int posn, Name suffix) throws InvalidNameException { unparsed = null; // no longer valid if (suffix instanceof LdapName) { LdapName s = (LdapName) suffix; rdns.addAll(posn, s.rdns); } else { Enumeration<String> comps = suffix.getAll(); while (comps.hasMoreElements()) { rdns.add(posn++, (new Rfc2253Parser(comps.nextElement()). parseRdn())); } } return this; }
Example #26
Source File: SimpleNamingContext.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public NameParser getNameParser(Name name) throws NamingException { throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]"); }
Example #27
Source File: StubContext.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override public NamingEnumeration<Binding> listBindings(Name name) throws NamingException { return new NamingEnumerationStub(); }
Example #28
Source File: SimpleNamingContext.java From spring-analysis-note with MIT License | 4 votes |
@Override public void rename(Name oldName, Name newName) throws NamingException { throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]"); }
Example #29
Source File: TestContext.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override public Context createSubcontext(Name name) throws NamingException { throw new OperationNotSupportedException(); }
Example #30
Source File: CorbanameUrl.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public Name getCosName() throws NamingException { return CNCtx.parser.parse(stringName); }