Java Code Examples for javax.naming.Name

The following examples show how to use javax.naming.Name. These examples are extracted from open source projects. 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 Project: jdk8u60   Source File: ResolveResult.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
      * 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 2
Source Project: hottub   Source File: ResolveResult.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
      * 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 3
Source Project: spring-ldap   Source File: LdapUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 4
Source Project: tomcatsrc   Source File: WARDirContext.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source Project: tomee   Source File: EjbFactory.java    License: Apache License 2.0 6 votes vote down vote up
@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
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 7
Source Project: scriptella-etl   Source File: LdifScriptTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 8
/**
 * 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 Project: spring-ldap   Source File: DistinguishedName.java    License: Apache License 2.0 5 votes vote down vote up
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 10
Source Project: Tomcat7.0.67   Source File: NamingContext.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 11
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 12
Source Project: activemq-artemis   Source File: NonSerializableFactory.java    License: Apache License 2.0 5 votes vote down vote up
@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 13
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 14
Source Project: spring-ldap   Source File: LdapTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 15
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 Project: spring-ldap   Source File: DistinguishedName.java    License: Apache License 2.0 5 votes vote down vote up
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 17
Source Project: JDKSourceCode1.8   Source File: ContinuationDirContext.java    License: MIT License 5 votes vote down vote up
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 18
Source Project: jdk8u60   Source File: StubContext.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
    return new NamingEnumerationStub();
}
 
Example 19
Source Project: openbd-core   Source File: ldapEntry.java    License: GNU General Public License v3.0 4 votes vote down vote up
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
	throw new OperationNotSupportedException();
}
 
Example 20
Source Project: tomee   Source File: OpenEJBContext.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public NamingEnumeration<Binding> listBindings(final Name name) throws NamingException {
    return getThreadContext().listBindings(name);
}
 
Example 21
Source Project: spring4-understanding   Source File: SimpleNamingContext.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object lookup(Name name) throws NamingException {
	throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
 
Example 22
Source Project: openbd-core   Source File: ldapEntry.java    License: GNU General Public License v3.0 4 votes vote down vote up
public NamingEnumeration list(Name _name) throws NamingException {
	throw new OperationNotSupportedException();
}
 
Example 23
Source Project: jqm   Source File: JndiContext.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void bind(Name name, Object obj) throws NamingException
{
    this.bind(StringUtils.join(Collections.list(name.getAll()), "/"), obj);
}
 
Example 24
@Override
public Object lookupLink(Name name) throws NamingException {

	return null;
}
 
Example 25
public DifferentSubtreeTempEntryRenamingStrategy(Name subtreeNode) {
    this.subtreeNode = subtreeNode;
}
 
Example 26
Source Project: kieker   Source File: FakeContext.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void rename(final Name oldName, final Name newName) throws NamingException {
	// No code necessary
}
 
Example 27
public void bind(Name name, Object obj, Attributes attrs)
throws NamingException  {
    DirContextNamePair res = getTargetContext(name);
    res.getDirContext().bind(res.getName(), obj, attrs);
}
 
Example 28
public void rebind(Name name, Object obj, Attributes attrs)
        throws NamingException {
    DirContextNamePair res = getTargetContext(name);
    res.getDirContext().rebind(res.getName(), obj, attrs);
}
 
Example 29
Source Project: carbon-identity   Source File: MyUser.java    License: Apache License 2.0 4 votes vote down vote up
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes, String[] attributesToReturn)
    throws NamingException {
    return null;  //To change body of implemented methods use File | Settings | File Templates.
}
 
Example 30
Source Project: tomee   Source File: JNDIContext.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void unbind(final Name name) throws NamingException {
    unbind(name.toString());
}