Java 类javax.naming.CompositeName 实例源码

项目:tomcat7    文件:TestNamingContext.java   
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    resp.setContentType("text/plain;UTF-8");
    PrintWriter out = resp.getWriter();

    try {
        Context initCtx = new InitialContext();

        Boolean b1 = (Boolean) initCtx.lookup(JNDI_NAME);
        Boolean b2 = (Boolean) initCtx.lookup(
                new CompositeName(JNDI_NAME));

        out.print(b1);
        out.print(b2);

    } catch (NamingException ne) {
        throw new ServletException(ne);
    }
}
项目:unitimes    文件:LocalContext.java   
@Override
public void bind(Name name, Object obj) throws NamingException {
    if (name.isEmpty()) {
        throw new InvalidNameException("Cannot bind empty name");
    }

    Name nm = getMyComponents(name);
    String atom = nm.get(0);
    Object inter = iBindings.get(atom);

    if (nm.size() == 1) {
        if (inter != null)
            throw new NameAlreadyBoundException("Use rebind to override");

        obj = NamingManager.getStateToBind(obj, new CompositeName().add(atom), this, iEnv);

        iBindings.put(atom, obj);
    } else {
        if (!(inter instanceof Context))
            throw new NotContextException(atom + " does not name a context");

        ((Context) inter).bind(nm.getSuffix(1), obj);
    }
}
项目:unitimes    文件:LocalContext.java   
@Override
public void rebind(Name name, Object obj) throws NamingException {
    if (name.isEmpty())
        throw new InvalidNameException("Cannot bind empty name");

    Name nm = getMyComponents(name);
    String atom = nm.get(0);

    if (nm.size() == 1) {
        obj = NamingManager.getStateToBind(obj, new CompositeName().add(atom), this, iEnv);

        iBindings.put(atom, obj);
    } else {
        Object inter = iBindings.get(atom);

        if (!(inter instanceof Context))
            throw new NotContextException(atom + " does not name a context");

        ((Context) inter).rebind(nm.getSuffix(1), obj);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestNamingContext.java   
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    resp.setContentType("text/plain;UTF-8");
    PrintWriter out = resp.getWriter();

    try {
        Context initCtx = new InitialContext();

        Boolean b1 = (Boolean) initCtx.lookup(JNDI_NAME);
        Boolean b2 = (Boolean) initCtx.lookup(
                new CompositeName(JNDI_NAME));

        out.print(b1);
        out.print(b2);

    } catch (NamingException ne) {
        throw new ServletException(ne);
    }
}
项目:alfresco-repository    文件:PropertyValueDAOTest.java   
@Test
public void testPropertyValue_Serializable() throws Exception
{
    for (int i = 0; i < 100; i++)
    {
        // Choose a type that implements equals and hashCode but will not be recognised
        runPropertyValueTest(new CompositeName("Name-"+i), false);
    }
}
项目:lams    文件:JNDIRealm.java   
/**
 * Returns the distinguished name of a search result.
 *
 * @param context Our DirContext
 * @param base The base DN
 * @param result The search result
 * @return String containing the distinguished name
 */
protected String getDistinguishedName(DirContext context, String base, SearchResult result)
    throws NamingException {
    // Get the entry's distinguished name
    NameParser parser = context.getNameParser("");
    Name contextName = parser.parse(context.getNameInNamespace());
    Name baseName = parser.parse(base);

    // Bugzilla 32269
    Name entryName = parser.parse(new CompositeName(result.getName()).get(0));

    Name name = contextName.addAll(baseName);
    name = name.addAll(entryName);
    return name.toString();
}
项目:unitimes    文件:LocalContext.java   
protected Name getMyComponents(Name name) throws NamingException {
    if (name instanceof CompositeName) {
        if (name.size() > 1)
            throw new InvalidNameException(name.toString() + " has more components than namespace can handle");
        return parse(name.get(0));
    } else {
        return name;
    }
}
项目:unitimes    文件:LocalContext.java   
@Override
public Object lookup(Name name) throws NamingException {
    if (name.isEmpty())
        return cloneCtx();

    Name nm = getMyComponents(name);
    String atom = nm.get(0);
    Object inter = iBindings.get(atom);

    if (nm.size() == 1) {
        if (inter == null)
            throw new NameNotFoundException(name + " not found");

        try {
            return NamingManager.getObjectInstance(inter, new CompositeName().add(atom), this, iEnv);
        } catch (Exception e) {
            NamingException ne = new NamingException("getObjectInstance failed");
            ne.setRootCause(e);
            throw ne;
        }
    } else {
        if (!(inter instanceof Context))
            throw new NotContextException(atom + " does not name a context");

        return ((Context) inter).lookup(nm.getSuffix(1));
    }
}
项目:unitimes    文件:LocalContext.java   
public Object next() throws NamingException {
    String name = (String) iNames.nextElement();
    Object obj = iBindings.get(name);

    try {
        obj = NamingManager.getObjectInstance(obj, new CompositeName().add(name), LocalContext.this, LocalContext.this.iEnv);
    } catch (Exception e) {
        NamingException ne = new NamingException("getObjectInstance failed");
        ne.setRootCause(e);
        throw ne;
    }

    return new Binding(name, obj);
}
项目:OpenJSharp    文件:ContinuationDirContext.java   
protected DirContextNamePair getTargetContext(Name name)
        throws NamingException {

    if (cpe.getResolvedObj() == null)
        throw (NamingException)cpe.fillInStackTrace();

    Context ctx = NamingManager.getContext(cpe.getResolvedObj(),
                                           cpe.getAltName(),
                                           cpe.getAltNameCtx(),
                                           env);
    if (ctx == null)
        throw (NamingException)cpe.fillInStackTrace();

    if (ctx instanceof DirContext)
        return new DirContextNamePair((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();
        return (new DirContextNamePair(dctx, rr.getRemainingName()));
    }

    // 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 DirContextNamePair((DirContext)ultimate,
                                      new CompositeName()));
    }

    throw (NamingException)cpe.fillInStackTrace();
}
项目:OpenJSharp    文件:ResolveResult.java   
/**
      * Constructs a new instance of ResolveResult consisting of
      * the resolved object and the remaining unresolved component.
      *
      * @param robj The non-null object resolved to.
      * @param rcomp The single remaining name component that has yet to be
      *                 resolved. Cannot be null (but can be empty).
      */
    public ResolveResult(Object robj, String rcomp) {
        resolvedObj = robj;
        try {
        remainingName = new CompositeName(rcomp);
//          remainingName.appendComponent(rcomp);
        } catch (InvalidNameException e) {
            // ignore; shouldn't happen
        }
    }
