當前位置: 首頁>>代碼示例>>Java>>正文


Java Name.size方法代碼示例

本文整理匯總了Java中javax.naming.Name.size方法的典型用法代碼示例。如果您正苦於以下問題:Java Name.size方法的具體用法?Java Name.size怎麽用?Java Name.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.naming.Name的用法示例。


在下文中一共展示了Name.size方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getNameParser

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Retrieves the parser associated with the named context. In a federation
 * of namespaces, different naming systems will parse names differently.
 * This method allows an application to get a parser for parsing names into
 * their atomic components using the naming convention of a particular
 * naming system. Within any single naming system, NameParser objects
 * returned by this method must be equal (using the equals() test).
 * 
 * @param name
 *            the name of the context from which to get the parser
 * @return a name parser that can parse compound names into their atomic
 *         components
 * @exception NamingException
 *                if a naming exception is encountered
 */
@Override
public NameParser getNameParser(Name name) throws NamingException {

	while ((!name.isEmpty()) && (name.get(0).length() == 0))
		name = name.getSuffix(1);
	if (name.isEmpty())
		return nameParser;

	if (name.size() > 1) {
		Object obj = bindings.get(name.get(0));
		if (obj instanceof Context) {
			return ((Context) obj).getNameParser(name.getSuffix(1));
		} else {
			throw new NotContextException(sm.getString("namingContext.contextExpected"));
		}
	}

	return nameParser;

}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:36,代碼來源:NamingContext.java

示例2: getNameParser

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Retrieves the parser associated with the named context. In a 
 * federation of namespaces, different naming systems will parse names 
 * differently. This method allows an application to get a parser for 
 * parsing names into their atomic components using the naming convention 
 * of a particular naming system. Within any single naming system, 
 * NameParser objects returned by this method must be equal (using the 
 * equals() test).
 * 
 * @param name the name of the context from which to get the parser
 * @return a name parser that can parse compound names into their atomic 
 * components
 * @exception NamingException if a naming exception is encountered
 */
public NameParser getNameParser(Name name)
    throws NamingException {

    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        return nameParser;

    if (name.size() > 1) {
        Object obj = bindings.get(name.get(0));
        if (obj instanceof Context) {
            return ((Context) obj).getNameParser(name.getSuffix(1));
        } else {
            throw new NotContextException
                (sm.getString("namingContext.contextExpected"));
        }
    }

    return nameParser;

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:36,代碼來源:NamingContext.java

示例3: rebind

import javax.naming.Name; //導入方法依賴的package包/類
@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);
	}
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:22,代碼來源:LocalContext.java

示例4: destroySubcontext

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Destroys the named context and removes it from the namespace. Any 
 * attributes associated with the name are also removed. Intermediate 
 * contexts are not destroyed.
 * <p>
 * This method is idempotent. It succeeds even if the terminal atomic 
 * name is not bound in the target context, but throws 
 * NameNotFoundException if any of the intermediate contexts do not exist. 
 * 
 * In a federated naming system, a context from one naming system may be 
 * bound to a name in another. One can subsequently look up and perform 
 * operations on the foreign context using a composite name. However, an 
 * attempt destroy the context using this composite name will fail with 
 * NotContextException, because the foreign context is not a "subcontext" 
 * of the context in which it is bound. Instead, use unbind() to remove 
 * the binding of the foreign context. Destroying the foreign context 
 * requires that the destroySubcontext() be performed on a context from 
 * the foreign context's "native" naming system.
 * 
 * @param name the name of the context to be destroyed; may not be empty
 * @exception NameNotFoundException if an intermediate context does not 
 * exist
 * @exception NotContextException if the name is bound but does not name 
 * a context, or does not name a context of the appropriate type
 */
@Override
public void destroySubcontext(Name name) throws NamingException {
    
    if (!checkWritable()) {
        return;
    }
    
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException
            (sm.getString("namingContext.invalidName"));
    
    NamingEntry entry = bindings.get(name.get(0));
    
    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name, name.get(0)));
    }
    
    if (name.size() > 1) {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).destroySubcontext(name.getSuffix(1));
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).close();
            bindings.remove(name.get(0));
        } else {
            throw new NotContextException
                (sm.getString("namingContext.contextExpected"));
        }
    }
    
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:64,代碼來源:NamingContext.java

