Package javax.naming

Examples of javax.naming.NamingException


      bindings.put(newName, value);
   }

   public void unbind(Name name) throws NamingException
   {
      throw new NamingException("Unsupported op");     
   }
View Full Code Here


     
      // Redeploy the naming service
      redeployNaming();
     
      Context ctx2 = createInitialContext(env);
      NamingException ne = null;
      try
      {
         assertEquals(ObjectBinder.VALUE, ctx2.lookup(ObjectBinder.NAME));
      }
      catch (NamingException e)
      {
         // Cache the exception to fail the test later, after
         // we check that we can recover
         log.error("Caught NamingException", e);
         ne = e;
      }
     
      // We recover from failure
      if (ne != null)
      {
         try
         {
            assertEquals(ObjectBinder.VALUE, ctx2.lookup(ObjectBinder.NAME));
         }
         catch (Exception e)
         {
            log.error("Failed to reacquire server");
         }
         // Now fail due to the earlier failure
         fail(ne.getMessage());        
      }
     
      // Confirm the original context is still good
      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
   }
View Full Code Here

   * @exception NamingException if a naming exception is encountered
   */
  public Object lookup(String name) throws NamingException {
   
    VFSItem item = resolveFile(name);
    if (item == null) throw new NamingException(smgr.getString("resources.notFound", name));

    if (item instanceof VFSContainer) {
      VFSDirContext tempContext = new VFSDirContext(env);
      tempContext.setVirtualDocBase(item);
      return tempContext;
View Full Code Here

   * @exception NamingException if a naming exception is encountered
   */
  public void unbind(String name) throws NamingException {

    VFSItem file = resolveFile(name);
    if (file == null) throw new NamingException(smgr.getString("resources.notFound", name));

    VFSStatus status = file.delete();
    if (status == VFSConstants.NO)
      throw new NamingException(smgr.getString("resources.unbindFailed", name));
  }
View Full Code Here

   * @exception NamingException if a naming exception is encountered
   */
  public void rename(String oldName, String newName) throws NamingException {

    VFSItem oldFile = resolveFile(oldName);
    if (oldFile == null) throw new NamingException(smgr.getString("resources.notFound", oldName));

    VFSItem newFile = resolveFile(newName);
    if (newFile != null)
      throw new NameAlreadyBoundException();
   
View Full Code Here

   * @exception NamingException if a naming exception is encountered
   */
  public NamingEnumeration<NameClassPair> list(String name) throws NamingException {

    VFSItem file = resolveFile(name);
    if (file == null) throw new NamingException(smgr.getString("resources.notFound", name));
    return new NamingContextEnumeration(list(file).iterator());

  }
View Full Code Here

   */
  public Attributes getAttributes(String name, String[] attrIds) throws NamingException {

    // Building attribute list
    VFSItem file = resolveFile(name);
    if (file == null) throw new NamingException(smgr.getString("resources.notFound", name));
    return new VFSResourceAttributes(file);

  }
View Full Code Here

    // Note: No custom attributes allowed
    VFSItem file = resolveFile(name);
    if (file != null) throw new NameAlreadyBoundException(smgr.getString("resources.alreadyBound", name));
   
    int lastSlash = name.lastIndexOf('/');
    if (lastSlash == -1) throw new NamingException();
    String parent = name.substring(0, lastSlash);
    VFSItem folder = resolveFile(parent);
    if (folder == null || (!(folder instanceof VFSContainer)))
      throw new NamingException(smgr.getString("resources.bindFailed", name));
    String newName = name.substring(lastSlash + 1);
    VFSLeaf childLeaf = ((VFSContainer)folder).createChildLeaf(newName);
    if (childLeaf == null)
      throw new NamingException(smgr.getString("resources.bindFailed", name));
    copyVFS(childLeaf, name, obj, attrs);
    if(childLeaf instanceof MetaTagged) {
      MetaInfo infos = ((MetaTagged)childLeaf).getMetaInfo();
      if(infos != null && infos.getAuthorIdentity() == null) {
        infos.setAuthor(userSession.getIdentity().getName());
View Full Code Here

    // Note: No custom attributes allowed
    // Check obj type

    VFSItem vfsItem = resolveFile(name);
    if (vfsItem == null || (!(vfsItem instanceof VFSLeaf))) throw new NamingException(smgr.getString("resources.bindFailed", name));
    VFSLeaf file = (VFSLeaf)vfsItem;
   
    if(file instanceof Versionable && ((Versionable)file).getVersions().isVersioned()) {
      VersionsManager.getInstance().addToRevisions((Versionable)file, identity, "");
    }
View Full Code Here

      is = (InputStream) obj;
    } else if (obj instanceof DirContext) {
      createSubcontext(name, attrs);
      return;
    }
    if (is == null) throw new NamingException(smgr.getString("resources.bindFailed", name));

    // Try to get Quota
    long quotaLeft = -1;
    boolean withQuotaCheck = false;
    VFSContainer parentContainer = file.getParentContainer();
    if (parentContainer != null) {
      quotaLeft = VFSManager.getQuotaLeftKB(parentContainer);
      if (quotaLeft != Quota.UNLIMITED) {
        quotaLeft = quotaLeft * 1024; // convert from kB
        withQuotaCheck = true;
      } else {
        withQuotaCheck = false;
      }
    }
    // Open os
    OutputStream os = null;
    byte buffer[] = new byte[bufferSize];
    int len = -1;
    try {
      os = file.getOutputStream(false);
      while (true) {
        len = is.read(buffer);
        if (len == -1) break;
        if (withQuotaCheck) {
          // re-calculate quota and check
          quotaLeft = quotaLeft - len;
          if (quotaLeft < 0) throw new NamingException("Quota exceeded.");
        }
        os.write(buffer, 0, len);
      }
    } catch (Exception e) {
      FileUtils.closeSafely(os); // close first, in order to be able to delete any reamins of the file
      file.delete();
      if (e instanceof NamingException) throw (NamingException)e;
      throw new NamingException(smgr.getString("resources.bindFailed"));
    } finally {
      FileUtils.closeSafely(os);
      FileUtils.closeSafely(is);
    }
  }
View Full Code Here

TOP

Related Classes of javax.naming.NamingException

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.