项目:OpenJSharp    文件:ResolveResult.java   
/**
  * Adds a single component to the end of remaining name.
  *
  * @param name The component to add. Can be null.
  * @see #getRemainingName
  * @see #appendRemainingName
  */
public void appendRemainingComponent(String name) {
    if (name != null) {
        CompositeName rname = new CompositeName();
        try {
            rname.add(name);
        } catch (InvalidNameException e) {
            // ignore; shouldn't happen for empty composite name
        }
        appendRemainingName(rname);
    }
}
项目:jdk8u-jdk    文件:ContinuationDirContext.java   
protected DirContextNamePair getTargetContext(Name name)
        throws NamingException {

    if (cpe.getResolvedObj() == null)
        throw (NamingException)cpe.fillInStackTrace();

    Context ctx = NamingManager.getContext(cpe.getResolvedObj(),
                                           cpe.getAltName(),
                                           cpe.getAltNameCtx(),
                                           env);
    if (ctx == null)
        throw (NamingException)cpe.fillInStackTrace();

    if (ctx instanceof DirContext)
        return new DirContextNamePair((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();
        return (new DirContextNamePair(dctx, rr.getRemainingName()));
    }

    // 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 DirContextNamePair((DirContext)ultimate,
                                      new CompositeName()));
    }

    throw (NamingException)cpe.fillInStackTrace();
}
项目:jdk8u-jdk    文件:ResolveResult.java   
/**
      * Constructs a new instance of ResolveResult consisting of
      * the resolved object and the remaining unresolved component.
      *
      * @param robj The non-null object resolved to.
      * @param rcomp The single remaining name component that has yet to be
      *                 resolved. Cannot be null (but can be empty).
      */
    public ResolveResult(Object robj, String rcomp) {
        resolvedObj = robj;
        try {
        remainingName = new CompositeName(rcomp);
//          remainingName.appendComponent(rcomp);
        } catch (InvalidNameException e) {
            // ignore; shouldn't happen
        }
    }
项目:jdk8u-jdk    文件:ResolveResult.java   
/**
  * Adds a single component to the end of remaining name.
  *
  * @param name The component to add. Can be null.
  * @see #getRemainingName
  * @see #appendRemainingName
  */
