当前位置: 首页>>代码示例>>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;未经允许,请勿转载。