Package javax.naming

Examples of javax.naming.Name


        Iterator itor = list.iterator();
        while (itor.hasNext())
        {
            EnvEntry ee = (EnvEntry)itor.next();
            ee.bindToENC(ee.getJndiName());
            Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee);
            NamingUtil.bind(envCtx, namingEntryName.toString(), ee);//also save the EnvEntry in the context so we can check it later         
        }
       
        Log.debug("Binding env entries from the server scope");
       
        scope = getWebAppContext().getServer();
        list = NamingEntryUtil.lookupNamingEntries(scope, EnvEntry.class);
        itor = list.iterator();
        while (itor.hasNext())
        {
            EnvEntry ee = (EnvEntry)itor.next();
            ee.bindToENC(ee.getJndiName());
            Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee);
            NamingUtil.bind(envCtx, namingEntryName.toString(), ee);//also save the EnvEntry in the context so we can check it later         
        }
       
        Log.debug("Binding env entries from the context scope");
        scope = getWebAppContext();
        list = NamingEntryUtil.lookupNamingEntries(scope, EnvEntry.class);
        itor = list.iterator();
        while (itor.hasNext())
        {
            EnvEntry ee = (EnvEntry)itor.next();
            ee.bindToENC(ee.getJndiName());
            Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee);
            NamingUtil.bind(envCtx, namingEntryName.toString(), ee);//also save the EnvEntry in the context so we can check it later
        }
    } 
View Full Code Here



  private String containsName(DirContext ctx, Attribute attr, String dn) throws NamingException, OperationFailedException
  {
    NameParser parser = ctx.getNameParser(realm.getPrefix());
    Name name = parser.parse(dn);
   
    for (NamingEnumeration e=attr.getAll(); e.hasMore(); ) {
      String cand = (String)e.next();
      Name candName = parser.parse(cand);
     
      if ( name.equals(candName) ) {
        e.close();
        return cand;
      }
     
      //toimiiko jos prefixi� ei ole???
      if (cand.toLowerCase().startsWith("cn")) {
        String res = containsName(ctx, fetchMembers(ctx, candName.getSuffix(candName.size()-2).toString()), dn);
        if (res != null) {
          throw new OperationFailedException("Loops not allowed, '"+dn+"' is already a member of '"+cand+"'");
        }
      }
    }
View Full Code Here


   public void  bind(Context ctx, String name, Object val) throws NamingException
   {
      // Bind val to name in ctx, and make sure that all intermediate contexts exist
      Name n = ctx.getNameParser("").parse(name);
      while (n.size() > 1)
      {
         String ctxName = n.get(0);
         try
         {
            ctx = (Context)ctx.lookup(ctxName);
         } catch (NameNotFoundException e)
         {
            ctx = ctx.createSubcontext(ctxName);
         }
         n = n.getSuffix(1);
      }

      ctx.bind(n.get(0), val);
   }
View Full Code Here

    public Context createSubcontext(String name) throws NamingException {
        return createSubcontext(new CompositeName(name));
    }

    public Context createSubcontext(Name name) throws NamingException {
        Name childName = validateName(name);

        // If null, it means we don't know how to handle this -> throw to the
        // parent
        if (childName == null)
            return this.parent.createSubcontext(name);
        // If empty name, complain - we should have a child name here
        else if (childName.isEmpty())
            throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                    "WinstoneContext.AlreadyExists", name.toString()));
        else if (childName.size() > 1) {
            Object ctx = lookup(childName.get(0));
            if (!(ctx instanceof Context))
                throw new NotContextException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NotContext", new String[] {
                                childName.get(0), ctx.getClass().getName() }));
            else if (ctx == null)
                throw new NameNotFoundException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NameNotFound", childName.get(0)));
            else
                try {
                    ((Context) ctx).createSubcontext(childName.getSuffix(1));
                } finally {
                    ((Context) ctx).close();
                }
        }

        Context childContext = null;
        synchronized (this.contextLock) {
            if (this.bindings.get(childName.get(0)) != null)
                throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.AlreadyExists", childName.get(0)));
            else {
                childContext = new WinstoneContext(this.environment, this,
                        this.myAbsoluteName + "/" + childName.get(0),
                        new Boolean(true));
                this.bindings.put(childName.get(0), childContext);
            }
        }
        return childContext;
    }
View Full Code Here

    public void destroySubcontext(String name) throws NamingException {
        destroySubcontext(new CompositeName(name));
    }

    public void destroySubcontext(Name name) throws NamingException {
        Name childName = validateName(name);

        // If null, it means we don't know how to handle this -> throw to the parent
        if (childName == null)
            this.parent.destroySubcontext(name);
        // If absolutely referring to this context, tell the parent to delete this context
        else if (childName.isEmpty()) {
            if (!name.isEmpty())
                this.parent.destroySubcontext(name.getSuffix(name.size() - 2));
            else
                throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES
                        .getString("WinstoneContext.CantDestroyEmptyName"));
        } else if (childName.size() > 1) {
            Object ctx = lookup(childName.get(0));
            if (!(ctx instanceof Context))
                throw new NotContextException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NotContext", new String[] {
                                childName.get(0), ctx.getClass().getName() }));
            else if (ctx == null)
                throw new NameNotFoundException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NameNotFound", childName.get(0)));
            else
                try {
                    ((Context) ctx).destroySubcontext(childName.getSuffix(1));
                } finally {
                    ((Context) ctx).close();
                }
        } else
            synchronized (this.contextLock) {
                Context childContext = (Context) lookup(childName.get(0));
                childContext.close();
                this.bindings.remove(childName.get(0));
            }
    }