示例5: unbind

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Unbinds the named object. Removes the terminal atomic name in name 
 * from the target context--that named by all but the terminal atomic 
 * part of name.
 * <p>
 * This method is idempotent. It succeeds even if the terminal atomic 
 * name is not bound in the target context, but throws 
 * NameNotFoundException if any of the intermediate contexts do not exist. 
 * 
 * @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(Name name) throws NamingException {
    
    if (!checkWritable()) {
        return;
    }

    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException
            (sm.getString("namingContext.invalidName"));
    
    NamingEntry entry = bindings.get(name.get(0));
    
    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name, name.get(0)));
    }
    
    if (name.size() > 1) {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).unbind(name.getSuffix(1));
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        bindings.remove(name.get(0));
    }
    
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:47,代碼來源:NamingContext.java

示例6: destroySubcontext

import javax.naming.Name; //導入方法依賴的package包/類
/**
    * Destroys the named context and removes it from the namespace. Any 
    * attributes associated with the name are also removed. Intermediate 
    * contexts are not destroyed.
    * <p>
    * This method is idempotent. It succeeds even if the terminal atomic 
    * name is not bound in the target context, but throws 
    * NameNotFoundException if any of the intermediate contexts do not exist. 
    * 
    * In a federated naming system, a context from one naming system may be 
    * bound to a name in another. One can subsequently look up and perform 
    * operations on the foreign context using a composite name. However, an 
    * attempt destroy the context using this composite name will fail with 
    * NotContextException, because the foreign context is not a "subcontext" 
    * of the context in which it is bound. Instead, use unbind() to remove 
    * the binding of the foreign context. Destroying the foreign context 
    * requires that the destroySubcontext() be performed on a context from 
    * the foreign context's "native" naming system.
    * 
    * @param name the name of the context to be destroyed; may not be empty
    * @exception NameNotFoundException if an intermediate context does not 
    * exist
    * @exception NotContextException if the name is bound but does not name 
    * a context, or does not name a context of the appropriate type
    */
   public void destroySubcontext(Name name)
       throws NamingException {
       
       checkWritable();
       
while ((!name.isEmpty()) && (name.get(0).length() == 0))
    name = name.getSuffix(1);
       if (name.isEmpty())
           throw new NamingException
               (sm.getString("namingContext.invalidName"));
       
       NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
       
       if (entry == null) {
           throw new NameNotFoundException
               (sm.getString("namingContext.nameNotBound", name.get(0)));
       }
       
       if (name.size() > 1) {
           if (entry.type == NamingEntry.CONTEXT) {
               ((Context) entry.value).unbind(name.getSuffix(1));
           } else {
               throw new NamingException
                   (sm.getString("namingContext.contextExpected"));
           }
       } else {
           if (entry.type == NamingEntry.CONTEXT) {
               ((Context) entry.value).close();
               bindings.remove(name.get(0));
           } else {
               throw new NotContextException
                   (sm.getString("namingContext.contextExpected"));
           }
       }
       
   }
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:62,代碼來源:NamingContext.java

示例7: getParentGroupForGroup