public void appendRemainingComponent(String name) {
    if (name != null) {
        CompositeName rname = new CompositeName();
        try {
            rname.add(name);
        } catch (InvalidNameException e) {
            // ignore; shouldn't happen for empty composite name
        }
        appendRemainingName(rname);
    }
}
项目:openjdk-jdk10    文件:ContinuationDirContext.java   
protected DirContextNamePair getTargetContext(Name name)
        throws NamingException {

    if (cpe.getResolvedObj() == null)
        throw (NamingException)cpe.fillInStackTrace();

    Context ctx = NamingManager.getContext(cpe.getResolvedObj(),
                                           cpe.getAltName(),
                                           cpe.getAltNameCtx(),
                                           env);
    if (ctx == null)
        throw (NamingException)cpe.fillInStackTrace();

    if (ctx instanceof DirContext)
        return new DirContextNamePair((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();
        return (new DirContextNamePair(dctx, rr.getRemainingName()));
    }

    // 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 DirContextNamePair((DirContext)ultimate,
                                      new CompositeName()));
    }

    throw (NamingException)cpe.fillInStackTrace();
}
项目:openjdk-jdk10    文件:ResolveResult.java   
/**
      * Constructs a new instance of ResolveResult consisting of
      * the resolved object and the remaining unresolved component.
      *
      * @param robj The non-null object resolved to.
      * @param rcomp The single remaining name component that has yet to be
      *                 resolved. Cannot be null (but can be empty).
      */
    public ResolveResult(Object robj, String rcomp) {
        resolvedObj = robj;
        try {
        remainingName = new CompositeName(rcomp);
//          remainingName.appendComponent(rcomp);
        } catch (InvalidNameException e) {
            // ignore; shouldn't happen
        }
    }
项目:openjdk-jdk10    文件:ResolveResult.java   
/**
  * Adds a single component to the end of remaining name.
  *
  * @param name The component to add. Can be null.
  * @see #getRemainingName
  * @see #appendRemainingName
  */
public void appendRemainingComponent(String name) {
    if (name != null) {
        CompositeName rname = new CompositeName();
        try {
            rname.add(name);
        } catch (InvalidNameException e) {
            // ignore; shouldn't happen for empty composite name
        }
        appendRemainingName(rname);
    }
}
项目:alfresco-repository    文件:PropertyValueDAOTest.java   
@Test
public void testPropertySerializableValue() throws Exception
{
    final Serializable serializableValue = new CompositeName("123");
    RetryingTransactionCallback<Pair<Long, Serializable>> createValueCallback = new RetryingTransactionCallback<Pair<Long, Serializable>>()
    {
        public Pair<Long, Serializable> execute() throws Throwable
        {
            return propertyValueDAO.createPropertySerializableValue(serializableValue);
        }
    };
    final Pair<Long, Serializable> entityPair = txnHelper.doInTransaction(createValueCallback, false);
    assertNotNull(entityPair);
    assertEquals(serializableValue, entityPair.getSecond());

    RetryingTransactionCallback<Pair<Long, Serializable>> getValueCallback = new RetryingTransactionCallback<Pair<Long, Serializable>>()
    {
        public Pair<Long, Serializable> execute() throws Throwable
        {
            return propertyValueDAO.getPropertySerializableValueById(entityPair.getFirst());
        }
    };
    final Pair<Long, Serializable> entityPairCheck = txnHelper.doInTransaction(getValueCallback, false);
    assertNotNull(entityPairCheck);
    assertEquals(entityPair.getFirst(), entityPairCheck.getFirst());
    assertEquals(entityPair, entityPairCheck);

    // Check that we can persist and retrieve byte[] as a Serializable
    final Serializable bytes = (Serializable) new byte[] {1, 2, 3};
    RetryingTransactionCallback<Pair<Long, Void>> testBytesCallback = new RetryingTransactionCallback<Pair<Long, Void>>()
    {
        public Pair<Long, Void> execute() throws Throwable
        {
            Long id = propertyValueDAO.createPropertySerializableValue(bytes).getFirst();
            Serializable check = propertyValueDAO.getPropertySerializableValueById(id).getSecond();
            assertNotNull(check);
            assertTrue(check instanceof byte[]);
            Arrays.equals((byte[])bytes, (byte[])check);
            return null;
        }
    };
    txnHelper.doInTransaction(testBytesCallback, false);
}
项目:unitimes    文件:LocalContext.java   
@Override
public Object lookup(String name) throws NamingException {
    return lookup(new CompositeName(name));
}
项目:unitimes    文件:LocalContext.java   
@Override
public void bind(String name, Object obj) throws NamingException {
    bind(new CompositeName(name), obj);
}
项目:unitimes    文件:LocalContext.java   
@Override
public void rebind(String name, Object obj) throws NamingException {
    rebind(new CompositeName(name), obj);
}
项目:unitimes    文件:LocalContext.java   
@Override
public void unbind(String name) throws NamingException {
    unbind(new CompositeName(name));
}
项目:unitimes    文件:LocalContext.java   
@Override
public void rename(String oldname, String newname) throws NamingException {
    rename(new CompositeName(oldname), new CompositeName(newname));
}
项目:unitimes    文件:LocalContext.java   
@Override
public NamingEnumeration list(String name) throws NamingException {
    return list(new CompositeName(name));
}
项目:unitimes    文件:LocalContext.java   
@Override
public NamingEnumeration listBindings(String name) throws NamingException {
    return listBindings(new CompositeName(name));
}
项目:unitimes    文件:LocalContext.java   
@Override
public void destroySubcontext(String name) throws NamingException {
    destroySubcontext(new CompositeName(name));
}
项目:unitimes    文件:LocalContext.java   
@Override
public Context createSubcontext(String name) throws NamingException {
    return createSubcontext(new CompositeName(name));
}
项目:unitimes    文件:LocalContext.java   
@Override
public Object lookupLink(String name) throws NamingException {
    return lookupLink(new CompositeName(name));
}
项目:unitimes    文件:LocalContext.java   
@Override
public NameParser getNameParser(String name) throws NamingException {
    return getNameParser(new CompositeName(name));
}
项目:unitimes    文件:LocalContext.java   
@Override
public String composeName(String name, String prefix) throws NamingException {
    Name result = composeName(new CompositeName(name), new CompositeName(prefix));
    return result.toString();
}
项目:alfresco-repository    文件:LDAPUserRegistry.java   
/**
 * Converts a given DN into one suitable for use through JNDI. In particular, escapes special characters such as '/'
 * which have special meaning to JNDI.
 * 
 * @param dn
 *            the dn
 * @return the name
 * @throws InvalidNameException
 *             the invalid name exception
 */