View Full Code Here

            }
    }

    public String composeName(String name1, String name2)
            throws NamingException {
        Name name = composeName(new CompositeName(name1), new CompositeName(
                name2));
        return name == null ? null : name.toString();
    }
View Full Code Here

        try {
            InitialContext ic = new InitialContext();
            for (Iterator i = this.objectsToCreate.keySet().iterator(); i.hasNext();) {
                String name = (String) i.next();
                try {
                    Name fullName = new CompositeName(name);
                    Context currentContext = ic;
                    while (fullName.size() > 1) {
                        // Make contexts that are not already present
                        try {
                            currentContext = currentContext
                                    .createSubcontext(fullName.get(0));
                        } catch (NamingException err) {
                            currentContext = (Context) currentContext
                                    .lookup(fullName.get(0));
                        }
                        fullName = fullName.getSuffix(1);
                    }
                    ic.bind(name, this.objectsToCreate.get(name));
                    Logger.log(Logger.FULL_DEBUG, JNDI_RESOURCES,
                            "ContainerJNDIManager.BoundResource", name);
                } catch (NamingException err) {
View Full Code Here

    protected Name validateName(Name name) throws NamingException {
        // Check for absolute urls and redirect or correct
        if (name.isEmpty())
            return name;
        else if (name.get(0).equals(BODGED_PREFIX)) {
            Name newName = name.getSuffix(1).add(0, FIRST_CHILD).add(0, PREFIX);
            return validateName(newName);
        } else if (name.get(0).equals(PREFIX)) {
            String stringName = name.toString();
            if (stringName.equals(this.myAbsoluteName))
                return nameParser.parse("");
View Full Code Here

     * Lookup an object in the context. Returns a copy of this context if the
     * name is empty, or the specified resource (if we have it). If the name is
     * unknown, throws a NameNotFoundException.
     */
    public Object lookup(Name name) throws NamingException {
        Name searchName = validateName(name);

        // If null, it means we don't know how to handle this -> throw to the
        // parent
        if (searchName == null)
            return this.parent.lookup(name);
        // If empty name, return a copy of this Context
        else if (searchName.isEmpty())
            return new WinstoneContext(this.environment, this.parent,
                    this.myAbsoluteName, this.contextLock, this.bindings);

        String thisName = searchName.get(0);
        synchronized (this.contextLock) {
            Object thisValue = bindings.get(thisName);

            // If the name points to something in this level, try to find it,
            // and give
            // an error if not available
            if (searchName.size() == 1) {
                if (thisValue == null)
                    throw new NameNotFoundException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                            "WinstoneContext.NameNotFound", name.toString()));

                try {
                    return NamingManager.getObjectInstance(thisValue,
                            new CompositeName().add(thisName), this,
                            this.environment);
                } catch (Exception e) {
                    NamingException ne = new NamingException(ContainerJNDIManager.JNDI_RESOURCES
                            .getString("WinstoneContext.FailedToGetInstance"));
                    ne.setRootCause(e);
                    throw ne;
                }
            }

            else if (thisValue == null)
                throw new NameNotFoundException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NameNotFound", thisName.toString()));

            // If it's not in this level and what we found is not a context,
            // complain
            else if (!(thisValue instanceof Context))
                throw new NotContextException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NotContext", new String[] {
                                thisName.toString(),
                                thisValue.getClass().getName() }));

            // Open the context, perform a lookup, then close the context we
            // opened
            else
                try {
                    return ((Context) thisValue)
                            .lookup(searchName.getSuffix(1));
                } finally {
                    ((Context) thisValue).close();
                }
        }
    }
View Full Code Here

    /**
     * Returns a list of objects bound to the context
     */
    public NamingEnumeration list(Name name) throws NamingException {
        Name searchName = validateName(name);

        // If null, it means we don't know how to handle this -> throw to the
        // parent
        if (searchName == null)
            return this.parent.list(name);
        // If empty name, return a copy of this Context
        else if (searchName.isEmpty()) {
            NamingEnumeration e = null;
            synchronized (this.contextLock) {
                e = new WinstoneNameEnumeration(this.bindings);
            }
            return e;
        }

        // Lookup the object - if it's not a context, throw an error
        else {
            Object ctx = this.lookup(searchName);
            if (ctx instanceof Context)
                try {
                    return ((Context) ctx).list(new CompositeName(""));
                } finally {
                    ((Context) ctx).close();
                }
            else if (ctx == null)
                throw new NameNotFoundException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NameNotFound", searchName.toString()));
            else
                throw new NotContextException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NotContext",
                        new String[] { searchName.toString(),
                                ctx.getClass().getName() }));
        }
    }
View Full Code Here

TOP

Related Classes of javax.naming.Name

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.