import javax.naming.Name; //導入方法依賴的package包/類
@Override
public GroupBean getParentGroupForGroup(DirContext ctx, String groupID)
{
	LDAPResult groupRes = ldap.getGroupResult(ctx, groupID, ldap.getGroupAttributes());
	if( groupRes == null )
	{
		return null;
	}

	try
	{
		Name groupName = groupRes.getFullName();
		int sz = groupName.size();
		if( sz > 1 )
		{
			groupName.remove(sz - 1);
			Attributes attributes = ctx.getAttributes(groupName);
			Attribute attribute = attributes.get(LDAP.OBJECTCLASS);
			if( attribute != null && attribute.contains(ldap.getGroupObject()) )
			{
				return ldap.getGroupBeanFromResult(groupRes);
			}
		}
	}
	catch( NamingException e )
	{
		LOGGER.error(e, e);
	}
	return null;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:31,代碼來源:DirectoryGroupSearch.java

示例8: treeLookup

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Entry tree lookup.
 */
protected Entry treeLookup(Name name) {
    if (name.isEmpty())
        return entries;
    Entry currentEntry = entries;
    for (int i = 0; i < name.size(); i++) {
        if (name.get(i).length() == 0)
            continue;
        currentEntry = currentEntry.getChild(name.get(i));
        if (currentEntry == null)
            return null;
    }
    return currentEntry;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:WARDirContext.java

示例9: unbind

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Unbinds the named object. Removes the terminal atomic name in name 
 * from the target context--that named by all but the terminal atomic 
 * part of name.
 * <p>
 * This method is idempotent. It succeeds even if the terminal atomic 
 * name is not bound in the target context, but throws 
 * NameNotFoundException if any of the intermediate contexts do not exist. 
 * 
 * @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
 */
public void unbind(Name name)
    throws NamingException {
    checkWritable();
    
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException
            (sm.getString("namingContext.invalidName"));
    
    NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
    
    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name.get(0)));
    }
    
    if (name.size() > 1) {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).unbind(name.getSuffix(1));
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        bindings.remove(name.get(0));
    }
    
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:44,代碼來源:NamingContext.java

示例10: destroySubcontext

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Destroys the named context and removes it from the namespace. Any 
 * attributes associated with the name are also removed. Intermediate 
 * contexts are not destroyed.
 * <p>
 * This method is idempotent. It succeeds even if the terminal atomic 
 * name is not bound in the target context, but throws 
 * NameNotFoundException if any of the intermediate contexts do not exist. 
 * 
 * In a federated naming system, a context from one naming system may be 
 * bound to a name in another. One can subsequently look up and perform 
 * operations on the foreign context using a composite name. However, an 
 * attempt destroy the context using this composite name will fail with 
 * NotContextException, because the foreign context is not a "subcontext" 
 * of the context in which it is bound. Instead, use unbind() to remove 
 * the binding of the foreign context. Destroying the foreign context 
 * requires that the destroySubcontext() be performed on a context from 
 * the foreign context's "native" naming system.
 * 
 * @param name the name of the context to be destroyed; may not be empty
 * @exception NameNotFoundException if an intermediate context does not 
 * exist
 * @exception NotContextException if the name is bound but does not name 
 * a context, or does not name a context of the appropriate type
 */
public void destroySubcontext(Name name)
    throws NamingException {
    
    checkWritable();
    
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException
            (sm.getString("namingContext.invalidName"));
    
    NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
    
    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name.get(0)));
    }
    
    if (name.size() > 1) {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).unbind(name.getSuffix(1));
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).close();
            bindings.remove(name.get(0));
        } else {
            throw new NotContextException
                (sm.getString("namingContext.contextExpected"));
        }
    }
    
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:62,代碼來源:NamingContext.java

示例11: destroySubcontext

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Destroys subcontext with name name. The subcontext must be empty otherwise
 * ContextNotEmptyException is thrown. Once a context is destroyed, the instance should not be
 * used.
 * 
 * @param name subcontext to destroy
 * @throws NoPermissionException if this context has been destroyed.
 * @throws InvalidNameException if name is empty or is CompositeName that spans more than one
 *         naming system.
 * @throws ContextNotEmptyException if Context name is not empty.
 * @throws NameNotFoundException if subcontext with name name can not be found.
 * @throws NotContextException if name is not bound to instance of ContextImpl.
 * 
 */
