下面列出了javax.naming.spi.Resolver#javax.naming.spi.ResolveResult 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Resolves the host and port of "url" to a root context connected
* to the named DNS server, and returns the domain name as the
* remaining name.
*/
protected ResolveResult getRootURLContext(String url, Hashtable<?,?> env)
throws NamingException {
DnsUrl dnsUrl;
try {
dnsUrl = new DnsUrl(url);
} catch (MalformedURLException e) {
throw new InvalidNameException(e.getMessage());
}
DnsUrl[] urls = new DnsUrl[] { dnsUrl };
String domain = dnsUrl.getDomain();
return new ResolveResult(
DnsContextFactory.getContext(".", urls, env),
new CompositeName().add(domain));
}
public void rename(String oldName, String newName) throws NamingException {
String oldPrefix = getURLPrefix(oldName);
String newPrefix = getURLPrefix(newName);
if (!urlEquals(oldPrefix, newPrefix)) {
throw new OperationNotSupportedException(
"Renaming using different URL prefixes not supported : " +
oldName + " " + newName);
}
ResolveResult res = getRootURLContext(oldName, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
ctx.rename(res.getRemainingName(), getURLSuffix(newPrefix, newName));
} finally {
ctx.close();
}
}
public void rename(String oldName, String newName) throws NamingException {
String oldPrefix = getURLPrefix(oldName);
String newPrefix = getURLPrefix(newName);
if (!urlEquals(oldPrefix, newPrefix)) {
throw new OperationNotSupportedException(
"Renaming using different URL prefixes not supported : " +
oldName + " " + newName);
}
ResolveResult res = getRootURLContext(oldName, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
ctx.rename(res.getRemainingName(), getURLSuffix(newPrefix, newName));
} finally {
ctx.close();
}
}
/**
* This method is used by the iiop and iiopname URL Context factories.
*/
@SuppressWarnings("unchecked")
public static ResolveResult createUsingURL(String url, Hashtable<?,?> env)
throws NamingException {
CNCtx ctx = new CNCtx();
if (env != null) {
env = (Hashtable<?,?>) env.clone();
}
ctx._env = (Hashtable<String, java.lang.Object>)env;
String rest = ctx.initUsingUrl(
env != null ?
(org.omg.CORBA.ORB) env.get("java.naming.corba.orb")
: null,
url, env);
// rest is the INS name
// Return the parsed form to prevent subsequent lookup
// from parsing the string as a composite name
// The caller should be aware that a toString() of the name,
// which came from the environment will yield its INS syntax,
// rather than a composite syntax
return new ResolveResult(ctx, parser.parse(rest));
}
public void rename(String oldName, String newName) throws NamingException {
String oldPrefix = getURLPrefix(oldName);
String newPrefix = getURLPrefix(newName);
if (!urlEquals(oldPrefix, newPrefix)) {
throw new OperationNotSupportedException(
"Renaming using different URL prefixes not supported : " +
oldName + " " + newName);
}
ResolveResult res = getRootURLContext(oldName, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
ctx.rename(res.getRemainingName(), getURLSuffix(newPrefix, newName));
} finally {
ctx.close();
}
}
/**
* This method is used by the iiop and iiopname URL Context factories.
*/
@SuppressWarnings("unchecked")
public static ResolveResult createUsingURL(String url, Hashtable<?,?> env)
throws NamingException {
CNCtx ctx = new CNCtx();
if (env != null) {
env = (Hashtable<?,?>) env.clone();
}
ctx._env = (Hashtable<String, java.lang.Object>)env;
String rest = ctx.initUsingUrl(
env != null ?
(org.omg.CORBA.ORB) env.get("java.naming.corba.orb")
: null,
url, env);
// rest is the INS name
// Return the parsed form to prevent subsequent lookup
// from parsing the string as a composite name
// The caller should be aware that a toString() of the name,
// which came from the environment will yield its INS syntax,
// rather than a composite syntax
return new ResolveResult(ctx, parser.parse(rest));
}
public NamingEnumeration<SearchResult> search(String name,
String filterExpr,
Object[] filterArgs,
SearchControls cons)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return
ctx.search(res.getRemainingName(), filterExpr, filterArgs, cons);
} finally {
ctx.close();
}
}
private NamingEnumeration<SearchResult> searchUsingURL(String name)
throws NamingException {
LdapURL url = new LdapURL(name);
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.search(res.getRemainingName(),
setFilterUsingURL(url),
setSearchControlsUsingURL(url));
} finally {
ctx.close();
}
}
private NamingEnumeration<SearchResult> searchUsingURL(String name)
throws NamingException {
LdapURL url = new LdapURL(name);
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.search(res.getRemainingName(),
setFilterUsingURL(url),
setSearchControlsUsingURL(url));
} finally {
ctx.close();
}
}
public Attributes getAttributes(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.getAttributes(res.getRemainingName());
} finally {
ctx.close();
}
}
public Attributes getAttributes(String name, String[] attrIds)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.getAttributes(res.getRemainingName(), attrIds);
} finally {
ctx.close();
}
}
public void modifyAttributes(String name, int mod_op, Attributes attrs)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
ctx.modifyAttributes(res.getRemainingName(), mod_op, attrs);
} finally {
ctx.close();
}
}
public void modifyAttributes(String name, ModificationItem[] mods)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
ctx.modifyAttributes(res.getRemainingName(), mods);
} finally {
ctx.close();
}
}
public DirContext createSubcontext(String name, Attributes attrs)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.createSubcontext(res.getRemainingName(), attrs);
} finally {
ctx.close();
}
}
public Attributes getAttributes(String name, String[] attrIds)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.getAttributes(res.getRemainingName(), attrIds);
} finally {
ctx.close();
}
}
public DirContext createSubcontext(String name, Attributes attrs)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.createSubcontext(res.getRemainingName(), attrs);
} finally {
ctx.close();
}
}
public DirContext getSchemaClassDefinition(String name)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.getSchemaClassDefinition(res.getRemainingName());
} finally {
ctx.close();
}
}
public NamingEnumeration<SearchResult> search(String name,
Attributes matchingAttributes)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.search(res.getRemainingName(), matchingAttributes);
} finally {
ctx.close();
}
}
public NamingEnumeration<SearchResult> search(String name,
Attributes matchingAttributes,
String[] attributesToReturn)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.search(res.getRemainingName(),
matchingAttributes, attributesToReturn);
} finally {
ctx.close();
}
}
public NamingEnumeration<SearchResult> search(String name,
String filter,
SearchControls cons)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.search(res.getRemainingName(), filter, cons);
} finally {
ctx.close();
}
}
public NamingEnumeration<SearchResult> search(String name,
String filterExpr,
Object[] filterArgs,
SearchControls cons)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return
ctx.search(res.getRemainingName(), filterExpr, filterArgs, cons);
} finally {
ctx.close();
}
}
public Object lookup(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.lookup(res.getRemainingName());
} finally {
ctx.close();
}
}
public void bind(String name, Object obj) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
ctx.bind(res.getRemainingName(), obj);
} finally {
ctx.close();
}
}
public DirContext getSchemaClassDefinition(String name)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.getSchemaClassDefinition(res.getRemainingName());
} finally {
ctx.close();
}
}
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.list(res.getRemainingName());
} finally {
ctx.close();
}
}
public NamingEnumeration<Binding> listBindings(String name)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.listBindings(res.getRemainingName());
} finally {
ctx.close();
}
}
public void destroySubcontext(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
ctx.destroySubcontext(res.getRemainingName());
} finally {
ctx.close();
}
}
public NamingEnumeration<SearchResult> search(String name,
Attributes matchingAttributes,
String[] attributesToReturn)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
DirContext ctx = (DirContext)res.getResolvedObj();
try {
return ctx.search(res.getRemainingName(),
matchingAttributes, attributesToReturn);
} finally {
ctx.close();
}
}
public Object lookupLink(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.lookupLink(res.getRemainingName());
} finally {
ctx.close();
}
}
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.list(res.getRemainingName());
} finally {
ctx.close();
}
}