本文整理汇总了Java中javax.naming.Name类的典型用法代码示例。如果您正苦于以下问题:Java Name类的具体用法?Java Name怎么用?Java Name使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Name类属于javax.naming包,在下文中一共展示了Name类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookup
import javax.naming.Name; //导入依赖的package包/类
/**
* Retrieves the named object. If name is empty, returns a new instance
* of this context (which represents the same naming context as this
* context, but its environment may be modified independently and it may
* be accessed concurrently).
*
* @param name the name of the object to look up
* @return the object bound to name
* @exception NamingException if a naming exception is encountered
*/
public Object lookup(Name name)
throws NamingException {
CacheEntry entry = cacheLookup(name.toString());
if (entry != null) {
if (!entry.exists) {
throw notFoundException;
}
if (entry.resource != null) {
// Check content caching.
return entry.resource;
} else {
return entry.context;
}
}
Object object = dirContext.lookup(parseName(name));
if (object instanceof InputStream)
return new Resource((InputStream) object);
else
return object;
}
示例2: list
import javax.naming.Name; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are
* not included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration list(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextEnumeration(bindings.values().iterator());
}
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).list(name.getSuffix(1));
}
示例3: matches
import javax.naming.Name; //导入依赖的package包/类
private boolean matches(int beg, int end, Name n) {
if (n instanceof LdapName) {
LdapName ln = (LdapName) n;
return doesListMatch(beg, end, ln.rdns);
} else {
for (int i = beg; i < end; i++) {
Rdn rdn;
String rdnString = n.get(i - beg);
try {
rdn = (new Rfc2253Parser(rdnString)).parseRdn();
} catch (InvalidNameException e) {
return false;
}
if (!rdn.equals(rdns.get(i))) {
return false;
}
}
}
return true;
}
示例4: getAttributes
import javax.naming.Name; //导入依赖的package包/类
/**
* Retrieves all of the attributes associated with a named object.
*
* @return the set of attributes associated with name.
* Returns an empty attribute set if name has no attributes; never null.
* @param name the name of the object from which to retrieve attributes
* @exception NamingException if a naming exception is encountered
*/
public Attributes getAttributes(Name name, String[] attrIds)
throws NamingException {
Entry entry = null;
if (name.isEmpty())
entry = entries;
else
entry = treeLookup(name);
if (entry == null)
throw new NamingException
(sm.getString("resources.notFound", name));
ZipEntry zipEntry = entry.getEntry();
ResourceAttributes attrs = new ResourceAttributes();
attrs.setCreationDate(new Date(zipEntry.getTime()));
attrs.setName(entry.getName());
if (!zipEntry.isDirectory())
attrs.setResourceType("");
attrs.setContentLength(zipEntry.getSize());
attrs.setLastModified(new Date(zipEntry.getTime()));
return attrs;
}
示例5: doListBindings
import javax.naming.Name; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the
* objects bound to them. The contents of any subcontexts are not
* included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param strName the name of the context to list
* @return an enumeration of the bindings in this context.
* Each element of the enumeration is of type Binding.
* @exception NamingException if a naming exception is encountered
*/
@Override
protected List<NamingEntry> doListBindings(String strName)
throws NamingException {
Name name = getEscapedJndiName(strName);
if (name.isEmpty())
return list(entries);
Entry entry = treeLookup(name);
if (entry == null)
return null;
return list(entry);
}
示例6: getGroupResult
import javax.naming.Name; //导入依赖的package包/类
public LDAPResult getGroupResult(DirContext ctx, String groupID, String[] attrs)
{
if( !Check.isEmpty(groupIdField) )
{
SingleFilter nv1 = new SingleFilter(OBJECTCLASS, getGroupObject());
SingleFilter nv2 = new SingleFilter(groupIdField, groupID);
return searchFirstResultAllBases(ctx, new AndFilter(nv1, nv2), new LdapResultHitsCollector(attrs), true);
}
try
{
Name name = LDAP.parse(groupID);
return new LDAPResult(name, getAttributes(ctx, name, attrs));
}
catch( InvalidNameException e )
{
LOGGER.debug(e, e);
return null;
}
}
示例7: collectAllSubGroupFullNames
import javax.naming.Name; //导入依赖的package包/类
private void collectAllSubGroupFullNames(Set<String> results, DirContext ctx, Name parent)
{
final String fullname = parent.toString();
if( results.add(fullname) )
{
for( Name child : ldap.searchAllBases(ctx, getSubgroupsByMemberOfFilter(fullname),
new FullNameHitsCollector(), true) )
{
collectAllSubGroupFullNames(results, ctx, child);
}
}
}
示例8: createSubcontext
import javax.naming.Name; //导入依赖的package包/类
/**
* Creates and binds a new context. Creates a new context with the given
* name and binds it in the target context (that named by all but
* terminal atomic component of the name). All intermediate contexts and
* the target context must already exist.
*
* @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(Name name) throws NamingException {
if (!checkWritable()) {
return null;
}
NamingContext newContext = new NamingContext(env, this.name);
bind(name, newContext);
newContext.setExceptionOnFailedWrite(getExceptionOnFailedWrite());
return newContext;
}
示例9: lookup
import javax.naming.Name; //导入依赖的package包/类
@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));
}
}
示例10: rename
import javax.naming.Name; //导入依赖的package包/类
@Override
public void rename(Name oldname, Name newname) throws NamingException {
if (oldname.isEmpty() || newname.isEmpty())
throw new InvalidNameException("Cannot rename empty name");
Name oldnm = getMyComponents(oldname);
Name newnm = getMyComponents(newname);
if (oldnm.size() != newnm.size())
throw new OperationNotSupportedException("Do not support rename across different contexts");
String oldatom = oldnm.get(0);
String newatom = newnm.get(0);
if (oldnm.size() == 1) {
if (iBindings.get(newatom) != null)
throw new NameAlreadyBoundException(newname.toString() + " is already bound");
Object oldBinding = iBindings.remove(oldatom);
if (oldBinding == null)
throw new NameNotFoundException(oldname.toString() + " not bound");
iBindings.put(newatom, oldBinding);
} else {
if (!oldatom.equals(newatom))
throw new OperationNotSupportedException("Do not support rename across different contexts");
Object inter = iBindings.get(oldatom);
if (!(inter instanceof Context))
throw new NotContextException(oldatom + " does not name a context");
((Context) inter).rename(oldnm.getSuffix(1), newnm.getSuffix(1));
}
}
示例11: lookup
import javax.naming.Name; //导入依赖的package包/类
/**
* Retrieves the named object. If name is empty, returns a new instance
* of this context (which represents the same naming context as this
* context, but its environment may be modified independently and it may
* be accessed concurrently).
*
* @param name the name of the object to look up
* @return the object bound to name
* @exception NamingException if a naming exception is encountered
*/
public Object lookup(Name name)
throws NamingException {
if (name.isEmpty())
return this;
Entry entry = treeLookup(name);
if (entry == null)
throw new NamingException
(sm.getString("resources.notFound", name));
ZipEntry zipEntry = entry.getEntry();
if (zipEntry.isDirectory())
return new WARDirContext(base, entry);
else
return new WARResource(entry.getEntry());
}
示例12: list
import javax.naming.Name; //导入依赖的package包/类
@Override
public NamingEnumeration list(Name name) throws NamingException {
if (name.isEmpty())
return new ListOfNames(iBindings.keys());
Object target = lookup(name);
if (target instanceof Context)
return ((Context) target).list("");
throw new NotContextException(name + " cannot be listed");
}
示例13: listBindings
import javax.naming.Name; //导入依赖的package包/类
@Override
public NamingEnumeration listBindings(Name name) throws NamingException {
if (name.isEmpty())
return new ListOfBindings(iBindings.keys());
Object target = lookup(name);
if (target instanceof Context)
return ((Context) target).listBindings("");
throw new NotContextException(name + " cannot be listed");
}
示例14: 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;
}
示例15: treeLookup
import javax.naming.Name; //导入依赖的package包/类
/**
* Entry tree lookup.
*/
protected Entry treeLookup(Name name) {
if (name.isEmpty() || entries == null)
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;
}