public void destroySubcontext(Name name) throws NamingException {
  checkIsDestroyed();
  Name parsedName = getParsedName(name);
  if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
    throw new InvalidNameException(
        LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
  }
  String subContextName = parsedName.get(0);
  Object boundObject = ctxMaps.get(subContextName);
  if (boundObject == null) {
    throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND_IN_THE_CONTEXT
        .toLocalizedString(subContextName));
  }
  if (!(boundObject instanceof ContextImpl)) {
    throw new NotContextException();
  }
  ContextImpl contextToDestroy = (ContextImpl) boundObject;
  if (parsedName.size() == 1) {
    // Check if the Context to be destroyed is empty. Can not destroy
    // non-empty Context.
    if (contextToDestroy.ctxMaps.size() == 0) {
      ctxMaps.remove(subContextName);
      contextToDestroy.destroyInternal();
    } else {
      throw new ContextNotEmptyException(
          LocalizedStrings.ContextImpl_CAN_NOT_DESTROY_NONEMPTY_CONTEXT.toLocalizedString());
    }
  } else {
    // Let the subcontext destroy the context
    ((ContextImpl) boundObject).destroySubcontext(parsedName.getSuffix(1));
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:47,代碼來源:ContextImpl.java

示例12: rebind

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Rebinds object obj to name name . If there is existing binding it will be overwritten.
 * 
 * @param name name of the object to rebind.
 * @param obj object to add. Can be null.
 * @throws NoPermissionException if this context has been destroyed
 * @throws InvalidNameException if name is empty or is CompositeName that spans more than one
 *         naming system
 * @throws NotContextException if name has more than one atomic name and intermediate context is
 *         not found
 * @throws NamingException if any other naming error occurs
 * 
 */
public void rebind(Name name, Object obj) throws NamingException {
  checkIsDestroyed();
  Name parsedName = getParsedName(name);
  if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
    throw new InvalidNameException(
        LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
  }
  String nameToBind = parsedName.get(0);
  if (parsedName.size() == 1) {
    ctxMaps.put(nameToBind, obj);
  } else {
    Object boundObject = ctxMaps.get(nameToBind);
    if (boundObject instanceof Context) {
      /*
       * Let the subcontext bind the object.
       */
      ((Context) boundObject).bind(parsedName.getSuffix(1), obj);
    } else {
      if (boundObject == null) {
        // Create new subcontext and let it do the binding
        Context sub = createSubcontext(nameToBind);
        sub.bind(parsedName.getSuffix(1), obj);
      } else {
        throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0
            .toLocalizedString(boundObject));
      }
    }
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:43,代碼來源:ContextImpl.java

示例13: bind

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Binds a name to an object. All intermediate contexts and the target 
 * context (that named by all but terminal atomic component of the name) 
 * must already exist.
 * 
 * @param name the name to bind; may not be empty
 * @param obj the object to bind; possibly null
 * @param rebind if true, then perform a rebind (ie, overwrite)
 * @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
 */
protected void bind(Name name, Object obj, boolean rebind)
    throws NamingException {
    
    if (!checkWritable()) {
        return;
    }
    
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException
            (sm.getString("namingContext.invalidName"));
    
    NamingEntry entry = bindings.get(name.get(0));
    
    if (name.size() > 1) {
        if (entry == null) {
            throw new NameNotFoundException(sm.getString(
                    "namingContext.nameNotBound", name, name.get(0)));
        }
        if (entry.type == NamingEntry.CONTEXT) {
            if (rebind) {
                ((Context) entry.value).rebind(name.getSuffix(1), obj);
            } else {
                ((Context) entry.value).bind(name.getSuffix(1), obj);
            }
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        if ((!rebind) && (entry != null)) {
            throw new NameAlreadyBoundException
                (sm.getString("namingContext.alreadyBound", name.get(0)));
        } else {
            // Getting the type of the object and wrapping it within a new
            // NamingEntry
            Object toBind = 
                NamingManager.getStateToBind(obj, name, this, env);
            if (toBind instanceof Context) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.CONTEXT);
            } else if (toBind instanceof LinkRef) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.LINK_REF);
            } else if (toBind instanceof Reference) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.REFERENCE);
            } else if (toBind instanceof Referenceable) {
                toBind = ((Referenceable) toBind).getReference();
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.REFERENCE);
            } else {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.ENTRY);
            }
            bindings.put(name.get(0), entry);
        }
    }
    
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:75,代碼來源:NamingContext.java