public static Name jndiName(String dn) throws InvalidNameException
{
    Name n = new CompositeName();
    n.add(dn);
    return n;
}
项目:tomcat7    文件:NameParserImpl.java   
/**
 * Parses a name into its components.
 * 
 * @param name The non-null string name to parse
 * @return A non-null parsed form of the name using the naming convention 
 * of this parser.
 */
@Override
public Name parse(String name)
    throws NamingException {
    return new CompositeName(name);
}
项目:tomcat7    文件:WARDirContext.java   
/**
 * JNDI treats ' and " as reserved characters therefore they need to be
 * escaped as part of converting file names to JNDI names. Note that while
 * ' can be used in Windows and Unix file names, " is only valid on Unix.
 * This method assumes that the string is currently unquoted.
 * 
 * @return  A valid JNDI name
 * @throws InvalidNameException 
 */
private Name getEscapedJndiName(String name) throws InvalidNameException {
    return new CompositeName(name.replace("'", "\\'").replace("\"", ""));
}
项目:tomcat7    文件:NamingContext.java   
/**
 * Retrieves the named object.
 * 
 * @param name the name of the object to look up
 * @return the object bound to name
 * @exception NamingException if a naming exception is encountered
 */
@Override
public Object lookup(String name)
    throws NamingException {
    return lookup(new CompositeName(name), true);
}
项目:tomcat7    文件:NamingContext.java   
/**
 * Binds a name to an object.
 * 
 * @param name the name to bind; may not be empty
 * @param obj the object to bind; possibly null
 * @exception NameAlreadyBoundException if name is already bound
 * @exception javax.naming.directory.InvalidAttributesException if object
 * did not supply all mandatory attributes
 * @exception NamingException if a naming exception is encountered
 */
@Override
public void bind(String name, Object obj)
    throws NamingException {
    bind(new CompositeName(name), obj);
}
项目:tomcat7    文件:NamingContext.java   
/**
 * Binds a name to an object, overwriting any existing binding.
 * 
 * @param name the name to bind; may not be empty
 * @param obj the object to bind; possibly null
 * @exception javax.naming.directory.InvalidAttributesException if object
 * did not supply all mandatory attributes
 * @exception NamingException if a naming exception is encountered
 */
@Override
public void rebind(String name, Object obj)
    throws NamingException {
    rebind(new CompositeName(name), obj);
}
项目:tomcat7    文件:NamingContext.java   
/**
 * Unbinds the named object.
 * 
 * @param name the name to bind; may not be empty
 * @exception NameNotFoundException if an intermediate context does not 
 * exist
 * @exception NamingException if a naming exception is encountered
 */
@Override
public void unbind(String name)
    throws NamingException {
    unbind(new CompositeName(name));
}
项目:tomcat7    文件:NamingContext.java   
/**
 * Binds a new name to the object bound to an old name, and unbinds the 
 * old name.
 * 
 * @param oldName the name of the existing binding; may not be empty
 * @param newName the name of the new binding; may not be empty
 * @exception NameAlreadyBoundException if newName is already bound
 * @exception NamingException if a naming exception is encountered
 */
@Override
public void rename(String oldName, String newName)
    throws NamingException {
    rename(new CompositeName(oldName), new CompositeName(newName));
}
项目:lazycat    文件:NamingContext.java   
/**
 * Creates and binds a new context.
 * 
 * @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(String name) throws NamingException {
    return createSubcontext(new CompositeName(name));
}