示例14: bind

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Binds a name to an object. All intermediate contexts and the target
 * context (that named by all but terminal atomic component of the name)
 * must already exist.
 * 
 * @param name
 *            the name to bind; may not be empty
 * @param obj
 *            the object to bind; possibly null
 * @param rebind
 *            if true, then perform a rebind (ie, overwrite)
 * @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
 */
protected void bind(Name name, Object obj, boolean rebind) throws NamingException {

	if (!checkWritable()) {
		return;
	}

	while ((!name.isEmpty()) && (name.get(0).length() == 0))
		name = name.getSuffix(1);
	if (name.isEmpty())
		throw new NamingException(sm.getString("namingContext.invalidName"));

	NamingEntry entry = bindings.get(name.get(0));

	if (name.size() > 1) {
		if (entry == null) {
			throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name, name.get(0)));
		}
		if (entry.type == NamingEntry.CONTEXT) {
			if (rebind) {
				((Context) entry.value).rebind(name.getSuffix(1), obj);
			} else {
				((Context) entry.value).bind(name.getSuffix(1), obj);
			}
		} else {
			throw new NamingException(sm.getString("namingContext.contextExpected"));
		}
	} else {
		if ((!rebind) && (entry != null)) {
			throw new NameAlreadyBoundException(sm.getString("namingContext.alreadyBound", name.get(0)));
		} else {
			// Getting the type of the object and wrapping it within a new
			// NamingEntry
			Object toBind = NamingManager.getStateToBind(obj, name, this, env);
			if (toBind instanceof Context) {
				entry = new NamingEntry(name.get(0), toBind, NamingEntry.CONTEXT);
			} else if (toBind instanceof LinkRef) {
				entry = new NamingEntry(name.get(0), toBind, NamingEntry.LINK_REF);
			} else if (toBind instanceof Reference) {
				entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE);
			} else if (toBind instanceof Referenceable) {
				toBind = ((Referenceable) toBind).getReference();
				entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE);
			} else {
				entry = new NamingEntry(name.get(0), toBind, NamingEntry.ENTRY);
			}
			bindings.put(name.get(0), entry);
		}
	}

}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:69,代碼來源:NamingContext.java

示例15: bind

import javax.naming.Name; //導入方法依賴的package包/類
/**
 * Binds a name to an object. All intermediate contexts and the target 
 * context (that named by all but terminal atomic component of the name) 
 * must already exist.
 * 
 * @param name the name to bind; may not be empty
 * @param obj the object to bind; possibly null
 * @param rebind if true, then perform a rebind (ie, overwrite)
 * @exception NameAlreadyBoundException if name is already bound
 * @exception InvalidAttributesException if object did not supply all 
 * mandatory attributes
 * @exception NamingException if a naming exception is encountered
 */
protected void bind(Name name, Object obj, boolean rebind)
    throws NamingException {
    
    checkWritable();
    
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException
            (sm.getString("namingContext.invalidName"));
    
    NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
    
    if (name.size() > 1) {
        if (entry == null) {
            throw new NameNotFoundException
                (sm.getString("namingContext.nameNotBound", name.get(0)));
        }
        if (entry.type == NamingEntry.CONTEXT) {
            if (rebind) {
                ((Context) entry.value).rebind(name.getSuffix(1), obj);
            } else {
                ((Context) entry.value).bind(name.getSuffix(1), obj);
            }
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        if ((!rebind) && (entry != null)) {
            throw new NameAlreadyBoundException
                (sm.getString("namingContext.alreadyBound", name.get(0)));
        } else {
            // Getting the type of the object and wrapping it within a new
            // NamingEntry
            Object toBind = 
                NamingManager.getStateToBind(obj, name, this, env);
            if (toBind instanceof Context) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.CONTEXT);
            } else if (toBind instanceof LinkRef) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.LINK_REF);
            } else if (toBind instanceof Reference) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.REFERENCE);
            } else if (toBind instanceof Referenceable) {
                toBind = ((Referenceable) toBind).getReference();
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.REFERENCE);
            } else {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.ENTRY);
            }
            bindings.put(name.get(0), entry);
        }
    }
    
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:73,代碼來源:NamingContext.java


注:本文中的javax.naming.Name.size方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。